Remove usage of global event emitter from Minerva

This patch removes the remaining usages of M.on/M.off/M.emit
(functionality derived from moduleLoader.js in MobileFrontend) in
Minerva and continues the work of
Id990b0e1a53221d5c1cb3e3012aed0e27d801fc2 (patch for MobileFrontend).

This patch and the patch for MobileFrontend should be merged together as
they both depend on eachother.

Depends-On: Id990b0e1a53221d5c1cb3e3012aed0e27d801fc2
Bug: T156186
Change-Id: I005d2fcdbf91c2f1ac98178dfa388aa8174e7530
This commit is contained in:
Nicholas Ray 2018-12-04 15:13:38 -07:00
parent 8feff10336
commit 5bfd949f9a
6 changed files with 41 additions and 13 deletions

View file

@ -2,7 +2,8 @@
var BackToTopOverlay = M.require( 'skins.minerva.options/BackToTopOverlay' ),
backtotop = new BackToTopOverlay(),
features = mw.config.get( 'wgMinervaFeatures', {} ),
browser = M.require( 'mobile.startup/Browser' ).getSingleton();
browser = M.require( 'mobile.startup/Browser' ).getSingleton(),
eventBus = M.require( 'mobile.startup/eventBusSingleton' );
// check if browser user agent is iOS (T141598)
if ( browser.isIos() || !features.backToTop ) {
@ -12,7 +13,7 @@
// initialize the back to top element
backtotop.appendTo( 'body' );
M.on( 'scroll', function () {
eventBus.on( 'scroll', function () {
if ( $( window ).height() - $( window ).scrollTop() <= 0 ) {
backtotop.show();
} else {

View file

@ -3,6 +3,7 @@
var loader = M.require( 'mobile.startup/rlModuleLoader' ),
features = mw.config.get( 'wgMinervaFeatures', {} ),
overlayManager = M.require( 'skins.minerva.scripts/overlayManager' ),
eventBus = M.require( 'mobile.startup/eventBusSingleton' ),
isAnon = mw.user.isAnon();
// check the categories feature has been turned on
@ -14,7 +15,7 @@
overlayManager.add( /^\/categories$/, function () {
return loader.loadModule( 'mobile.categories.overlays', true ).then( function ( loadingOverlay ) {
var CategoryOverlay = M.require( 'mobile.categories.overlays/CategoryOverlay' );
M.on( 'category-added', function () {
eventBus.on( 'category-added', function () {
window.location.hash = '#/categories';
} );
@ -22,7 +23,8 @@
return new CategoryOverlay( {
api: new mw.Api(),
isAnon: isAnon,
title: M.getCurrentPage().title
title: M.getCurrentPage().title,
eventBus: eventBus
} );
} );
} );
@ -36,7 +38,8 @@
return new CategoryAddOverlay( {
api: new mw.Api(),
isAnon: isAnon,
title: M.getCurrentPage().title
title: M.getCurrentPage().title,
eventBus: eventBus
} );
} );
} );

View file

@ -16,7 +16,8 @@
overlayManager = OverlayManager.getSingleton(),
page = M.getCurrentPage(),
api = new mw.Api(),
thumbs = page.getThumbnails();
thumbs = page.getThumbnails(),
eventBus = M.require( 'mobile.startup/eventBusSingleton' );
/**
* Event handler for clicking on an image thumbnail
@ -116,7 +117,8 @@
imageOverlay = new ImageOverlay( {
api: api,
thumbnails: thumbs,
title: decodeURIComponent( title )
title: decodeURIComponent( title ),
eventBus: eventBus
} );
imageOverlay.on( ImageOverlay.EVENT_EXIT, function () {
// Actually dismiss the overlay whenever the cross is closed.
@ -361,7 +363,7 @@
initModifiedInfo();
initRegistrationInfo();
initHistoryLink( $( '.last-modifier-tagline a' ) );
M.on( 'resize', loadTabletModules );
eventBus.on( 'resize', loadTabletModules );
loadTabletModules();
appendDownloadButton();
initRedlinksCta();

View file

@ -1,6 +1,7 @@
( function ( M ) {
var TableOfContents = M.require( 'mobile.toc/TableOfContents' ),
Toggler = M.require( 'mobile.toggle/Toggler' );
Toggler = M.require( 'mobile.toggle/Toggler' ),
eventBus = M.require( 'mobile.startup/eventBusSingleton' );
/**
* Create TableOfContents if the given Page has sections and is not the main page
@ -19,7 +20,13 @@
} );
// eslint-disable-next-line no-new
new Toggler( toc.$el, 'toc-', null, true );
new Toggler( {
$container: toc.$el,
prefix: 'toc-',
page: null,
isClosed: true,
eventBus: eventBus
} );
// if there is a toc already, replace it
if ( $toc.length > 0 ) {
// don't show toc at end of page, when no sections there

View file

@ -1,7 +1,8 @@
( function ( M ) {
var page = M.getCurrentPage(),
$contentContainer = $( '#mw-content-text > .mw-parser-output' ),
Toggler = M.require( 'mobile.toggle/Toggler' );
Toggler = M.require( 'mobile.toggle/Toggler' ),
eventBus = M.require( 'mobile.startup/eventBusSingleton' );
if ( !page.getLeadSectionElement() ) {
// Operating in desktop Minerva mode. Stop execution. (T172948)
@ -31,7 +32,12 @@
delete window.mfTempOpenSection;
}
// eslint-disable-next-line no-new
new Toggler( $container, prefix, page );
new Toggler( {
$container: $container,
prefix: prefix,
page: page,
eventBus: eventBus
} );
}
// avoid this running on Watchlist

View file

@ -11,7 +11,12 @@
QUnit.module( 'Minerva DownloadIcon', {
beforeEach: function () {
this.skin = new Skin( {} );
this.skin = new Skin( {
eventBus: {
on: function () {},
off: function () {}
}
} );
}
} );
@ -74,6 +79,10 @@
QUnit.module( 'Minerva DownloadIcon.isAvailable()', {
beforeEach: function () {
this.skin = new Skin( {
eventBus: {
on: function () {},
off: function () {}
},
page: new Page( {
id: 0,
title: 'Test',