mediawiki-skins-MinervaNeue/resources/skins.minerva.options/backtotop.js
Nicholas Ray 5bfd949f9a 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
2018-12-06 19:30:09 -07:00

24 lines
693 B
JavaScript

( function ( M ) {
var BackToTopOverlay = M.require( 'skins.minerva.options/BackToTopOverlay' ),
backtotop = new BackToTopOverlay(),
features = mw.config.get( 'wgMinervaFeatures', {} ),
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 ) {
return;
}
// initialize the back to top element
backtotop.appendTo( 'body' );
eventBus.on( 'scroll', function () {
if ( $( window ).height() - $( window ).scrollTop() <= 0 ) {
backtotop.show();
} else {
backtotop.hide();
}
} );
}( mw.mobileFrontend ) );