moodle/lib/amd/build/drawer.min.js.map
2023-03-09 09:53:19 +08:00

1 line
4.8 KiB
Plaintext

{"version":3,"file":"drawer.min.js","sources":["../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 <http://www.gnu.org/licenses/>.\n\n/**\n * Controls the drawer.\n *\n * @module core/drawer\n * @copyright 2019 Jun Pataleta <jun@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport $ from 'jquery';\nimport * as PubSub from 'core/pubsub';\nimport * as Aria from 'core/aria';\nimport DrawerEvents from 'core/drawer_events';\n\n/**\n * Show the drawer.\n *\n * @param {Object} root The drawer container.\n */\nconst show = root => {\n // Ensure that it is a jQuery.\n root = $(root);\n\n Aria.unhide(root.get());\n root.removeClass('hidden');\n root.attr('aria-expanded', true);\n root.focus();\n\n PubSub.publish(DrawerEvents.DRAWER_SHOWN, root);\n};\n\n/**\n * Hide the drawer.\n *\n * @param {Object} root The drawer container.\n */\nconst hide = root => {\n // Ensure that it is a jQuery.\n root = $(root);\n\n root.addClass('hidden');\n root.attr('aria-expanded', false);\n Aria.hide(root.get());\n\n PubSub.publish(DrawerEvents.DRAWER_HIDDEN, root);\n};\n\n/**\n * Check if the drawer is visible.\n *\n * @param {Object} root The drawer container.\n * @return {boolean}\n */\nconst isVisible = (root) => {\n let isHidden = root.hasClass('hidden');\n return !isHidden;\n};\n\n/**\n * Toggle the drawer visibility.\n *\n * @param {Object} root The drawer container.\n */\nconst toggle = (root) => {\n if (isVisible(root)) {\n hide(root);\n } else {\n show(root);\n }\n};\n\n/**\n * Add event listeners to toggle the drawer.\n *\n * @param {Object} root The drawer container.\n * @param {Object} toggleElements The toggle elements.\n */\nconst registerToggles = (root, toggleElements) => {\n let openTrigger = null;\n toggleElements.attr('aria-expanded', isVisible(root));\n\n toggleElements.on('click', (e) => {\n e.preventDefault();\n const wasVisible = isVisible(root);\n toggle(root);\n toggleElements.attr('aria-expanded', !wasVisible);\n\n if (!wasVisible) {\n // Remember which trigger element opened the drawer.\n openTrigger = toggleElements.filter((index, element) => {\n return element == e.target || element.contains(e.target);\n });\n } else if (openTrigger) {\n // The drawer has gone from open to close so we need to set the focus back\n // to the element that openend it.\n openTrigger.focus();\n openTrigger = null;\n }\n });\n};\n\n/**\n * Find the root element of the drawer based on the using the drawer content root's ID.\n *\n * @param {Object} contentRoot The drawer content's root element.\n * @returns {*|jQuery}\n */\nconst getDrawerRoot = (contentRoot) => {\n contentRoot = $(contentRoot);\n return contentRoot.closest('[data-region=\"right-hand-drawer\"]');\n};\n\nexport default {\n hide: hide,\n show: show,\n isVisible: isVisible,\n toggle: toggle,\n registerToggles: registerToggles,\n getDrawerRoot: getDrawerRoot\n};\n"],"names":["show","root","Aria","unhide","get","removeClass","attr","focus","PubSub","publish","DrawerEvents","DRAWER_SHOWN","hide","addClass","DRAWER_HIDDEN","isVisible","hasClass","toggle","registerToggles","toggleElements","openTrigger","on","e","preventDefault","wasVisible","filter","index","element","target","contains","getDrawerRoot","contentRoot","closest"],"mappings":";;;;;;;mQAgCMA,KAAOC,OAETA,MAAO,mBAAEA,MAETC,KAAKC,OAAOF,KAAKG,OACjBH,KAAKI,YAAY,UACjBJ,KAAKK,KAAK,iBAAiB,GAC3BL,KAAKM,QAELC,OAAOC,QAAQC,uBAAaC,aAAcV,OAQxCW,KAAOX,QAETA,MAAO,mBAAEA,OAEJY,SAAS,UACdZ,KAAKK,KAAK,iBAAiB,GAC3BJ,KAAKU,KAAKX,KAAKG,OAEfI,OAAOC,QAAQC,uBAAaI,cAAeb,OASzCc,UAAad,OACAA,KAAKe,SAAS,UAS3BC,OAAUhB,OACRc,UAAUd,MACVW,KAAKX,MAELD,KAAKC,oBA6CE,CACXW,KAAMA,KACNZ,KAAMA,KACNe,UAAWA,UACXE,OAAQA,OACRC,gBAxCoB,CAACjB,KAAMkB,sBACvBC,YAAc,KAClBD,eAAeb,KAAK,gBAAiBS,UAAUd,OAE/CkB,eAAeE,GAAG,SAAUC,IACxBA,EAAEC,uBACIC,WAAaT,UAAUd,MAC7BgB,OAAOhB,MACPkB,eAAeb,KAAK,iBAAkBkB,YAEjCA,WAKMJ,cAGPA,YAAYb,QACZa,YAAc,MAPdA,YAAcD,eAAeM,QAAO,CAACC,MAAOC,UACjCA,SAAWL,EAAEM,QAAUD,QAAQE,SAASP,EAAEM,cA4B7DE,cAXmBC,cACnBA,aAAc,mBAAEA,cACGC,QAAQ"}