{"version":3,"file":"drawer.min.js","sources":["https:\/\/edu.grsu.by\/theme\/boost\/amd\/src\/drawer.js"],"sourcesContent":["\/\/ This file is part of Moodle - http:\/\/moodle.org\/\n\/\/\n\/\/ Moodle is free software: you can redistribute it and\/or modify\n\/\/ it under the terms of the GNU General Public License as published by\n\/\/ the Free Software Foundation, either version 3 of the License, or\n\/\/ (at your option) any later version.\n\/\/\n\/\/ Moodle is distributed in the hope that it will be useful,\n\/\/ but WITHOUT ANY WARRANTY; without even the implied warranty of\n\/\/ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\/\/ GNU General Public License for more details.\n\/\/\n\/\/ You should have received a copy of the GNU General Public License\n\/\/ along with Moodle. If not, see .\n\n\/**\n * Contain the logic for a drawer.\n *\n * @package theme_boost\n * @copyright 2016 Damyon Wiese\n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\ndefine(['jquery', 'core\/custom_interaction_events', 'core\/log', 'core\/pubsub'],\n function($, CustomEvents, Log, PubSub) {\n\n var SELECTORS = {\n TOGGLE_REGION: '[data-region=\"drawer-toggle\"]',\n TOGGLE_ACTION: '[data-action=\"toggle-drawer\"]',\n TOGGLE_TARGET: 'aria-controls',\n TOGGLE_SIDE: 'left',\n BODY: 'body',\n SECTION: '.list-group-item[href*=\"#section-\"]',\n DRAWER: '#nav-drawer'\n };\n\n var small = $(document).width() < 768;\n\n \/**\n * Constructor for the Drawer.\n *\n * @param {object} root The root jQuery element for the modal\n *\/\n var Drawer = function() {\n\n if (!$(SELECTORS.TOGGLE_REGION).length) {\n Log.debug('Page is missing a drawer region');\n }\n if (!$(SELECTORS.TOGGLE_ACTION).length) {\n Log.debug('Page is missing a drawer toggle link');\n }\n $(SELECTORS.TOGGLE_REGION).each(function(index, ele) {\n var trigger = $(ele).find(SELECTORS.TOGGLE_ACTION);\n var drawerid = trigger.attr('aria-controls');\n var drawer = $(document.getElementById(drawerid));\n var hidden = trigger.attr('aria-expanded') == 'false';\n var side = trigger.attr('data-side');\n var body = $(SELECTORS.BODY);\n var preference = trigger.attr('data-preference');\n if (small) {\n M.util.set_user_preference(preference, 'false');\n }\n\n drawer.on('mousewheel DOMMouseScroll', this.preventPageScroll);\n\n if (!hidden) {\n body.addClass('drawer-open-' + side);\n trigger.attr('aria-expanded', 'true');\n } else {\n trigger.attr('aria-expanded', 'false');\n }\n }.bind(this));\n\n this.registerEventListeners();\n if (small) {\n this.closeAll();\n }\n };\n\n Drawer.prototype.closeAll = function() {\n $(SELECTORS.TOGGLE_REGION).each(function(index, ele) {\n var trigger = $(ele).find(SELECTORS.TOGGLE_ACTION);\n var side = trigger.attr('data-side');\n var body = $(SELECTORS.BODY);\n var drawerid = trigger.attr('aria-controls');\n var drawer = $(document.getElementById(drawerid));\n var preference = trigger.attr('data-preference');\n\n trigger.attr('aria-expanded', 'false');\n body.removeClass('drawer-open-' + side);\n drawer.attr('aria-hidden', 'true');\n drawer.addClass('closed');\n if (!small) {\n M.util.set_user_preference(preference, 'false');\n }\n });\n };\n\n \/**\n * Open \/ close the blocks drawer.\n *\n * @method toggleDrawer\n * @param {Event} e\n *\/\n Drawer.prototype.toggleDrawer = function(e) {\n var trigger = $(e.target).closest('[data-action=toggle-drawer]');\n var drawerid = trigger.attr('aria-controls');\n var drawer = $(document.getElementById(drawerid));\n var body = $(SELECTORS.BODY);\n var side = trigger.attr('data-side');\n var preference = trigger.attr('data-preference');\n if (small) {\n M.util.set_user_preference(preference, 'false');\n }\n\n body.addClass('drawer-ease');\n var open = trigger.attr('aria-expanded') == 'true';\n if (!open) {\n \/\/ Open.\n trigger.attr('aria-expanded', 'true');\n drawer.attr('aria-hidden', 'false');\n drawer.focus();\n body.addClass('drawer-open-' + side);\n drawer.removeClass('closed');\n if (!small) {\n M.util.set_user_preference(preference, 'true');\n }\n } else {\n \/\/ Close.\n body.removeClass('drawer-open-' + side);\n trigger.attr('aria-expanded', 'false');\n drawer.addClass('closed').delay(500).queue(function() {\n \/\/ Ensure that during the delay, the drawer wasn't re-opened.\n if ($(this).hasClass('closed')) {\n $(this).attr('aria-hidden', 'true');\n }\n $(this).dequeue();\n });\n if (!small) {\n M.util.set_user_preference(preference, 'false');\n }\n }\n\n \/\/ Publish an event to tell everything that the drawer has been toggled.\n \/\/ The drawer transitions closed so another event will fire once teh transition\n \/\/ has completed.\n PubSub.publish('nav-drawer-toggle-start', open);\n };\n\n \/**\n * Prevent the page from scrolling when the drawer is at max scroll.\n *\n * @method preventPageScroll\n * @param {Event} e\n *\/\n Drawer.prototype.preventPageScroll = function(e) {\n var delta = e.wheelDelta || (e.originalEvent && e.originalEvent.wheelDelta) || -e.originalEvent.detail,\n bottomOverflow = (this.scrollTop + $(this).outerHeight() - this.scrollHeight) >= 0,\n topOverflow = this.scrollTop <= 0;\n\n if ((delta < 0 && bottomOverflow) || (delta > 0 && topOverflow)) {\n e.preventDefault();\n }\n };\n\n \/**\n * Set up all of the event handling for the modal.\n *\n * @method registerEventListeners\n *\/\n Drawer.prototype.registerEventListeners = function() {\n\n $(SELECTORS.TOGGLE_ACTION).each(function(index, element) {\n CustomEvents.define($(element), [CustomEvents.events.activate]);\n $(element).on(CustomEvents.events.activate, function(e, data) {\n this.toggleDrawer(data.originalEvent);\n data.originalEvent.preventDefault();\n }.bind(this));\n }.bind(this));\n\n $(SELECTORS.SECTION).click(function() {\n if (small) {\n this.closeAll();\n }\n }.bind(this));\n\n \/\/ Publish an event to tell everything that the drawer completed the transition\n \/\/ to either an open or closed state.\n $(SELECTORS.DRAWER).on('webkitTransitionEnd msTransitionEnd transitionend', function(e) {\n var drawer = $(e.target).closest(SELECTORS.DRAWER);\n var open = drawer.attr('aria-hidden') == 'false';\n PubSub.publish('nav-drawer-toggle-end', open);\n });\n };\n\n return {\n 'init': function() {\n return new Drawer();\n }\n };\n});\n"],"names":["define","$","CustomEvents","Log","PubSub","SELECTORS","small","document","width","Drawer","length","debug","each","index","ele","trigger","find","drawerid","attr","drawer","getElementById","hidden","side","body","preference","M","util","set_user_preference","on","this","preventPageScroll","addClass","bind","registerEventListeners","closeAll","prototype","removeClass","toggleDrawer","e","target","closest","open","delay","queue","hasClass","dequeue","focus","publish","delta","wheelDelta","originalEvent","detail","bottomOverflow","scrollTop","outerHeight","scrollHeight","topOverflow","preventDefault","element","events","activate","data","click"],"mappings":";;;;;;;AAsBAA,4BAAO,CAAC,SAAU,iCAAkC,WAAY,gBAC3D,SAASC,EAAGC,aAAcC,IAAKC,YAE5BC,wBACe,gCADfA,wBAEe,gCAFfA,eAKM,OALNA,kBAMS,sCANTA,iBAOQ,cAGRC,MAAQL,EAAEM,UAAUC,QAAU,IAO9BC,OAAS,WAEJR,EAAEI,yBAAyBK,QAC5BP,IAAIQ,MAAM,mCAETV,EAAEI,yBAAyBK,QAC5BP,IAAIQ,MAAM,wCAEdV,EAAEI,yBAAyBO,KAAK,SAASC,MAAOC,SACxCC,QAAUd,EAAEa,KAAKE,KAAKX,yBACtBY,SAAWF,QAAQG,KAAK,iBACxBC,OAASlB,EAAEM,SAASa,eAAeH,WACnCI,OAA0C,SAAjCN,QAAQG,KAAK,iBACtBI,KAAOP,QAAQG,KAAK,aACpBK,KAAOtB,EAAEI,gBACTmB,WAAaT,QAAQG,KAAK,mBAC1BZ,OACAmB,EAAEC,KAAKC,oBAAoBH,WAAY,SAG3CL,OAAOS,GAAG,4BAA6BC,KAAKC,mBAEvCT,OAIDN,QAAQG,KAAK,gBAAiB,UAH9BK,KAAKQ,SAAS,eAAiBT,MAC\/BP,QAAQG,KAAK,gBAAiB,UAIpCc,KAAKH,YAEFI,yBACD3B,YACK4B,mBAIbzB,OAAO0B,UAAUD,SAAW,WACxBjC,EAAEI,yBAAyBO,MAAK,SAASC,MAAOC,SACxCC,QAAUd,EAAEa,KAAKE,KAAKX,yBACtBiB,KAAOP,QAAQG,KAAK,aACpBK,KAAOtB,EAAEI,gBACTY,SAAWF,QAAQG,KAAK,iBACxBC,OAASlB,EAAEM,SAASa,eAAeH,WACnCO,WAAa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