mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-12-22 10:33:24 +00:00
842a91590a
* eslint-config-wikimedia: 0.27.0 → 0.28.2 The following rules are failing and were disabled: * tests/selenium: * implicit-arrow-linebreak * no-mixed-spaces-and-tabs * grunt-banana-checker: 0.11.1 → 0.13.0 * stylelint-config-wikimedia: 0.16.1 → 0.17.2 The following rules no longer exist and were removed: * stylistic/selector-list-comma-newline-after * braces: 3.0.2 → 3.0.3 * https://github.com/advisories/GHSA-grv7-fg5c-xmjg Change-Id: Ia94454c1da778f241085714e1601a0233d547570
53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
const $drawerContainer = $( document.body );
|
|
const BODY_CLASS_SCROLL_LOCKED = 'has-drawer--with-scroll-locked';
|
|
|
|
/**
|
|
* Discard a drawer from display on the page.
|
|
*
|
|
* @private
|
|
* @param {Drawer} drawer
|
|
*/
|
|
function discardDrawer( drawer ) {
|
|
// remove the class
|
|
$drawerContainer.removeClass( BODY_CLASS_SCROLL_LOCKED );
|
|
// FIXME: queue removal from DOM (using setTimeout so that any animations have time to run)
|
|
// This works around an issue in MobileFrontend that the Drawer onBeforeHide method is
|
|
// called /before/ the animation for closing has completed. This needs to be accounted
|
|
// for in Drawer so this function can be synchronous.
|
|
setTimeout( () => {
|
|
// detach the node from the DOM. Use detach rather than remove to allow reuse without
|
|
// losing any existing events.
|
|
drawer.$el.detach();
|
|
}, 100 );
|
|
}
|
|
|
|
/**
|
|
* Lock scroll of viewport.
|
|
*
|
|
* @ignore
|
|
*/
|
|
function lockScroll() {
|
|
$drawerContainer.addClass( BODY_CLASS_SCROLL_LOCKED );
|
|
}
|
|
|
|
/**
|
|
* @param {Drawer} drawer to display
|
|
* @param {Object} options for display
|
|
* @param {boolean} options.hideOnScroll whether a scroll closes the drawer
|
|
* @ignore
|
|
*/
|
|
function displayDrawer( drawer, options ) {
|
|
$drawerContainer.append( drawer.$el );
|
|
drawer.show();
|
|
if ( options.hideOnScroll ) {
|
|
$( window ).one( 'scroll.drawer', () => {
|
|
drawer.hide();
|
|
} );
|
|
}
|
|
}
|
|
module.exports = {
|
|
displayDrawer,
|
|
lockScroll,
|
|
discardDrawer
|
|
};
|