Content deleted Content added
←Created page with 'mw.loader.load( '/w/index.php?title=User:Jdlrobson/scripts/backtotop.css&action=raw&ctype=text/css', 'text/css' ).then(function () { var backtotop, // eslint-...' Tags: Mobile edit Mobile web edit |
No edit summary Tags: Mobile edit Mobile web edit |
||
Line 1:
mw.loader.load( '/w/index.php?title=User:Jdlrobson/scripts/backtotop.css&action=raw&ctype=text/css', 'text/css' )
var backtotop,
// eslint-disable-next-line no-restricted-properties
M = mw.mobileFrontend,
mobile = M.require( 'mobile.startup' ),
View = mobile.View,
browser = mobile.Browser.getSingleton(),
eventBus = mobile.eventBusSingleton;
/**
* Displays a little arrow at the bottom right of the viewport.
* @class BackToTopOverlay
* @extends View
* @param {Object} props
*/
function BackToTopOverlay( props ) {
View.call( this,
$.extend( {}, props, {
className: 'backtotop',
events: { click: 'onBackToTopClick' }
} )
);
}
OO.inheritClass( BackToTopOverlay, View );
BackToTopOverlay.prototype.template = mw.template.get( 'skins.minerva.options', 'BackToTopOverlay.mustache' );
* @memberof BackToTopOverlay
* @instance
*/
BackToTopOverlay.prototype.hide = function () {
this.$el.removeClass( 'visible' );
};
/**
* Handles the click on the "Back to top" element and scrolls back
* to the top smoothly.
* @memberof BackToTopOverlay
* @instance
*/
BackToTopOverlay.prototype.onBackToTopClick = function () {
// eslint-disable-next-line no-jquery/no-global-selector
$( 'html, body' ).animate( { scrollTop: 0 }, 400 );
};
backtotop = new BackToTopOverlay();
// initialize the back to top element
backtotop.appendTo( 'body' );
eventBus.on( 'scroll', function () {
if ( $( window ).height() - $( window ).scrollTop() <= 0 ) {
backtotop.show();
} else {
backtotop.hide();
}
} );
|