Debian Codegraph @

skins/MinervaNeue/resources/skins.minerva.scripts/ctaDrawers.js

raw symbols SCIP
1 const mobile = require( 'mobile.startup' );
2 const drawers = require( './drawers.js' );
3 const CtaDrawer = mobile.CtaDrawer;
4
5 /**
6 * Initialize red links call-to-action
7 *
8 * Upon clicking a red link, show an interstitial CTA explaining that the page doesn't exist
9 * with a button to create it, rather than directly navigate to the edit form.
10 *
11 * Special case T201339: following a red link to a user or user talk page should not prompt for
12 * its creation. The reasoning is that user pages should be created by their owners and it's far
13 * more common that non-owners follow a user's red linked user page to consider their
14 * contributions, account age, or other activity.
15 *
16 * For example, a user adds a section to a Talk page and signs their contribution (which creates
17 * a link to their user page whether exists or not). If the user page does not exist, that link
18 * will be red. In both cases, another user follows this link, not to edit create a page for
19 * that user but to obtain information on them.
20 *
21 * @private
22 * @param {jQuery} $redLinks
23 */
24 function initRedlinksCta( $redLinks ) {
25 $redLinks.on( 'click', function ( ev ) {
26 const drawerOptions = {
27 progressiveButton: {
28 progressive: true,
29 label: mw.msg( 'mobile-frontend-editor-redlink-create' ),
30 href: $( this ).attr( 'href' )
31 },
32 actionAnchor: {
33 progressive: true,
34 label: mw.msg( 'mobile-frontend-editor-redlink-leave' ),
35 additionalClassNames: 'cancel'
36 },
37 onBeforeHide: drawers.discardDrawer,
38 content: mw.msg( 'mobile-frontend-editor-redlink-explain' )
39 },
40 drawer = CtaDrawer( drawerOptions );
41
42 // use preventDefault() and not return false to close other open
43 // drawers or anything else.
44 ev.preventDefault();
45 ev.stopPropagation();
46 drawers.displayDrawer( drawer, { hideOnScroll: true } );
47 } );
48 }
49
50 /**
51 * A CtaDrawer should show for anonymous users.
52 *
53 * @param {jQuery} $watchstar
54 * @ignore
55 */
56 function initWatchstarCta( $watchstar ) {
57 let watchCtaDrawer;
58 // show a CTA for anonymous users
59 $watchstar.on( 'click', ( ev ) => {
60 if ( !watchCtaDrawer ) {
61 watchCtaDrawer = CtaDrawer( {
62 content: mw.msg( 'minerva-watchlist-cta' ),
63 queryParams: {
64 notice: 'mobile-frontend-watchlist-purpose',
65 campaign: 'mobile_watchPageActionCta',
66 returntoquery: 'article_action=watch'
67 },
68 onBeforeHide: drawers.discardDrawer,
69 signupQueryParams: {
70 notice: 'mobile-frontend-watchlist-signup-action'
71 }
72 } );
73 }
74 // If it's already shown dont display again
75 // (if user is clicking fast since we are reusing the drawer
76 // this might result in the drawer opening and closing)
77 if ( !watchCtaDrawer.$el[ 0 ].parentNode ) {
78 drawers.displayDrawer( watchCtaDrawer, { hideOnScroll: true } );
79 }
80 // prevent default to stop the user
81 // being navigated to Special:UserLogin
82 ev.preventDefault();
83 // Don't stopProgation, as we want WikimediaEvents to log clicks to this.
84 } );
85 }
86
87 module.exports = {
88 initWatchstarCta: initWatchstarCta,
89 initRedlinksCta: initRedlinksCta
90 };