Rev 1 | AutorÃa | Comparar con el anterior | Ultima modificación | Ver Log |
{"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 fro
m '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.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 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 // t
o 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","focus","PubSub","publish","DrawerEvents","DRAWER_SHOWN","hide","addClass","DRAWER_HIDDEN","isVisible","hasClass","toggle","registerToggles","toggleElements","openTrigger","attr","on","e","preventDefault","wasVisible","filter","index","element","target","contains","getDrawerRoot","contentRoot","closest"],"map
pings":";;;;;;;mQAgCMA,KAAOC,OAETA,MAAO,mBAAEA,MAETC,KAAKC,OAAOF,KAAKG,OACjBH,KAAKI,YAAY,UACjBJ,KAAKK,QAELC,OAAOC,QAAQC,uBAAaC,aAAcT,OAQxCU,KAAOV,QAETA,MAAO,mBAAEA,OAEJW,SAAS,UACdV,KAAKS,KAAKV,KAAKG,OAEfG,OAAOC,QAAQC,uBAAaI,cAAeZ,OASzCa,UAAab,OACAA,KAAKc,SAAS,UAS3BC,OAAUf,OACRa,UAAUb,MACVU,KAAKV,MAELD,KAAKC,oBA6CE,CACXU,KAAMA,KACNX,KAAMA,KACNc,UAAWA,UACXE,OAAQA,OACRC,gBAxCoB,CAAChB,KAAMiB,sBACvBC,YAAc,KAClBD,eAAeE,KAAK,gBAAiBN,UAAUb,OAE/CiB,eAAeG,GAAG,SAAUC,IACxBA,EAAEC,uBACIC,WAAaV,UAAUb,MAC7Be,OAAOf,MACPiB,eAAeE,KAAK,iBAAkBI,YAEjCA,WAKML,cAGPA,YAAYb,QACZa,YAAc,MAPdA,YAAcD,eAAeO,QAAO,CAACC,MAAOC,UACjCA,SAAWL,EAAEM,QAAUD,QAAQE,SAASP,EAAEM,cA4B7DE,cAXmBC,cACnBA,aAAc,mBAAEA,cACGC,QAAQ"}