Jdlrobson has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/351211 )

Change subject: Hygiene: Notification filter
......................................................................

Hygiene: Notification filter

Address bug:
* Move creation of OOjs UI element inside loadModuleScript as
OOjs UI is not available until that happens (this was breaking
with cache disabled intermittenly)

Several improvements for readability:
* Create generic openNavigationDrawer click handler (DRY)
* Pass mainMenu to NotificationsFilterOverlay
* Use href option for Button widget rather than binding

Change-Id: I7a67f7343559927ed350b0db7a6833d273a81d64
---
M resources/mobile.notifications.filter.overlay/NotificationsFilterOverlay.js
M resources/skins.minerva.notifications/init.js
2 files changed, 54 insertions(+), 59 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/11/351211/1

diff --git 
a/resources/mobile.notifications.filter.overlay/NotificationsFilterOverlay.js 
b/resources/mobile.notifications.filter.overlay/NotificationsFilterOverlay.js
index 68a4ca5..7499ff8 100644
--- 
a/resources/mobile.notifications.filter.overlay/NotificationsFilterOverlay.js
+++ 
b/resources/mobile.notifications.filter.overlay/NotificationsFilterOverlay.js
@@ -16,6 +16,9 @@
                Overlay.apply( this, options );
 
                // Initialize
+               this.on( 'hide', function () {
+                       options.mainMenu.closeNavigationDrawers();
+               } );
                this.$( '.overlay-content' ).append(
                        $( '<div>' )
                                .addClass( 
'notifications-filter-overlay-read-state' )
diff --git a/resources/skins.minerva.notifications/init.js 
b/resources/skins.minerva.notifications/init.js
index c6f481f..bebb3d0 100644
--- a/resources/skins.minerva.notifications/init.js
+++ b/resources/skins.minerva.notifications/init.js
@@ -36,18 +36,19 @@
        // Once the DOM is loaded hijack the notifications button to display an 
overlay rather
        // than linking to Special:Notifications.
        $( function () {
-               var filterOverlayDeferred = $.Deferred(),
-                       $notifReadState,
-                       $crossWikiUnreadFilter,
-                       filterStatusButton,
-                       $readStateButton;
 
-               $btn.on( 'click', function () {
+               /**
+                * Click event handler which opens the drawer and disables 
default link behaviour
+                * @method
+                * @ignore
+                */
+               function openNavigationDrawer() {
                        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;
-               } );
+               }
+               $btn.on( 'click', openNavigationDrawer );
 
                /**
                 * Load the notification overlay.
@@ -86,71 +87,62 @@
                        } );
                } );
 
-               // 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 () {
-                       overlayManager.add( /^\/notifications-filter$/, 
function () {
-                               return filterOverlayDeferred.then( function ( 
overlay ) {
-                                       mainMenu.openNavigationDrawer( 
'secondary' );
-                                       overlay.on( 'hide', function () {
-                                               
mainMenu.closeNavigationDrawers();
-                                       } );
-                                       return overlay;
-                               } );
-                       } );
-
-                       // The 'ext.echo.special.onInitialize' hook is fired 
whenever special page notification changes display on click of a filter.
-                       // Hence the hook is restricted from firing more than 
once.
-                       if ( initialized ) {
-                               return;
-                       }
-                       $crossWikiUnreadFilter = $( 
'.mw-echo-ui-crossWikiUnreadFilterWidget' );
-                       $notifReadState = $( 
'.mw-echo-ui-notificationsInboxWidget-main-toolbar-readState' );
-                       $readStateButton = $notifReadState.find( 
'.oo-ui-buttonElement' );
-
-                       // Load the notification filter overlay
-                       loadModuleScript( 'mobile.notifications.filter.overlay' 
).done( function () {
-                               var NotificationsFilterOverlay = M.require( 
'mobile.notifications.filter.overlay/NotificationsFilterOverlay' );
-                               filterOverlayDeferred.resolve(
-                                       new NotificationsFilterOverlay( {
-                                               $notifReadState: 
$notifReadState,
-                                               $crossWikiUnreadFilter: 
$crossWikiUnreadFilter
-                                       } )
-                               );
-                       } );
-
-                       $readStateButton.on( 'click', function () {
-                               router.navigate( 'Special: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;
-                       } );
-                       $crossWikiUnreadFilter.on( 'click', 
'.oo-ui-optionWidget', function () {
-                               router.navigate( 'Special: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;
-                       } );
-
+               /**
+                * Adds a filter button to the UI inside 
notificationsInboxWidget
+                * @method
+                * @ignore
+                */
+               function addFilterButton() {
                        // Create filter button once the notifications overlay 
has been loaded
-                       filterStatusButton = new OO.ui.ButtonWidget(
+                       var filterStatusButton = new OO.ui.ButtonWidget(
                                {
+                                       href: '#/notifications-filter',
                                        classes: [ 
'mw-echo-ui-notificationsInboxWidget-main-toolbar-nav-filter-placeholder' ],
                                        icon: 'funnel',
                                        label: 'Filter'
                                } );
+
                        $( 
'.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 )
                        );
+               }
 
-                       filterStatusButton.$element.on( 'click', function () {
-                               router.navigate( '#/notifications-filter' );
-                               return false;
+               // 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 () {
+                       // The 'ext.echo.special.onInitialize' hook is fired 
whenever special page notification changes display on click of a filter.
+                       // Hence the hook is restricted from firing more than 
once.
+                       if ( initialized ) {
+                               return;
+                       }
+
+                       // Load the notification filter overlay
+                       loadModuleScript( 'mobile.notifications.filter.overlay' 
).done( function () {
+                               var $crossWikiUnreadFilter = $( 
'.mw-echo-ui-crossWikiUnreadFilterWidget' ),
+                                       $notifReadState = $( 
'.mw-echo-ui-notificationsInboxWidget-main-toolbar-readState' ),
+                                       $readStateButton = 
$notifReadState.find( '.oo-ui-buttonElement' ),
+                                       NotificationsFilterOverlay = M.require( 
'mobile.notifications.filter.overlay/NotificationsFilterOverlay' );
+
+                               // setup the filter button (now we have OOjs UI)
+                               addFilterButton();
+
+                               $readStateButton.on( 'click', 
openNavigationDrawer );
+                               $crossWikiUnreadFilter.on( 'click', 
'.oo-ui-optionWidget', openNavigationDrawer );
+
+                               // setup route
+                               overlayManager.add( /^\/notifications-filter$/, 
function () {
+                                       mainMenu.openNavigationDrawer( 
'secondary' );
+                                       return new NotificationsFilterOverlay( {
+                                               $notifReadState: 
$notifReadState,
+                                               mainMenu: mainMenu,
+                                               $crossWikiUnreadFilter: 
$crossWikiUnreadFilter
+                                       } );
+                               } );
                        } );
                        initialized = true;
                } );

-- 
To view, visit https://gerrit.wikimedia.org/r/351211
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7a67f7343559927ed350b0db7a6833d273a81d64
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to