Debian Codegraph @

extensions/Echo/modules/mobile/notifications.js

raw symbols SCIP
1 const mobile = require( 'mobile.startup' );
2
3 /**
4 * @module module:ext.echo.mobile
5 */
6
7 /**
8 * @fires module:ext.echo.mobile#echo.mobile every time the notifications overlay is opened
9 */
10 function onOpenNotificationsOverlay() {
11 mw.hook( 'echo.mobile' ).fire( true );
12 }
13
14 /**
15 * @fires module:ext.echo.mobile#echo.mobile every time the notifications overlay is closed
16 */
17 function onCloseNotificationsOverlay() {
18 mw.hook( 'echo.mobile' ).fire( false );
19 }
20
21 /**
22 * This code loads the necessary modules for the notifications overlay, not to be confused
23 * with the Toast notifications defined by common/toast.js.
24 */
25 function init() {
26 const notificationsFilterOverlay = require( './notificationsFilterOverlay.js' ),
27 notificationsOverlay = require( './overlay.js' ),
28 overlayManager = mobile.getOverlayManager();
29
30 function showNotificationOverlay() {
31 const overlay = notificationsOverlay(
32 ( exit ) => {
33 onCloseNotificationsOverlay();
34 exit();
35 } );
36 onOpenNotificationsOverlay();
37
38 return overlay;
39 }
40
41 let initialized = false;
42 // Once the DOM is loaded add the overlay and overlay manager. Minerva will handle the
43 // notification button that will link to Special:Notifications.
44 $( () => {
45 overlayManager.add( /^\/notifications$/, showNotificationOverlay );
46
47 /**
48 * Adds a filter button to the UI inside notificationsInboxWidget
49 *
50 * @method
51 * @ignore
52 */
53 function addFilterButton() {
54 // Create filter button once the notifications overlay has been loaded
55 const filterStatusButton = new OO.ui.ButtonWidget(
56 {
57 href: '#/notifications-filter',
58 classes: [ 'mw-echo-ui-notificationsInboxWidget-main-toolbar-nav-filter-placeholder' ],
59 icon: 'funnel',
60 label: mw.msg( 'echo-mobile-notifications-filter-title' )
61 } );
62
63 // eslint-disable-next-line no-jquery/no-global-selector
64 $( '.mw-echo-ui-notificationsInboxWidget-cell-placeholder' ).append(
65 $( '<div>' )
66 .addClass( 'mw-echo-ui-notificationsInboxWidget-main-toolbar-nav-filter' )
67 .addClass( 'mw-echo-ui-notificationsInboxWidget-cell' )
68 .append( filterStatusButton.$element )
69 );
70 }
71
72 // This code will currently only be invoked on Special:Notifications
73 // The code is bundled here since it makes use of loadModuleScript. This also allows
74 // the possibility of invoking the filter from outside the Special page in future.
75 // Once the 'ext.echo.special.onInitialize' hook has fired, load notification filter.
76 mw.hook( 'ext.echo.special.onInitialize' ).add( () => {
77 // eslint-disable-next-line no-jquery/no-global-selector
78 const $crossWikiUnreadFilter = $( '.mw-echo-ui-crossWikiUnreadFilterWidget' ),
79 // eslint-disable-next-line no-jquery/no-global-selector
80 $notifReadState = $( '.mw-echo-ui-notificationsInboxWidget-main-toolbar-readState' );
81
82 // The 'ext.echo.special.onInitialize' hook is fired whenever special page notification
83 // changes display on click of a filter.
84 // Hence the hook is restricted from firing more than once.
85 if ( initialized ) {
86 return;
87 }
88
89 // setup the filter button (now we have OOjs UI)
90 addFilterButton();
91
92 // setup route
93 overlayManager.add( /^\/notifications-filter$/, () => {
94 onOpenNotificationsOverlay();
95 return notificationsFilterOverlay( {
96 onBeforeExit: function ( exit ) {
97 onCloseNotificationsOverlay();
98 exit();
99 },
100 $notifReadState: $notifReadState,
101 $crossWikiUnreadFilter: $crossWikiUnreadFilter
102 } );
103 } );
104 initialized = true;
105 } );
106 } );
107
108 }
109
110 module.exports.init = init;