2017-07-12 15:12:40 +00:00
|
|
|
/*
|
|
|
|
* This code loads the necessary modules for the notifications overlay, not to be confused
|
|
|
|
* with the Toast notifications defined by common/toast.js.
|
|
|
|
*/
|
2018-11-16 15:16:25 +00:00
|
|
|
( function ( M ) {
|
2019-03-19 23:21:56 +00:00
|
|
|
var badge,
|
|
|
|
mainMenu = M.require( 'skins.minerva.scripts/mainMenu' ),
|
2017-07-12 15:12:40 +00:00
|
|
|
router = require( 'mediawiki.router' ),
|
2019-03-19 23:21:56 +00:00
|
|
|
mobile = M.require( 'mobile.startup' ),
|
|
|
|
util = mobile.util,
|
2017-07-12 15:12:40 +00:00
|
|
|
NotificationBadge = M.require( 'skins.minerva.notifications/NotificationBadge' ),
|
|
|
|
overlayManager = M.require( 'skins.minerva.scripts/overlayManager' ),
|
|
|
|
initialized = false;
|
|
|
|
|
2019-03-19 23:21:56 +00:00
|
|
|
function showNotificationOverlay() {
|
2019-04-03 23:32:18 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2019-03-19 23:21:56 +00:00
|
|
|
var $pageCenter = $( '#mw-mf-page-center' ),
|
|
|
|
overlay = mobile.notifications.overlay( badge.setCount.bind( badge ),
|
|
|
|
badge.markAsSeen.bind( badge ) );
|
|
|
|
mainMenu.openNavigationDrawer( 'secondary' );
|
|
|
|
overlay.on( 'hide', function () {
|
|
|
|
mainMenu.closeNavigationDrawers();
|
|
|
|
$pageCenter.off( '.secondary' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
$pageCenter.one( 'click.secondary', function () {
|
|
|
|
router.back();
|
|
|
|
} );
|
|
|
|
return overlay;
|
|
|
|
}
|
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
// Once the DOM is loaded hijack the notifications button to display an overlay rather
|
|
|
|
// than linking to Special:Notifications.
|
2019-03-19 23:21:56 +00:00
|
|
|
util.docReady( function () {
|
|
|
|
badge = new NotificationBadge( {
|
|
|
|
onClick: function () {
|
|
|
|
router.navigate( '#/notifications' );
|
|
|
|
// Important that we also prevent propagation to avoid interference
|
|
|
|
// with events that may
|
|
|
|
// be binded on #mw-mf-page-center that close overlay
|
|
|
|
return false;
|
|
|
|
},
|
2019-04-03 23:32:18 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2019-06-19 17:31:16 +00:00
|
|
|
el: $( '#user-notifications.user-button' ).parent()
|
2017-07-12 15:12:40 +00:00
|
|
|
} );
|
2019-03-19 23:21:56 +00:00
|
|
|
overlayManager.add( /^\/notifications$/, showNotificationOverlay );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a filter button to the UI inside notificationsInboxWidget
|
|
|
|
* @method
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function addFilterButton() {
|
|
|
|
// Create filter button once the notifications overlay has been loaded
|
|
|
|
var filterStatusButton = new OO.ui.ButtonWidget(
|
|
|
|
{
|
|
|
|
href: '#/notifications-filter',
|
|
|
|
classes: [ 'mw-echo-ui-notificationsInboxWidget-main-toolbar-nav-filter-placeholder' ],
|
|
|
|
icon: 'funnel',
|
|
|
|
label: mw.msg( 'mobile-frontend-notifications-filter' )
|
|
|
|
} );
|
|
|
|
|
2019-04-03 23:32:18 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2017-07-12 15:12:40 +00:00
|
|
|
$( '.mw-echo-ui-notificationsInboxWidget-cell-placeholder' ).append(
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationsInboxWidget-main-toolbar-nav-filter' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationsInboxWidget-cell' )
|
|
|
|
.append( filterStatusButton.$element )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This code will currently only be invoked on Special:Notifications
|
|
|
|
// The code is bundled here since it makes use of loadModuleScript. This also allows
|
|
|
|
// the possibility of invoking the filter from outside the Special page in future.
|
|
|
|
// Once the 'ext.echo.special.onInitialize' hook has fired, load notification filter.
|
|
|
|
mw.hook( 'ext.echo.special.onInitialize' ).add( function () {
|
2018-09-13 15:33:20 +00:00
|
|
|
// The 'ext.echo.special.onInitialize' hook is fired whenever special page notification
|
|
|
|
// changes display on click of a filter.
|
2017-07-12 15:12:40 +00:00
|
|
|
// Hence the hook is restricted from firing more than once.
|
|
|
|
if ( initialized ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the notification filter overlay
|
2019-01-09 16:57:40 +00:00
|
|
|
mw.loader.using( 'mobile.notifications.overlay' ).then( function () {
|
2019-04-03 23:32:18 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2017-07-12 15:12:40 +00:00
|
|
|
var $crossWikiUnreadFilter = $( '.mw-echo-ui-crossWikiUnreadFilterWidget' ),
|
2019-04-03 23:32:18 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2017-07-12 15:12:40 +00:00
|
|
|
$notifReadState = $( '.mw-echo-ui-notificationsInboxWidget-main-toolbar-readState' ),
|
2019-01-09 16:57:40 +00:00
|
|
|
NotificationsFilterOverlay = M.require( 'mobile.notifications.overlay/NotificationsFilterOverlay' );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
// setup the filter button (now we have OOjs UI)
|
|
|
|
addFilterButton();
|
|
|
|
|
|
|
|
// setup route
|
|
|
|
overlayManager.add( /^\/notifications-filter$/, function () {
|
|
|
|
mainMenu.openNavigationDrawer( 'secondary' );
|
|
|
|
return new NotificationsFilterOverlay( {
|
|
|
|
$notifReadState: $notifReadState,
|
|
|
|
mainMenu: mainMenu,
|
|
|
|
$crossWikiUnreadFilter: $crossWikiUnreadFilter
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
initialized = true;
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2018-11-16 15:16:25 +00:00
|
|
|
}( mw.mobileFrontend ) );
|