2018-11-16 15:16:25 +00:00
|
|
|
( function ( M ) {
|
2019-02-07 16:34:18 +00:00
|
|
|
var
|
|
|
|
mobile = M.require( 'mobile.startup' ),
|
2019-02-08 17:04:26 +00:00
|
|
|
mfExtend = mobile.mfExtend,
|
2019-02-07 16:34:18 +00:00
|
|
|
View = mobile.View,
|
|
|
|
util = mobile.util;
|
2017-10-23 16:37:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays a little arrow at the bottom right of the viewport.
|
|
|
|
* @class BackToTopOverlay
|
|
|
|
* @extends View
|
2018-11-22 19:10:40 +00:00
|
|
|
* @param {Object} props
|
2017-10-23 16:37:32 +00:00
|
|
|
*/
|
2018-11-22 19:10:40 +00:00
|
|
|
function BackToTopOverlay( props ) {
|
|
|
|
View.call( this,
|
|
|
|
util.extend( {}, props, {
|
2019-02-05 20:54:10 +00:00
|
|
|
className: 'backtotop',
|
|
|
|
events: { click: 'onBackToTopClick' }
|
2018-11-22 19:10:40 +00:00
|
|
|
} )
|
|
|
|
);
|
2017-10-23 16:37:32 +00:00
|
|
|
}
|
|
|
|
|
2019-02-08 17:04:26 +00:00
|
|
|
mfExtend( BackToTopOverlay, View, {
|
2018-09-26 23:03:20 +00:00
|
|
|
template: mw.template.get( 'skins.minerva.options', 'BackToTopOverlay.hogan' ),
|
2017-10-23 16:37:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the back to top element, if it's not visible already.
|
2018-08-20 23:40:40 +00:00
|
|
|
* @memberof BackToTopOverlay
|
|
|
|
* @instance
|
2017-10-23 16:37:32 +00:00
|
|
|
*/
|
|
|
|
show: function () {
|
|
|
|
this.$el.css( 'visibility', 'visible' ).addClass( 'visible' );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide the back to top element, if it's visible.
|
2018-08-20 23:40:40 +00:00
|
|
|
* @memberof BackToTopOverlay
|
|
|
|
* @instance
|
2017-10-23 16:37:32 +00:00
|
|
|
*/
|
|
|
|
hide: function () {
|
|
|
|
this.$el.removeClass( 'visible' );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the click on the "Back to top" element and scrolls back
|
|
|
|
* to the top smoothly.
|
2018-08-20 23:40:40 +00:00
|
|
|
* @memberof BackToTopOverlay
|
|
|
|
* @instance
|
2017-10-23 16:37:32 +00:00
|
|
|
*/
|
|
|
|
onBackToTopClick: function () {
|
2019-04-03 23:32:18 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2017-10-23 16:37:32 +00:00
|
|
|
$( 'html, body' ).animate( { scrollTop: 0 }, 400 );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2018-09-26 23:03:20 +00:00
|
|
|
M.define( 'skins.minerva.options/BackToTopOverlay', BackToTopOverlay );
|
2017-10-23 16:37:32 +00:00
|
|
|
|
2018-11-16 15:16:25 +00:00
|
|
|
}( mw.mobileFrontend ) );
|