Debian Codegraph @

skins/MinervaNeue/resources/skins.minerva.scripts/drawers.js

raw symbols SCIP
1 const $drawerContainer = $( document.body );
2 const BODY_CLASS_SCROLL_LOCKED = 'has-drawer--with-scroll-locked';
3
4 /**
5 * Discard a drawer from display on the page.
6 *
7 * @private
8 * @param {Drawer} drawer
9 */
10 function discardDrawer( drawer ) {
11 // remove the class
12 $drawerContainer.removeClass( BODY_CLASS_SCROLL_LOCKED );
13 // FIXME: queue removal from DOM (using setTimeout so that any animations have time to run)
14 // This works around an issue in MobileFrontend that the Drawer onBeforeHide method is
15 // called /before/ the animation for closing has completed. This needs to be accounted
16 // for in Drawer so this function can be synchronous.
17 setTimeout( () => {
18 // detach the node from the DOM. Use detach rather than remove to allow reuse without
19 // losing any existing events.
20 drawer.$el.detach();
21 }, 100 );
22 }
23
24 /**
25 * Lock scroll of viewport.
26 *
27 * @ignore
28 */
29 function lockScroll() {
30 $drawerContainer.addClass( BODY_CLASS_SCROLL_LOCKED );
31 }
32
33 /**
34 * @param {Drawer} drawer to display
35 * @param {Object} options for display
36 * @param {boolean} options.hideOnScroll whether a scroll closes the drawer
37 * @ignore
38 */
39 function displayDrawer( drawer, options ) {
40 $drawerContainer.append( drawer.$el );
41 drawer.show();
42 if ( options.hideOnScroll ) {
43 $( window ).one( 'scroll.drawer', () => {
44 drawer.hide();
45 } );
46 }
47 }
48 module.exports = {
49 displayDrawer,
50 lockScroll,
51 discardDrawer
52 };