2024-03-24 20:53:43 +00:00
|
|
|
const mobile = require( 'mobile.startup' );
|
|
|
|
const drawers = require( './drawers.js' );
|
|
|
|
const CtaDrawer = mobile.CtaDrawer;
|
2019-09-19 21:19:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2024-06-26 13:23:40 +00:00
|
|
|
* @private
|
2023-10-19 14:07:38 +00:00
|
|
|
* @param {jQuery} $redLinks
|
2019-09-19 21:19:07 +00:00
|
|
|
*/
|
|
|
|
function initRedlinksCta( $redLinks ) {
|
|
|
|
$redLinks.on( 'click', function ( ev ) {
|
2024-03-24 20:53:43 +00:00
|
|
|
const drawerOptions = {
|
2023-11-07 16:29:17 +00:00
|
|
|
progressiveButton: {
|
2019-09-19 21:19:07 +00:00
|
|
|
progressive: true,
|
|
|
|
label: mw.msg( 'mobile-frontend-editor-redlink-create' ),
|
|
|
|
href: $( this ).attr( 'href' )
|
2023-11-07 16:29:17 +00:00
|
|
|
},
|
|
|
|
actionAnchor: {
|
2019-09-19 21:19:07 +00:00
|
|
|
progressive: true,
|
|
|
|
label: mw.msg( 'mobile-frontend-editor-redlink-leave' ),
|
|
|
|
additionalClassNames: 'cancel'
|
2023-11-07 16:29:17 +00:00
|
|
|
},
|
2019-12-16 23:47:54 +00:00
|
|
|
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.
|
2020-06-02 21:21:44 +00:00
|
|
|
*
|
2023-10-19 14:07:38 +00:00
|
|
|
* @param {jQuery} $watchstar
|
2024-06-26 13:23:40 +00:00
|
|
|
* @ignore
|
2019-09-19 21:19:07 +00:00
|
|
|
*/
|
|
|
|
function initWatchstarCta( $watchstar ) {
|
2024-03-24 20:53:43 +00:00
|
|
|
let watchCtaDrawer;
|
2019-09-19 21:19:07 +00:00
|
|
|
// show a CTA for anonymous users
|
2024-06-03 12:06:43 +00:00
|
|
|
$watchstar.on( 'click', ( ev ) => {
|
2019-09-19 21:19:07 +00:00
|
|
|
if ( !watchCtaDrawer ) {
|
|
|
|
watchCtaDrawer = CtaDrawer( {
|
|
|
|
content: mw.msg( 'minerva-watchlist-cta' ),
|
|
|
|
queryParams: {
|
2024-07-23 08:52:44 +00:00
|
|
|
notice: 'mobile-frontend-watchlist-purpose',
|
2019-09-19 21:19:07 +00:00
|
|
|
campaign: 'mobile_watchPageActionCta',
|
|
|
|
returntoquery: 'article_action=watch'
|
|
|
|
},
|
2019-12-16 23:47:54 +00:00
|
|
|
onBeforeHide: drawers.discardDrawer,
|
2019-09-19 21:19:07 +00:00
|
|
|
signupQueryParams: {
|
2024-07-23 08:52:44 +00:00
|
|
|
notice: 'mobile-frontend-watchlist-signup-action'
|
2019-09-19 21:19:07 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
2020-01-14 19:38:41 +00:00
|
|
|
// If it's already shown dont display again
|
|
|
|
// (if user is clicking fast since we are reusing the drawer
|
|
|
|
// this might result in the drawer opening and closing)
|
|
|
|
if ( !watchCtaDrawer.$el[ 0 ].parentNode ) {
|
|
|
|
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();
|
2021-11-05 00:52:30 +00:00
|
|
|
// Don't stopProgation, as we want WikimediaEvents to log clicks to this.
|
2019-09-19 21:19:07 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
initWatchstarCta: initWatchstarCta,
|
|
|
|
initRedlinksCta: initRedlinksCta
|
|
|
|
};
|