diff --git a/course/amd/build/activitychooser.min.js b/course/amd/build/activitychooser.min.js index eabdac2bf7a..929586d2f57 100644 --- a/course/amd/build/activitychooser.min.js +++ b/course/amd/build/activitychooser.min.js @@ -1,2 +1,2 @@ -define ("core_course/activitychooser",["exports","core_course/local/activitychooser/dialogue","core_course/local/activitychooser/repository","core_course/local/activitychooser/selectors","core/custom_interaction_events","core/templates","core/modal_factory","core/str","core/pending"],function(a,b,c,d,e,f,g,h,i){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=k(b);c=k(c);d=j(d);e=j(e);f=k(f);g=k(g);i=j(i);function j(a){return a&&a.__esModule?a:{default:a}}function k(a){if(a&&a.__esModule){return a}else{var b={};if(null!=a){for(var c in a){if(Object.prototype.hasOwnProperty.call(a,c)){var d=Object.defineProperty&&Object.getOwnPropertyDescriptor?Object.getOwnPropertyDescriptor(a,c):{};if(d.get||d.set){Object.defineProperty(b,c,d)}else{b[c]=a[c]}}}}b.default=a;return b}}function l(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){c(a);return}if(h.done){b(i)}else{Promise.resolve(i).then(d,e)}}function m(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){var h=a.apply(b,c);function f(a){l(h,d,e,f,g,"next",a)}function g(a){l(h,d,e,f,g,"throw",a)}f(void 0)})}}var n=function(a){var b=new i.default;o(a);b.resolve()};a.init=n;var o=function(a){var f=["click",e.default.events.activate,e.default.events.keyboardActivate],g=function(){var b=null;return function(){if(!b){b=new Promise(function(b){b(c.activityModules(a))})}return b}}();e.default.define(document,f);f.forEach(function(a){document.addEventListener(a,function(){var a=m(regeneratorRuntime.mark(function a(c){var e,f,h;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:if(!c.target.closest(d.default.elements.sectionmodchooser)){a.next=12;break}e=c.target.closest(d.default.elements.sectionmodchooser);a.t0=p;a.next=5;return g();case 5:a.t1=a.sent;a.t2=e.dataset.sectionid;f=(0,a.t0)(a.t1,a.t2);a.next=10;return q(f);case 10:h=a.sent;b.displayChooser(e,h,f);case 12:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}())})},p=function(a,b){var c=JSON.parse(JSON.stringify(a));c.allmodules.forEach(function(a){a.urls.addoption+="§ion="+b});return c.allmodules},q=function(a){return s(r(a))},r=function(a){var b=[],c=[],d=!!b.length,e=!!(c.length&&!1===d);return{default:a,favourites:b,recommended:c,favouritesFirst:d,recommendedFirst:e,fallback:!1===d&&!1===e}},s=function(a){return g.create({type:g.types.DEFAULT,title:(0,h.get_string)("addresourceoractivity"),body:f.render("core_course/chooser",a),large:!0,templateContext:{classes:"modchooser"}})}}); +define ("core_course/activitychooser",["exports","core_course/local/activitychooser/dialogue","core_course/local/activitychooser/repository","core_course/local/activitychooser/selectors","core/custom_interaction_events","core/templates","core/modal_factory","core/str","core/pending"],function(a,b,c,d,e,f,g,h,i){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=k(b);c=k(c);d=j(d);e=j(e);f=k(f);g=k(g);i=j(i);function j(a){return a&&a.__esModule?a:{default:a}}function k(a){if(a&&a.__esModule){return a}else{var b={};if(null!=a){for(var c in a){if(Object.prototype.hasOwnProperty.call(a,c)){var d=Object.defineProperty&&Object.getOwnPropertyDescriptor?Object.getOwnPropertyDescriptor(a,c):{};if(d.get||d.set){Object.defineProperty(b,c,d)}else{b[c]=a[c]}}}}b.default=a;return b}}function l(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){c(a);return}if(h.done){b(i)}else{Promise.resolve(i).then(d,e)}}function m(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){var h=a.apply(b,c);function f(a){l(h,d,e,f,g,"next",a)}function g(a){l(h,d,e,f,g,"throw",a)}f(void 0)})}}var n=function(a){var b=new i.default;o(a);b.resolve()};a.init=n;var o=function(a){var f=["click",e.default.events.activate,e.default.events.keyboardActivate],g=function(){var b=null;return function(){if(!b){b=new Promise(function(b){b(c.activityModules(a))})}return b}}();e.default.define(document,f);f.forEach(function(a){document.addEventListener(a,function(){var a=m(regeneratorRuntime.mark(function a(c){var e,f,h;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:if(!c.target.closest(d.default.elements.sectionmodchooser)){a.next=12;break}e=c.target.closest(d.default.elements.sectionmodchooser);a.t0=p;a.next=5;return g();case 5:a.t1=a.sent;a.t2=e.dataset.sectionid;f=(0,a.t0)(a.t1,a.t2);a.next=10;return q(f);case 10:h=a.sent;b.displayChooser(e,h,f);case 12:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}())})},p=function(a,b){var c=JSON.parse(JSON.stringify(a));c.content_items.forEach(function(a){a.link+="§ion="+b});return c.content_items},q=function(a){return s(r(a))},r=function(a){var b=[],c=[],d=!!b.length,e=!!(c.length&&!1===d);return{default:a,favourites:b,recommended:c,favouritesFirst:d,recommendedFirst:e,fallback:!1===d&&!1===e}},s=function(a){return g.create({type:g.types.DEFAULT,title:(0,h.get_string)("addresourceoractivity"),body:f.render("core_course/chooser",a),large:!0,templateContext:{classes:"modchooser"}})}}); //# sourceMappingURL=activitychooser.min.js.map diff --git a/course/amd/build/activitychooser.min.js.map b/course/amd/build/activitychooser.min.js.map index 4a79805b9ec..c5fc3dfb887 100644 --- a/course/amd/build/activitychooser.min.js.map +++ b/course/amd/build/activitychooser.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/activitychooser.js"],"names":["init","courseId","pendingPromise","Pending","registerListenerEvents","resolve","events","CustomEvents","activate","keyboardActivate","fetchModuleData","innerPromise","Promise","Repository","activityModules","define","document","forEach","event","addEventListener","e","target","closest","selectors","elements","sectionmodchooser","caller","sectionIdMapper","dataset","sectionid","builtModuleData","modalBuilder","sectionModal","ChooserDialogue","displayChooser","webServiceData","id","newData","JSON","parse","stringify","allmodules","module","urls","addoption","data","buildModal","templateDataBuilder","favourites","recommended","favouritesFirst","length","recommendedFirst","fallback","ModalFactory","create","type","types","DEFAULT","title","body","Templates","render","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AE,CACbC,OAAO,CAAE,YADI,CALM,CAApB,CASV,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 .\n\n/**\n * A type of dialogue used as for choosing modules in a course.\n *\n * @module core_course/activitychooser\n * @package core_course\n * @copyright 2020 Mathew May \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport * as ChooserDialogue from 'core_course/local/activitychooser/dialogue';\nimport * as Repository from 'core_course/local/activitychooser/repository';\nimport selectors from 'core_course/local/activitychooser/selectors';\nimport CustomEvents from 'core/custom_interaction_events';\nimport * as Templates from 'core/templates';\nimport * as ModalFactory from 'core/modal_factory';\nimport {get_string as getString} from 'core/str';\nimport Pending from 'core/pending';\n\n/**\n * Set up the activity chooser.\n *\n * @method init\n * @param {Number} courseId Course ID to use later on in fetchModules()\n */\nexport const init = courseId => {\n const pendingPromise = new Pending();\n\n registerListenerEvents(courseId);\n\n pendingPromise.resolve();\n};\n\n/**\n * Once a selection has been made make the modal & module information and pass it along\n *\n * @method registerListenerEvents\n * @param {Number} courseId\n */\nconst registerListenerEvents = (courseId) => {\n const events = [\n 'click',\n CustomEvents.events.activate,\n CustomEvents.events.keyboardActivate\n ];\n\n const fetchModuleData = (() => {\n let innerPromise = null;\n\n return () => {\n if (!innerPromise) {\n innerPromise = new Promise((resolve) => {\n resolve(Repository.activityModules(courseId));\n });\n }\n\n return innerPromise;\n };\n })();\n\n CustomEvents.define(document, events);\n\n // Display module chooser event listeners.\n events.forEach((event) => {\n document.addEventListener(event, async(e) => {\n if (e.target.closest(selectors.elements.sectionmodchooser)) {\n const caller = e.target.closest(selectors.elements.sectionmodchooser);\n const builtModuleData = sectionIdMapper(await fetchModuleData(), caller.dataset.sectionid);\n const sectionModal = await modalBuilder(builtModuleData);\n\n ChooserDialogue.displayChooser(caller, sectionModal, builtModuleData);\n }\n });\n });\n};\n\n/**\n * Given the web service data and an ID we want to make a deep copy\n * of the WS data then add on the section ID to the addoption URL\n *\n * @method sectionIdMapper\n * @param {Object} webServiceData Our original data from the Web service call\n * @param {Array} id The ID of the section we need to append to the links\n * @return {Array} [modules] with URL's built\n */\nconst sectionIdMapper = (webServiceData, id) => {\n // We need to take a fresh deep copy of the original data as an object is a reference type.\n const newData = JSON.parse(JSON.stringify(webServiceData));\n newData.allmodules.forEach((module) => {\n module.urls.addoption += '§ion=' + id;\n });\n return newData.allmodules;\n};\n\n/**\n * Build a modal for each section ID and store it into a map for quick access\n *\n * @method modalBuilder\n * @param {Map} data our map of section ID's & modules to generate modals for\n * @return {Object} TODO\n */\nconst modalBuilder = data => buildModal(templateDataBuilder(data));\n\n/**\n * Given an array of modules we want to figure out where & how to place them into our template object\n *\n * @method templateDataBuilder\n * @param {Array} data our modules to manipulate into a Templatable object\n * @return {Object} Our built object ready to render out\n */\nconst templateDataBuilder = (data) => {\n // Filter the incoming data to find favourite & recommended modules.\n const favourites = [];\n const recommended = [];\n\n // Given the results of the above filters lets figure out what tab to set active.\n\n // We have some favourites.\n const favouritesFirst = !!favourites.length;\n // Check if we have no favourites but have some recommended.\n const recommendedFirst = !!(recommended.length && favouritesFirst === false);\n // We have nothing fallback to show all modules.\n const fallback = favouritesFirst === false && recommendedFirst === false;\n\n return {\n 'default': data,\n favourites: favourites,\n recommended: recommended,\n favouritesFirst: favouritesFirst,\n recommendedFirst: recommendedFirst,\n fallback: fallback,\n };\n};\n\n/**\n * Given an object we want to prebuild a modal ready to store into a map\n *\n * @method buildModal\n * @param {Object} data The template data which contains arrays of modules\n * @return {Object} The modal for the calling section with everything already set up\n */\nconst buildModal = data => {\n return ModalFactory.create({\n type: ModalFactory.types.DEFAULT,\n title: getString('addresourceoractivity'),\n body: Templates.render('core_course/chooser', data),\n large: true,\n templateContext: {\n classes: 'modchooser'\n }\n });\n};\n"],"file":"activitychooser.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/activitychooser.js"],"names":["init","courseId","pendingPromise","Pending","registerListenerEvents","resolve","events","CustomEvents","activate","keyboardActivate","fetchModuleData","innerPromise","Promise","Repository","activityModules","define","document","forEach","event","addEventListener","e","target","closest","selectors","elements","sectionmodchooser","caller","sectionIdMapper","dataset","sectionid","builtModuleData","modalBuilder","sectionModal","ChooserDialogue","displayChooser","webServiceData","id","newData","JSON","parse","stringify","content_items","module","link","data","buildModal","templateDataBuilder","favourites","recommended","favouritesFirst","length","recommendedFirst","fallback","ModalFactory","create","type","types","DEFAULT","title","body","Templates","render","large","templateContext","classes"],"mappings":"qYAwBA,OACA,OACA,OACA,OACA,OACA,OAEA,O,grBAQO,GAAMA,CAAAA,CAAI,CAAG,SAAAC,CAAQ,CAAI,CAC5B,GAAMC,CAAAA,CAAc,CAAG,GAAIC,UAA3B,CAEAC,CAAsB,CAACH,CAAD,CAAtB,CAEAC,CAAc,CAACG,OAAf,EACH,CANM,C,YAcDD,CAAAA,CAAsB,CAAG,SAACH,CAAD,CAAc,IACnCK,CAAAA,CAAM,CAAG,CACX,OADW,CAEXC,UAAaD,MAAb,CAAoBE,QAFT,CAGXD,UAAaD,MAAb,CAAoBG,gBAHT,CAD0B,CAOnCC,CAAe,CAAI,UAAM,CAC3B,GAAIC,CAAAA,CAAY,CAAG,IAAnB,CAEA,MAAO,WAAM,CACT,GAAI,CAACA,CAAL,CAAmB,CACfA,CAAY,CAAG,GAAIC,CAAAA,OAAJ,CAAY,SAACP,CAAD,CAAa,CACpCA,CAAO,CAACQ,CAAU,CAACC,eAAX,CAA2Bb,CAA3B,CAAD,CACV,CAFc,CAGlB,CAED,MAAOU,CAAAA,CACV,CACJ,CAZuB,EAPiB,CAqBzCJ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,CAAxB,CAVQ,CAclC,MAAO,CACH,QAAWL,CADR,CAEHG,UAAU,CAAEA,CAFT,CAGHC,WAAW,CAAEA,CAHV,CAIHC,eAAe,CAAEA,CAJd,CAKHE,gBAAgB,CAAEA,CALf,CAMHC,QAAQ,CARK,KAAAH,CAAe,EAAc,KAAAE,CAEvC,CAQV,C,CASKN,CAAU,CAAG,SAAAD,CAAI,CAAI,CACvB,MAAOS,CAAAA,CAAY,CAACC,MAAb,CAAoB,CACvBC,IAAI,CAAEF,CAAY,CAACG,KAAb,CAAmBC,OADF,CAEvBC,KAAK,CAAE,iBAAU,uBAAV,CAFgB,CAGvBC,IAAI,CAAEC,CAAS,CAACC,MAAV,CAAiB,qBAAjB,CAAwCjB,CAAxC,CAHiB,CAIvBkB,KAAK,GAJkB,CAKvBC,eAAe,CAAE,CACbC,OAAO,CAAE,YADI,CALM,CAApB,CASV,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 .\n\n/**\n * A type of dialogue used as for choosing modules in a course.\n *\n * @module core_course/activitychooser\n * @package core_course\n * @copyright 2020 Mathew May \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport * as ChooserDialogue from 'core_course/local/activitychooser/dialogue';\nimport * as Repository from 'core_course/local/activitychooser/repository';\nimport selectors from 'core_course/local/activitychooser/selectors';\nimport CustomEvents from 'core/custom_interaction_events';\nimport * as Templates from 'core/templates';\nimport * as ModalFactory from 'core/modal_factory';\nimport {get_string as getString} from 'core/str';\nimport Pending from 'core/pending';\n\n/**\n * Set up the activity chooser.\n *\n * @method init\n * @param {Number} courseId Course ID to use later on in fetchModules()\n */\nexport const init = courseId => {\n const pendingPromise = new Pending();\n\n registerListenerEvents(courseId);\n\n pendingPromise.resolve();\n};\n\n/**\n * Once a selection has been made make the modal & module information and pass it along\n *\n * @method registerListenerEvents\n * @param {Number} courseId\n */\nconst registerListenerEvents = (courseId) => {\n const events = [\n 'click',\n CustomEvents.events.activate,\n CustomEvents.events.keyboardActivate\n ];\n\n const fetchModuleData = (() => {\n let innerPromise = null;\n\n return () => {\n if (!innerPromise) {\n innerPromise = new Promise((resolve) => {\n resolve(Repository.activityModules(courseId));\n });\n }\n\n return innerPromise;\n };\n })();\n\n CustomEvents.define(document, events);\n\n // Display module chooser event listeners.\n events.forEach((event) => {\n document.addEventListener(event, async(e) => {\n if (e.target.closest(selectors.elements.sectionmodchooser)) {\n const caller = e.target.closest(selectors.elements.sectionmodchooser);\n const builtModuleData = sectionIdMapper(await fetchModuleData(), caller.dataset.sectionid);\n const sectionModal = await modalBuilder(builtModuleData);\n\n ChooserDialogue.displayChooser(caller, sectionModal, builtModuleData);\n }\n });\n });\n};\n\n/**\n * Given the web service data and an ID we want to make a deep copy\n * of the WS data then add on the section ID to the addoption URL\n *\n * @method sectionIdMapper\n * @param {Object} webServiceData Our original data from the Web service call\n * @param {Array} id The ID of the section we need to append to the links\n * @return {Array} [modules] with URL's built\n */\nconst sectionIdMapper = (webServiceData, id) => {\n // We need to take a fresh deep copy of the original data as an object is a reference type.\n const newData = JSON.parse(JSON.stringify(webServiceData));\n newData.content_items.forEach((module) => {\n module.link += '§ion=' + id;\n });\n return newData.content_items;\n};\n\n/**\n * Build a modal for each section ID and store it into a map for quick access\n *\n * @method modalBuilder\n * @param {Map} data our map of section ID's & modules to generate modals for\n * @return {Object} TODO\n */\nconst modalBuilder = data => buildModal(templateDataBuilder(data));\n\n/**\n * Given an array of modules we want to figure out where & how to place them into our template object\n *\n * @method templateDataBuilder\n * @param {Array} data our modules to manipulate into a Templatable object\n * @return {Object} Our built object ready to render out\n */\nconst templateDataBuilder = (data) => {\n // Filter the incoming data to find favourite & recommended modules.\n const favourites = [];\n const recommended = [];\n\n // Given the results of the above filters lets figure out what tab to set active.\n\n // We have some favourites.\n const favouritesFirst = !!favourites.length;\n // Check if we have no favourites but have some recommended.\n const recommendedFirst = !!(recommended.length && favouritesFirst === false);\n // We have nothing fallback to show all modules.\n const fallback = favouritesFirst === false && recommendedFirst === false;\n\n return {\n 'default': data,\n favourites: favourites,\n recommended: recommended,\n favouritesFirst: favouritesFirst,\n recommendedFirst: recommendedFirst,\n fallback: fallback,\n };\n};\n\n/**\n * Given an object we want to prebuild a modal ready to store into a map\n *\n * @method buildModal\n * @param {Object} data The template data which contains arrays of modules\n * @return {Object} The modal for the calling section with everything already set up\n */\nconst buildModal = data => {\n return ModalFactory.create({\n type: ModalFactory.types.DEFAULT,\n title: getString('addresourceoractivity'),\n body: Templates.render('core_course/chooser', data),\n large: true,\n templateContext: {\n classes: 'modchooser'\n }\n });\n};\n"],"file":"activitychooser.min.js"} \ No newline at end of file diff --git a/course/amd/build/local/activitychooser/dialogue.min.js b/course/amd/build/local/activitychooser/dialogue.min.js index c9ef8b71e9e..b28b3dbe516 100644 --- a/course/amd/build/local/activitychooser/dialogue.min.js +++ b/course/amd/build/local/activitychooser/dialogue.min.js @@ -1,2 +1,2 @@ -define ("core_course/local/activitychooser/dialogue",["exports","jquery","core/modal_events","core_course/local/activitychooser/selectors","core/templates","core/key_codes","core/loadingicon"],function(a,b,c,d,e,f,g){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.displayChooser=void 0;b=i(b);c=h(c);d=i(d);e=h(e);function h(a){if(a&&a.__esModule){return a}else{var b={};if(null!=a){for(var c in a){if(Object.prototype.hasOwnProperty.call(a,c)){var d=Object.defineProperty&&Object.getOwnPropertyDescriptor?Object.getOwnPropertyDescriptor(a,c):{};if(d.get||d.set){Object.defineProperty(b,c,d)}else{b[c]=a[c]}}}}b.default=a;return b}}function i(a){return a&&a.__esModule?a:{default:a}}function j(a,b){return m(a)||l(a,b)||k()}function k(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function l(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g=a[Symbol.iterator](),h;!(d=(h=g.next()).done);d=!0){c.push(h.value);if(b&&c.length===b)break}}catch(a){e=!0;f=a}finally{try{if(!d&&null!=g["return"])g["return"]()}finally{if(e)throw f}}return c}function m(a){if(Array.isArray(a))return a}var n=function(a,b){var c=a.find(d.default.regions.help)[0];c.innerHTML="";var f=(0,g.addIconToContainer)(c),h=null,i=new Promise(function(a){h=a}),k=e.renderForPromise("core_course/chooser_help",b);Promise.all([k,f,i]).then(function(a){var b=j(a,1),d=b[0],f=d.html,g=d.js;return e.replaceNodeContents(c,f,g)}).then(function(){c.querySelector(d.default.regions.chooserSummary.description).focus();return c}).catch(Notification.exception);a.one("slid.bs.carousel",function(){h()});a.carousel("next")},o=function(a,c){var e=function(f){if(f.target.closest(d.default.actions.optionActions.showSummary)){var e=(0,b.default)(a.getBody()[0].querySelector(d.default.regions.carousel)),g=f.target.closest(d.default.regions.chooserOption.container),h=g.dataset.modname,i=c.get(h);n(e,i)}if(f.target.matches(d.default.actions.closeOption)){var j=(0,b.default)(a.getBody()[0].querySelector(d.default.regions.carousel));j.carousel("prev");j.on("slid.bs.carousel",function(){var b=a.getBody()[0].querySelector(d.default.regions.modules),c=b.querySelector(d.default.regions.getModuleSelector(f.target.dataset.modname));c.focus()})}};a.getBodyPromise().then(function(a){return a[0]}).then(function(a){(0,b.default)(a.querySelector(d.default.regions.carousel)).carousel({interval:!1,pause:!0,keyboard:!1});return a}).then(function(a){a.addEventListener("click",e);return a}).then(function(a){p(a,c);return a}).catch()},p=function(a,c){var e=a.querySelector(d.default.regions.favouriteTabNav),g=a.querySelector(d.default.regions.recommendedTabNav),h=a.querySelector(d.default.regions.defaultTabNav);[e,g,h].forEach(function(a){return a.addEventListener("keyup",function(a){var b=a.target.parentElement.parentElement.firstElementChild.firstElementChild,c=a.target.parentElement.parentElement.lastElementChild.firstElementChild;if(a.keyCode===f.arrowRight){var d=a.target.parentElement.nextElementSibling;if(null===d){a.srcElement.tabIndex=-1;b.tabIndex=0;b.focus()}else if(d.firstElementChild.classList.contains("d-none")){a.srcElement.tabIndex=-1;c.tabIndex=0;c.focus()}else{a.srcElement.tabIndex=-1;d.firstElementChild.tabIndex=0;d.firstElementChild.focus()}}if(a.keyCode===f.arrowLeft){var e=a.target.parentElement.previousElementSibling;if(null===e){a.srcElement.tabIndex=-1;c.tabIndex=0;c.focus()}else if(e.firstElementChild.classList.contains("d-none")){a.srcElement.tabIndex=-1;b.tabIndex=0;b.focus()}else{a.srcElement.tabIndex=-1;e.firstElementChild.tabIndex=0;e.firstElementChild.focus()}}if(a.keyCode===f.home){a.srcElement.tabIndex=-1;b.tabIndex=0;b.focus()}if(a.keyCode===f.end){a.srcElement.tabIndex=-1;c.tabIndex=0;c.focus()}if(a.keyCode===f.space){a.preventDefault();a.target.click()}})});var i=a.querySelectorAll(d.default.regions.chooserOption.container);Array.from(i).forEach(function(e){return e.addEventListener("keyup",function(g){var e=document.querySelector(d.default.regions.chooserOptions);if(g.keyCode===f.enter||g.keyCode===f.space){if(g.target.matches(d.default.actions.optionActions.showSummary)){g.preventDefault();var h=g.target.closest(d.default.regions.chooserOption.container),i=h.dataset.modname,j=c.get(i),k=(0,b.default)(a.querySelector(d.default.regions.carousel));k.carousel({interval:!1,pause:!0,keyboard:!1});n(k,j)}}if(g.keyCode===f.arrowRight){g.preventDefault();var l=g.target.closest(d.default.regions.chooserOption.container),m=l.nextElementSibling,o=e.firstElementChild,p=r(m,o);q(p,l)}if(g.keyCode===f.arrowLeft){g.preventDefault();var s=g.target.closest(d.default.regions.chooserOption.container),t=s.previousElementSibling,u=e.lastElementChild,v=r(t,u);q(v,s)}if(g.keyCode===f.home){g.preventDefault();var w=g.target.closest(d.default.regions.chooserOption.container),x=e.firstElementChild;q(x,w)}if(g.keyCode===f.end){g.preventDefault();var y=g.target.closest(d.default.regions.chooserOption.container),z=e.lastElementChild;q(z,y)}})})},q=function(a){var b=1.\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 \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 {HTMLElement} 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 // Set up the tab handlers.\n const favTabNav = body.querySelector(selectors.regions.favouriteTabNav);\n const recommendedTabNav = body.querySelector(selectors.regions.recommendedTabNav);\n const defaultTabNav = body.querySelector(selectors.regions.defaultTabNav);\n const tabNavArray = [favTabNav, recommendedTabNav, defaultTabNav];\n tabNavArray.forEach((element) => {\n return element.addEventListener('keyup', (e) => {\n const firstLink = e.target.parentElement.parentElement.firstElementChild.firstElementChild;\n const lastLink = e.target.parentElement.parentElement.lastElementChild.firstElementChild;\n\n if (e.keyCode === arrowRight) {\n const nextLink = e.target.parentElement.nextElementSibling;\n if (nextLink === null) {\n e.srcElement.tabIndex = -1;\n firstLink.tabIndex = 0;\n firstLink.focus();\n } else if (nextLink.firstElementChild.classList.contains('d-none')) {\n e.srcElement.tabIndex = -1;\n lastLink.tabIndex = 0;\n lastLink.focus();\n } else {\n e.srcElement.tabIndex = -1;\n nextLink.firstElementChild.tabIndex = 0;\n nextLink.firstElementChild.focus();\n }\n }\n if (e.keyCode === arrowLeft) {\n const previousLink = e.target.parentElement.previousElementSibling;\n if (previousLink === null) {\n e.srcElement.tabIndex = -1;\n lastLink.tabIndex = 0;\n lastLink.focus();\n } else if (previousLink.firstElementChild.classList.contains('d-none')) {\n e.srcElement.tabIndex = -1;\n firstLink.tabIndex = 0;\n firstLink.focus();\n } else {\n e.srcElement.tabIndex = -1;\n previousLink.firstElementChild.tabIndex = 0;\n previousLink.firstElementChild.focus();\n }\n }\n if (e.keyCode === home) {\n e.srcElement.tabIndex = -1;\n firstLink.tabIndex = 0;\n firstLink.focus();\n }\n if (e.keyCode === end) {\n e.srcElement.tabIndex = -1;\n lastLink.tabIndex = 0;\n lastLink.focus();\n }\n if (e.keyCode === space) {\n e.preventDefault();\n e.target.click();\n }\n });\n });\n\n // Set up the handlers for the modules.\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"} \ No newline at end of file +{"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","favTabNav","favouriteTabNav","recommendedTabNav","defaultTabNav","forEach","element","firstLink","parentElement","firstElementChild","lastLink","lastElementChild","keyCode","arrowRight","nextLink","nextElementSibling","srcElement","tabIndex","classList","contains","arrowLeft","previousLink","previousElementSibling","home","end","space","preventDefault","click","chooserOptions","querySelectorAll","Array","from","document","enter","currentOption","nextOption","firstOption","toFocusOption","clickErrorHandler","focusChooserOption","previousOption","lastOption","currentChooserOption","previousChooserOption","previousChooserOptionLink","addChooser","previousChooserOptionHelp","currentChooserOptionLink","currentChooserOptionHelp","item","fallback","displayChooser","origin","sectionModules","Map","set","componentname","link","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,CAiB7CS,OAAO,CAACK,GAAR,CAAY,CAACH,CAAD,CAAiBL,CAAjB,CAAiCE,CAAjC,CAAZ,EACKO,IADL,CACU,gCAAGC,CAAH,GAAGA,IAAH,CAASC,CAAT,GAASA,EAAT,OAAkBL,CAAAA,CAAS,CAACM,mBAAV,CAA8BjB,CAA9B,CAAoCe,CAApC,CAA0CC,CAA1C,CAAlB,CADV,EAEKF,IAFL,CAEU,UAAM,CACRd,CA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OAAf,CAAuB,SAACzB,CAAD,CAAY,CAC/BT,CAAa,CAACoF,GAAd,CAAkB3E,CAAM,CAAC4E,aAAP,CAAuB,GAAvB,CAA6B5E,CAAM,CAAC6E,IAAtD,CAA4D7E,CAA5D,CACH,CAFD,EAKAX,CAAsB,CAACC,CAAD,CAAQC,CAAR,CAAtB,CAGAD,CAAK,CAACwF,OAAN,GAAgBrE,EAAhB,CAAmBsE,CAAW,CAACC,MAA/B,CAAuC,UAAM,CACzC1F,CAAK,CAAC2F,OAAN,EACH,CAFD,EAKA3F,CAAK,CAACwF,OAAN,GAAgBrE,EAAhB,CAAmBsE,CAAW,CAACG,KAA/B,CAAsC,UAAM,CACxC5F,CAAK,CAAC6F,QAAN,GAAiB,CAAjB,EAAoB9C,QAApB,CAA+B,CAAC,CAAhC,CAEA/C,CAAK,CAACwB,cAAN,GACCrC,IADD,CACM,SAAAsC,CAAI,CAAI,CACV,GAAMqE,CAAAA,CAAkB,CAAGrE,CAAI,CAAC,CAAD,CAAJ,CAAQlC,aAAR,CAAsBhB,UAAUC,OAAV,CAAkBmC,aAAlB,CAAgCC,SAAtD,CAA3B,CACAyD,CAAkB,CAACyB,CAAD,CAGrB,CAND,EAOCnG,KAPD,CAOOC,YAAY,CAACC,SAPpB,CAQH,CAXD,EAaAG,CAAK,CAAC+F,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 .\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 \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 {HTMLElement} 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 // Set up the tab handlers.\n const favTabNav = body.querySelector(selectors.regions.favouriteTabNav);\n const recommendedTabNav = body.querySelector(selectors.regions.recommendedTabNav);\n const defaultTabNav = body.querySelector(selectors.regions.defaultTabNav);\n const tabNavArray = [favTabNav, recommendedTabNav, defaultTabNav];\n tabNavArray.forEach((element) => {\n return element.addEventListener('keyup', (e) => {\n const firstLink = e.target.parentElement.parentElement.firstElementChild.firstElementChild;\n const lastLink = e.target.parentElement.parentElement.lastElementChild.firstElementChild;\n\n if (e.keyCode === arrowRight) {\n const nextLink = e.target.parentElement.nextElementSibling;\n if (nextLink === null) {\n e.srcElement.tabIndex = -1;\n firstLink.tabIndex = 0;\n firstLink.focus();\n } else if (nextLink.firstElementChild.classList.contains('d-none')) {\n e.srcElement.tabIndex = -1;\n lastLink.tabIndex = 0;\n lastLink.focus();\n } else {\n e.srcElement.tabIndex = -1;\n nextLink.firstElementChild.tabIndex = 0;\n nextLink.firstElementChild.focus();\n }\n }\n if (e.keyCode === arrowLeft) {\n const previousLink = e.target.parentElement.previousElementSibling;\n if (previousLink === null) {\n e.srcElement.tabIndex = -1;\n lastLink.tabIndex = 0;\n lastLink.focus();\n } else if (previousLink.firstElementChild.classList.contains('d-none')) {\n e.srcElement.tabIndex = -1;\n firstLink.tabIndex = 0;\n firstLink.focus();\n } else {\n e.srcElement.tabIndex = -1;\n previousLink.firstElementChild.tabIndex = 0;\n previousLink.firstElementChild.focus();\n }\n }\n if (e.keyCode === home) {\n e.srcElement.tabIndex = -1;\n firstLink.tabIndex = 0;\n firstLink.focus();\n }\n if (e.keyCode === end) {\n e.srcElement.tabIndex = -1;\n lastLink.tabIndex = 0;\n lastLink.focus();\n }\n if (e.keyCode === space) {\n e.preventDefault();\n e.target.click();\n }\n });\n });\n\n // Set up the handlers for the modules.\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.componentname + '_' + module.link, 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"} \ No newline at end of file diff --git a/course/amd/build/local/activitychooser/repository.min.js b/course/amd/build/local/activitychooser/repository.min.js index da5b3c7c694..a8213588930 100644 --- a/course/amd/build/local/activitychooser/repository.min.js +++ b/course/amd/build/local/activitychooser/repository.min.js @@ -1,2 +1,2 @@ -define ("core_course/local/activitychooser/repository",["exports","core/ajax"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.activityModules=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var c=function(a){return b.default.call([{methodname:"core_course_get_activity_picker_info",args:{courseid:a}}])[0]};a.activityModules=c}); +define ("core_course/local/activitychooser/repository",["exports","core/ajax"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.activityModules=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var c=function(a){return b.default.call([{methodname:"core_course_get_course_content_items",args:{courseid:a}}])[0]};a.activityModules=c}); //# sourceMappingURL=repository.min.js.map diff --git a/course/amd/build/local/activitychooser/repository.min.js.map b/course/amd/build/local/activitychooser/repository.min.js.map index 67b15907c10..0d357058ac9 100644 --- a/course/amd/build/local/activitychooser/repository.min.js.map +++ b/course/amd/build/local/activitychooser/repository.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../../src/local/activitychooser/repository.js"],"names":["activityModules","courseid","ajax","call","methodname","args"],"mappings":"oLAsBA,uDASO,GAAMA,CAAAA,CAAe,CAAG,SAACC,CAAD,CAAc,CAOzC,MAAOC,WAAKC,IAAL,CAAU,CAND,CACZC,UAAU,CAAE,sCADA,CAEZC,IAAI,CAAE,CACFJ,QAAQ,CAAEA,CADR,CAFM,CAMC,CAAV,EAAqB,CAArB,CACV,CARM,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 .\n\n/**\n *\n * @module core_course/repository\n * @package core_course\n * @copyright 2019 Mathew May \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport ajax from 'core/ajax';\n\n/**\n * Fetch all the information on modules we'll need in the activity chooser.\n *\n * @method activityModules\n * @param {Number} courseid What course to fetch the modules for\n * @return {object} jQuery promise\n */\nexport const activityModules = (courseid) => {\n const request = {\n methodname: 'core_course_get_activity_picker_info',\n args: {\n courseid: courseid,\n },\n };\n return ajax.call([request])[0];\n};\n"],"file":"repository.min.js"} \ No newline at end of file +{"version":3,"sources":["../../../src/local/activitychooser/repository.js"],"names":["activityModules","courseid","ajax","call","methodname","args"],"mappings":"oLAsBA,uDASO,GAAMA,CAAAA,CAAe,CAAG,SAACC,CAAD,CAAc,CAOzC,MAAOC,WAAKC,IAAL,CAAU,CAND,CACZC,UAAU,CAAE,sCADA,CAEZC,IAAI,CAAE,CACFJ,QAAQ,CAAEA,CADR,CAFM,CAMC,CAAV,EAAqB,CAArB,CACV,CARM,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 .\n\n/**\n *\n * @module core_course/repository\n * @package core_course\n * @copyright 2019 Mathew May \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport ajax from 'core/ajax';\n\n/**\n * Fetch all the information on modules we'll need in the activity chooser.\n *\n * @method activityModules\n * @param {Number} courseid What course to fetch the modules for\n * @return {object} jQuery promise\n */\nexport const activityModules = (courseid) => {\n const request = {\n methodname: 'core_course_get_course_content_items',\n args: {\n courseid: courseid,\n },\n };\n return ajax.call([request])[0];\n};\n"],"file":"repository.min.js"} \ No newline at end of file diff --git a/course/amd/src/activitychooser.js b/course/amd/src/activitychooser.js index 56599615159..2e5ecfc99d2 100644 --- a/course/amd/src/activitychooser.js +++ b/course/amd/src/activitychooser.js @@ -100,10 +100,10 @@ const registerListenerEvents = (courseId) => { const sectionIdMapper = (webServiceData, id) => { // We need to take a fresh deep copy of the original data as an object is a reference type. const newData = JSON.parse(JSON.stringify(webServiceData)); - newData.allmodules.forEach((module) => { - module.urls.addoption += '§ion=' + id; + newData.content_items.forEach((module) => { + module.link += '§ion=' + id; }); - return newData.allmodules; + return newData.content_items; }; /** diff --git a/course/amd/src/local/activitychooser/dialogue.js b/course/amd/src/local/activitychooser/dialogue.js index b8407e04d16..f443d9aca0b 100644 --- a/course/amd/src/local/activitychooser/dialogue.js +++ b/course/amd/src/local/activitychooser/dialogue.js @@ -318,7 +318,7 @@ export const displayChooser = (origin, modal, sectionModules) => { // Make a map so we can quickly fetch a specific module's object for either rendering or searching. const mappedModules = new Map(); sectionModules.forEach((module) => { - mappedModules.set(module.modulename, module); + mappedModules.set(module.componentname + '_' + module.link, module); }); // Register event listeners. diff --git a/course/amd/src/local/activitychooser/repository.js b/course/amd/src/local/activitychooser/repository.js index 1e6f1a50187..e6a09c5ab97 100644 --- a/course/amd/src/local/activitychooser/repository.js +++ b/course/amd/src/local/activitychooser/repository.js @@ -31,7 +31,7 @@ import ajax from 'core/ajax'; */ export const activityModules = (courseid) => { const request = { - methodname: 'core_course_get_activity_picker_info', + methodname: 'core_course_get_course_content_items', args: { courseid: courseid, }, diff --git a/course/templates/chooser_help.mustache b/course/templates/chooser_help.mustache index ad4dda234bf..aaf41905ba8 100644 --- a/course/templates/chooser_help.mustache +++ b/course/templates/chooser_help.mustache @@ -21,33 +21,34 @@ Example context (json): { - "label": "Option name", - "description": "Option description", - "urls": { - "addoption": "http://addoptionurl.com" - }, - "icon": "" + "id": 125, + "name": "assign", + "title": "Assignment", + "link": "http://yourmoodle/modedit.php?id=x&itemtype=y", + "icon": "", + "help": "This is a description of the assignment activity", + "archetype": 0, + "componentname": "mod_assign", + "favourite": 1 } }}
- {{#icon}} - {{>core/pix_icon}} - {{/icon}} - {{label}} + {{{icon}}} + {{title}}
- {{{description}}} + {{{help}}}
- - + {{#str}} add {{/str}}
diff --git a/course/templates/chooser_item.mustache b/course/templates/chooser_item.mustache index 92b930fc431..dd75b6a118a 100644 --- a/course/templates/chooser_item.mustache +++ b/course/templates/chooser_item.mustache @@ -29,20 +29,18 @@ "icon": "" } }} -