Debian Codegraph @

extensions/Echo/modules/mobile/overlay.js

raw symbols SCIP
1 /**
2 * @module module:ext.echo.mobile
3 */
4
5 const mobile = require( 'mobile.startup' ),
6 Overlay = mobile.Overlay,
7 list = require( './list.js' ),
8 promisedView = mobile.promisedView,
9 View = mobile.View;
10
11 /**
12 * @param {Overlay} overlay
13 * @param {Function} exit
14 */
15 function onBeforeExitAnimation( overlay, exit ) {
16 if ( getComputedStyle( overlay.$el[ 0 ] ).transitionDuration !== '0s' ) {
17 // Manually detach the overlay from DOM once hide animation completes.
18 overlay.$el[ 0 ].addEventListener( 'transitionend', exit, { once: true } );
19
20 // Kick off animation.
21 overlay.$el[ 0 ].classList.remove( 'visible' );
22 } else {
23 exit();
24 }
25 }
26
27 /**
28 * @param {number} count a capped (0-99 or 99+) count.
29 */
30 function onCountChange( count ) {
31 mw.hook( 'ext.echo.badge.countChange' ).fire(
32 'all',
33 count,
34 mw.msg( 'echo-badge-count',
35 mw.language.convertNumber( count )
36 )
37 );
38 }
39
40 /**
41 * Make a notification overlay
42 *
43 * @param {Function} onBeforeExit
44 * @return {Overlay}
45 */
46 function notificationsOverlay( onBeforeExit ) {
47 let markAllReadButton;
48 const oouiPromise = mw.loader.using( 'oojs-ui' ).then( () => {
49 markAllReadButton = new OO.ui.ButtonWidget( {
50 icon: 'checkAll'
51 } );
52 return View.make(
53 { class: 'notifications-overlay-header-markAllRead' },
54 [ markAllReadButton.$element ]
55 );
56 } );
57 const markAllReadButtonView = promisedView( oouiPromise );
58 // hide the button spinner as it is confusing to see in the top right corner
59 markAllReadButtonView.$el.hide();
60
61 const overlay = Overlay.make(
62 {
63 heading: '<strong>' + mw.message( 'notifications' ).escaped() + '</strong>',
64 footerAnchor: {
65 href: mw.util.getUrl( 'Special:Notifications' ),
66 progressive: true,
67 additionalClassNames: 'footer-link notifications-archive-link',
68 label: mw.msg( 'echo-overlay-link' )
69 },
70 headerActions: [ markAllReadButtonView ],
71 isBorderBox: false,
72 className: 'overlay notifications-overlay navigation-drawer',
73 onBeforeExit: function ( exit ) {
74 onBeforeExit( () => {
75 onBeforeExitAnimation( overlay, exit );
76 } );
77 }
78 },
79 promisedView(
80 oouiPromise.then( () => list( mw.echo, markAllReadButton, onCountChange ) )
81 )
82 );
83 return overlay;
84 }
85
86 module.exports = notificationsOverlay;