2019-09-19 21:19:07 +00:00
|
|
|
// eslint-disable-next-line no-restricted-properties
|
|
|
|
var mobile = mw.mobileFrontend.require( 'mobile.startup' ),
|
2019-12-16 23:47:54 +00:00
|
|
|
drawers = require( './drawers.js' ),
|
2019-09-19 21:19:07 +00:00
|
|
|
CtaDrawer = mobile.CtaDrawer,
|
|
|
|
Button = mobile.Button,
|
|
|
|
Anchor = mobile.Anchor;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize red links call-to-action
|
|
|
|
*
|
|
|
|
* Upon clicking a red link, show an interstitial CTA explaining that the page doesn't exist
|
|
|
|
* with a button to create it, rather than directly navigate to the edit form.
|
|
|
|
*
|
|
|
|
* Special case T201339: following a red link to a user or user talk page should not prompt for
|
|
|
|
* its creation. The reasoning is that user pages should be created by their owners and it's far
|
|
|
|
* more common that non-owners follow a user's red linked user page to consider their
|
|
|
|
* contributions, account age, or other activity.
|
|
|
|
*
|
|
|
|
* For example, a user adds a section to a Talk page and signs their contribution (which creates
|
|
|
|
* a link to their user page whether exists or not). If the user page does not exist, that link
|
|
|
|
* will be red. In both cases, another user follows this link, not to edit create a page for
|
|
|
|
* that user but to obtain information on them.
|
|
|
|
*
|
|
|
|
* @ignore
|
|
|
|
* @param {jQuery.Object} $redLinks
|
|
|
|
*/
|
|
|
|
function initRedlinksCta( $redLinks ) {
|
|
|
|
$redLinks.on( 'click', function ( ev ) {
|
|
|
|
var drawerOptions = {
|
|
|
|
progressiveButton: new Button( {
|
|
|
|
progressive: true,
|
|
|
|
label: mw.msg( 'mobile-frontend-editor-redlink-create' ),
|
|
|
|
href: $( this ).attr( 'href' )
|
|
|
|
} ).options,
|
|
|
|
actionAnchor: new Anchor( {
|
|
|
|
progressive: true,
|
|
|
|
label: mw.msg( 'mobile-frontend-editor-redlink-leave' ),
|
|
|
|
additionalClassNames: 'cancel'
|
|
|
|
} ).options,
|
2019-12-16 23:47:54 +00:00
|
|
|
onShow: function () {
|
|
|
|
drawers.onShow();
|
|
|
|
},
|
|
|
|
onBeforeHide: drawers.discardDrawer,
|
2019-09-19 21:19:07 +00:00
|
|
|
content: mw.msg( 'mobile-frontend-editor-redlink-explain' )
|
|
|
|
},
|
|
|
|
drawer = CtaDrawer( drawerOptions );
|
|
|
|
|
|
|
|
// use preventDefault() and not return false to close other open
|
|
|
|
// drawers or anything else.
|
|
|
|
ev.preventDefault();
|
2019-12-16 23:47:54 +00:00
|
|
|
ev.stopPropagation();
|
|
|
|
drawers.displayDrawer( drawer, { hideOnScroll: true } );
|
2019-09-19 21:19:07 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A CtaDrawer should show for anonymous users.
|
|
|
|
* @param {jQuery.Object} $watchstar
|
|
|
|
*/
|
|
|
|
function initWatchstarCta( $watchstar ) {
|
|
|
|
var watchCtaDrawer;
|
|
|
|
// show a CTA for anonymous users
|
|
|
|
$watchstar.on( 'click', function ( ev ) {
|
|
|
|
if ( !watchCtaDrawer ) {
|
|
|
|
watchCtaDrawer = CtaDrawer( {
|
|
|
|
content: mw.msg( 'minerva-watchlist-cta' ),
|
|
|
|
queryParams: {
|
|
|
|
warning: 'mobile-frontend-watchlist-purpose',
|
|
|
|
campaign: 'mobile_watchPageActionCta',
|
|
|
|
returntoquery: 'article_action=watch'
|
|
|
|
},
|
2019-12-16 23:47:54 +00:00
|
|
|
onShow: function () {
|
|
|
|
drawers.onShow();
|
|
|
|
},
|
|
|
|
onBeforeHide: drawers.discardDrawer,
|
2019-09-19 21:19:07 +00:00
|
|
|
signupQueryParams: {
|
|
|
|
warning: 'mobile-frontend-watchlist-signup-action'
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
watchCtaDrawer.show();
|
2019-12-16 23:47:54 +00:00
|
|
|
drawers.displayDrawer( watchCtaDrawer, { hideOnScroll: true } );
|
2019-09-19 21:19:07 +00:00
|
|
|
// prevent default to stop the user
|
|
|
|
// being navigated to Special:UserLogin
|
|
|
|
ev.preventDefault();
|
2019-12-16 23:47:54 +00:00
|
|
|
ev.stopPropagation();
|
2019-09-19 21:19:07 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
initWatchstarCta: initWatchstarCta,
|
|
|
|
initRedlinksCta: initRedlinksCta
|
|
|
|
};
|