1 {"version":3,"sources":["../../../src/local/activitychooser/dialogue.js"],"names":["showModuleHelp","carousel","moduleData","help","find","selectors","regions","innerHTML","spinnerPromise","transitionPromiseResolver","transitionPromise","Promise","resolve","contentPromise","Templates","renderForPromise","all","then","html","js","replaceNodeContents","querySelector","chooserSummary","description","focus","catch","Notification","exception","one","registerListenerEvents","modal","mappedModules","bodyClickListener","e","target","closest","actions","optionActions","showSummary","getBody","module","chooserOption","container","moduleName","dataset","modname","get","matches","closeOption","on","allModules","modules","caller","getModuleSelector","getBodyPromise","body","interval","pause","keyboard","addEventListener","initKeyboardNavigation","chooserOptions","querySelectorAll","Array","from","forEach","element","document","keyCode","enter","space","preventDefault","arrowRight","currentOption","nextOption","nextElementSibling","firstOption","firstElementChild","toFocusOption","clickErrorHandler","focusChooserOption","arrowLeft","previousOption","previousElementSibling","lastOption","lastElementChild","home","end","currentChooserOption","previousChooserOption","previousChooserOptionLink","addChooser","previousChooserOptionHelp","tabIndex","currentChooserOptionLink","currentChooserOptionHelp","item","fallback","displayChooser","origin","sectionModules","Map","set","modulename","getRoot","ModalEvents","hidden","destroy","shown","getModal","firstChooserOption","show"],"mappings":"+SAwBA,OACA,OACA,OACA,O,6xBAWMA,CAAAA,CAAc,CAAG,SAACC,CAAD,CAAWC,CAAX,CAA0B,CAC7C,GAAMC,CAAAA,CAAI,CAAGF,CAAQ,CAACG,IAAT,CAAcC,UAAUC,OAAV,CAAkBH,IAAhC,EAAsC,CAAtC,CAAb,CACAA,CAAI,CAACI,SAAL,CAAiB,EAAjB,CAF6C,GAKvCC,CAAAA,CAAc,CAAG,yBAAmBL,CAAnB,CALsB,CAQzCM,CAAyB,CAAG,IARa,CASvCC,CAAiB,CAAG,GAAIC,CAAAA,OAAJ,CAAY,SAAAC,CAAO,CAAI,CAC7CH,CAAyB,CAAGG,CAC/B,CAFyB,CATmB,CAcvCC,CAAc,CAAGC,CAAS,CAACC,gBAAV,CAA2B,0BAA3B,CAAuDb,CAAvD,CAdsB,CAiB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GAAMrE,CAAAA,CAAa,CAAG,GAAIsE,CAAAA,GAA1B,CACAD,CAAc,CAACnC,OAAf,CAAuB,SAACzB,CAAD,CAAY,CAC/BT,CAAa,CAACuE,GAAd,CAAkB9D,CAAM,CAAC+D,UAAzB,CAAqC/D,CAArC,CACH,CAFD,EAKAX,CAAsB,CAACC,CAAD,CAAQC,CAAR,CAAtB,CAGAD,CAAK,CAAC0E,OAAN,GAAgBvD,EAAhB,CAAmBwD,CAAW,CAACC,MAA/B,CAAuC,UAAM,CACzC5E,CAAK,CAAC6E,OAAN,EACH,CAFD,EAKA7E,CAAK,CAAC0E,OAAN,GAAgBvD,EAAhB,CAAmBwD,CAAW,CAACG,KAA/B,CAAsC,UAAM,CACxC9E,CAAK,CAAC+E,QAAN,GAAiB,CAAjB,EAAoBhB,QAApB,CAA+B,CAAC,CAAhC,CAEA/D,CAAK,CAACwB,cAAN,GACCrC,IADD,CACM,SAAAsC,CAAI,CAAI,CACV,GAAMuD,CAAAA,CAAkB,CAAGvD,CAAI,CAAC,CAAD,CAAJ,CAAQlC,aAAR,CAAsBhB,UAAUC,OAAV,CAAkBmC,aAAlB,CAAgCC,SAAtD,CAA3B,CACAsC,CAAkB,CAAC8B,CAAD,CAGrB,CAND,EAOCrF,KAPD,CAOOC,YAAY,CAACC,SAPpB,CAQH,CAXD,EAaAG,CAAK,CAACiF,IAAN,EACH,C","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 * A type of dialogue used as for choosing options.\n *\n * @module core_course/local/chooser/dialogue\n * @package core\n * @copyright 2019 Mihail Geshoski <mihail@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport $ from 'jquery';\nimport * as ModalEvents from 'core/modal_events';\nimport selectors from 'core_course/local/activitychooser/selectors';\nimport * as Templates from 'core/templates';\nimport {end, arrowLeft, arrowRight, home, enter, space} from 'core/key_codes';\nimport {addIconToContainer} from 'core/loadingicon';\n\n/**\n * Given an event from the main module 'page' navigate to it's help section via a carousel.\n *\n * @method showModuleHelp\n * @param {jQuery} carousel Our initialized carousel to manipulate\n * @param {Object} moduleData Data of the module to carousel to\n */\nconst showModuleHelp = (carousel, moduleData) => {\n const help = carousel.find(selectors.regions.help)[0];\n help.innerHTML = '';\n\n // Add a spinner.\n const spinnerPromise = addIconToContainer(help);\n\n // Used later...\n let transitionPromiseResolver = null;\n const transitionPromise = new Promise(resolve => {\n transitionPromiseResolver = resolve;\n });\n\n // Build up the html & js ready to place into the help section.\n const contentPromise = Templates.renderForPromise('core_course/chooser_help', moduleData);\n\n // Wait for the content to be ready, and for the transition to be complet.\n Promise.all([contentPromise, spinnerPromise, transitionPromise])\n .then(([{html, js}]) => Templates.replaceNodeContents(help, html, js))\n .then(() => {\n help.querySelector(selectors.regions.chooserSummary.description).focus();\n return help;\n })\n .catch(Notification.exception);\n\n // Move to the next slide, and resolve the transition promise when it's done.\n carousel.one('slid.bs.carousel', () => {\n transitionPromiseResolver();\n });\n // Trigger the transition between 'pages'.\n carousel.carousel('next');\n};\n\n/**\n * Register chooser related event listeners.\n *\n * @method registerListenerEvents\n * @param {Promise} modal Our modal that we are working with\n * @param {Map} mappedModules A map of all of the modules we are working with with K: mod_name V: {Object}\n */\nconst registerListenerEvents = (modal, mappedModules) => {\n const bodyClickListener = e => {\n if (e.target.closest(selectors.actions.optionActions.showSummary)) {\n const carousel = $(modal.getBody()[0].querySelector(selectors.regions.carousel));\n\n const module = e.target.closest(selectors.regions.chooserOption.container);\n const moduleName = module.dataset.modname;\n const moduleData = mappedModules.get(moduleName);\n showModuleHelp(carousel, moduleData);\n }\n\n // From the help screen go back to the module overview.\n if (e.target.matches(selectors.actions.closeOption)) {\n const carousel = $(modal.getBody()[0].querySelector(selectors.regions.carousel));\n\n // Trigger the transition between 'pages'.\n carousel.carousel('prev');\n carousel.on('slid.bs.carousel', () => {\n const allModules = modal.getBody()[0].querySelector(selectors.regions.modules);\n const caller = allModules.querySelector(selectors.regions.getModuleSelector(e.target.dataset.modname));\n caller.focus();\n });\n }\n };\n\n modal.getBodyPromise()\n\n // The return value of getBodyPromise is a jquery object containing the body NodeElement.\n .then(body => body[0])\n\n // Set up the carousel.\n .then(body => {\n $(body.querySelector(selectors.regions.carousel))\n .carousel({\n interval: false,\n pause: true,\n keyboard: false\n });\n\n return body;\n })\n\n // Add the listener for clicks on the body.\n .then(body => {\n body.addEventListener('click', bodyClickListener);\n return body;\n })\n\n // Register event listeners related to the keyboard navigation controls.\n .then(body => {\n initKeyboardNavigation(body, mappedModules);\n return body;\n })\n .catch();\n\n};\n\n/**\n * Initialise the keyboard navigation controls for the chooser.\n *\n * @method initKeyboardNavigation\n * @param {NodeElement} body Our modal that we are working with\n * @param {Map} mappedModules A map of all of the modules we are working with with K: mod_name V: {Object}\n */\nconst initKeyboardNavigation = (body, mappedModules) => {\n\n const chooserOptions = body.querySelectorAll(selectors.regions.chooserOption.container);\n\n Array.from(chooserOptions).forEach((element) => {\n return element.addEventListener('keyup', (e) => {\n const chooserOptions = document.querySelector(selectors.regions.chooserOptions);\n\n // Check for enter/ space triggers for showing the help.\n if (e.keyCode === enter || e.keyCode === space) {\n if (e.target.matches(selectors.actions.optionActions.showSummary)) {\n e.preventDefault();\n const module = e.target.closest(selectors.regions.chooserOption.container);\n const moduleName = module.dataset.modname;\n const moduleData = mappedModules.get(moduleName);\n const carousel = $(body.querySelector(selectors.regions.carousel));\n carousel.carousel({\n interval: false,\n pause: true,\n keyboard: false\n });\n showModuleHelp(carousel, moduleData);\n }\n }\n\n // Next.\n if (e.keyCode === arrowRight) {\n e.preventDefault();\n const currentOption = e.target.closest(selectors.regions.chooserOption.container);\n const nextOption = currentOption.nextElementSibling;\n const firstOption = chooserOptions.firstElementChild;\n const toFocusOption = clickErrorHandler(nextOption, firstOption);\n focusChooserOption(toFocusOption, currentOption);\n }\n\n // Previous.\n if (e.keyCode === arrowLeft) {\n e.preventDefault();\n const currentOption = e.target.closest(selectors.regions.chooserOption.container);\n const previousOption = currentOption.previousElementSibling;\n const lastOption = chooserOptions.lastElementChild;\n const toFocusOption = clickErrorHandler(previousOption, lastOption);\n focusChooserOption(toFocusOption, currentOption);\n }\n\n if (e.keyCode === home) {\n e.preventDefault();\n const currentOption = e.target.closest(selectors.regions.chooserOption.container);\n const firstOption = chooserOptions.firstElementChild;\n focusChooserOption(firstOption, currentOption);\n }\n\n if (e.keyCode === end) {\n e.preventDefault();\n const currentOption = e.target.closest(selectors.regions.chooserOption.container);\n const lastOption = chooserOptions.lastElementChild;\n focusChooserOption(lastOption, currentOption);\n }\n });\n });\n};\n\n/**\n * Focus on a chooser option element and remove the previous chooser element from the focus order\n *\n * @method focusChooserOption\n * @param {HTMLElement} currentChooserOption The current chooser option element that we want to focus\n * @param {HTMLElement} previousChooserOption The previous focused option element\n */\nconst focusChooserOption = (currentChooserOption, previousChooserOption = false) => {\n if (previousChooserOption !== false) {\n const previousChooserOptionLink = previousChooserOption.querySelector(selectors.actions.addChooser);\n const previousChooserOptionHelp = previousChooserOption.querySelector(selectors.actions.optionActions.showSummary);\n // Set tabindex to -1 to remove the previous chooser option element from the focus order.\n previousChooserOption.tabIndex = -1;\n previousChooserOptionLink.tabIndex = -1;\n previousChooserOptionHelp.tabIndex = -1;\n }\n\n const currentChooserOptionLink = currentChooserOption.querySelector(selectors.actions.addChooser);\n const currentChooserOptionHelp = currentChooserOption.querySelector(selectors.actions.optionActions.showSummary);\n // Set tabindex to 0 to add current chooser option element to the focus order.\n currentChooserOption.tabIndex = 0;\n currentChooserOptionLink.tabIndex = 0;\n currentChooserOptionHelp.tabIndex = 0;\n // Focus the current chooser option element.\n currentChooserOption.focus();\n};\n\n/**\n * Small error handling function to make sure the navigated to object exists\n *\n * @method clickErrorHandler\n * @param {HTMLElement} item What we want to check exists\n * @param {HTMLElement} fallback If we dont match anything fallback the focus\n * @return {String}\n */\nconst clickErrorHandler = (item, fallback) => {\n if (item !== null) {\n return item;\n } else {\n return fallback;\n }\n};\n\n/**\n * Display the module chooser.\n *\n * @method displayChooser\n * @param {HTMLElement} origin The calling button\n * @param {Object} modal Our created modal for the section\n * @param {Array} sectionModules An array of all of the built module information\n */\nexport const displayChooser = (origin, modal, sectionModules) => {\n\n // Make a map so we can quickly fetch a specific module's object for either rendering or searching.\n const mappedModules = new Map();\n sectionModules.forEach((module) => {\n mappedModules.set(module.modulename, module);\n });\n\n // Register event listeners.\n registerListenerEvents(modal, mappedModules);\n\n // We want to focus on the action select when the dialog is closed.\n modal.getRoot().on(ModalEvents.hidden, () => {\n modal.destroy();\n });\n\n // We want to focus on the first chooser option element as soon as the modal is opened.\n modal.getRoot().on(ModalEvents.shown, () => {\n modal.getModal()[0].tabIndex = -1;\n\n modal.getBodyPromise()\n .then(body => {\n const firstChooserOption = body[0].querySelector(selectors.regions.chooserOption.container);\n focusChooserOption(firstChooserOption);\n\n return;\n })\n .catch(Notification.exception);\n });\n\n modal.show();\n};\n"],"file":"dialogue.min.js"}