diff --git a/blocks/amd/build/events.min.js b/blocks/amd/build/events.min.js
new file mode 100644
index 00000000000..be506958c34
--- /dev/null
+++ b/blocks/amd/build/events.min.js
@@ -0,0 +1,2 @@
+define ("core_block/events",["exports","core/event_dispatcher"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.notifyBlockContentUpdated=a.eventTypes=void 0;var c={blockContentUpdated:"core_block/contentUpdated"};a.eventTypes=c;a.notifyBlockContentUpdated=function notifyBlockContentUpdated(a){return(0,b.dispatchEvent)(c.blockContentUpdated,{instanceId:a.dataset.instanceId},a)};var d=!1;if(!d){Y.use("event","moodle-core-event",function(a){document.addEventListener(c.blockContentUpdated,function(b){a.Global.fire(M.core.event.BLOCK_CONTENT_UPDATED,{instanceid:b.detail.instanceId})})});d=!0}});
+//# sourceMappingURL=events.min.js.map
diff --git a/blocks/amd/build/events.min.js.map b/blocks/amd/build/events.min.js.map
new file mode 100644
index 00000000000..87cecf92688
--- /dev/null
+++ b/blocks/amd/build/events.min.js.map
@@ -0,0 +1 @@
+{"version":3,"sources":["../src/events.js"],"names":["eventTypes","blockContentUpdated","notifyBlockContentUpdated","element","instanceId","dataset","legacyEventsRegistered","Y","use","document","addEventListener","e","Global","fire","M","core","event","BLOCK_CONTENT_UPDATED","instanceid","detail"],"mappings":"4LA+BO,GAAMA,CAAAA,CAAU,CAAG,CAStBC,mBAAmB,CAAE,2BATC,CAAnB,C,2CAoBkC,QAA5BC,CAAAA,yBAA4B,CAAAC,CAAO,QAAI,oBAChDH,CAAU,CAACC,mBADqC,CAEhD,CACIG,UAAU,CAAED,CAAO,CAACE,OAAR,CAAgBD,UADhC,CAFgD,CAKhDD,CALgD,CAAJ,C,CAQhD,GAAIG,CAAAA,CAAsB,GAA1B,CACA,GAAI,CAACA,CAAL,CAA6B,CAKzBC,CAAC,CAACC,GAAF,CAAM,OAAN,CAAe,mBAAf,CAAoC,SAAAD,CAAC,CAAI,CAErCE,QAAQ,CAACC,gBAAT,CAA0BV,CAAU,CAACC,mBAArC,CAA0D,SAAAU,CAAC,CAAI,CAE3DJ,CAAC,CAACK,MAAF,CAASC,IAAT,CAAcC,CAAC,CAACC,IAAF,CAAOC,KAAP,CAAaC,qBAA3B,CAAkD,CAACC,UAAU,CAAEP,CAAC,CAACQ,MAAF,CAASf,UAAtB,CAAlD,CACH,CAHD,CAIH,CAND,EAQAE,CAAsB,GACzB,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/ //\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 * Javascript events for the `core_block` subsystem.\n *\n * @module core_block/events\n * @copyright 2021 Andrew Nicols \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 4.0\n */\n\nimport {dispatchEvent} from 'core/event_dispatcher';\n\n/**\n * Events for `core_block`.\n *\n * @constant\n * @property {String} blockContentUpdated See {@link event:blockContentUpdated}\n */\nexport const eventTypes = {\n /**\n * An event triggered when the content of a block has changed.\n *\n * @event blockContentUpdated\n * @type {CustomEvent}\n * @property {HTMLElement} target The block element that was updated\n * @property {Number} instanceId The block instance id\n */\n blockContentUpdated: 'core_block/contentUpdated',\n};\n\n/**\n * Trigger an event to indicate that the content of a block was updated.\n *\n * @method notifyBlockContentUpdated\n * @param {HTMLElement} element The HTMLElement containing the updated block.\n * @returns {CustomEvent}\n * @fires blockContentUpdated\n */\nexport const notifyBlockContentUpdated = element => dispatchEvent(\n eventTypes.blockContentUpdated,\n {\n instanceId: element.dataset.instanceId,\n },\n element\n);\n\nlet legacyEventsRegistered = false;\nif (!legacyEventsRegistered) {\n // The following event triggers are legacy and will be removed in the future.\n // The following approach provides a backwards-compatability layer for the new events.\n // Code should be updated to make use of native events.\n\n Y.use('event', 'moodle-core-event', Y => {\n // Provide a backwards-compatability layer for YUI Events.\n document.addEventListener(eventTypes.blockContentUpdated, e => {\n // Trigger the legacy YUI event.\n Y.Global.fire(M.core.event.BLOCK_CONTENT_UPDATED, {instanceid: e.detail.instanceId});\n });\n });\n\n legacyEventsRegistered = true;\n}\n"],"file":"events.min.js"}
\ No newline at end of file
diff --git a/blocks/amd/src/events.js b/blocks/amd/src/events.js
new file mode 100644
index 00000000000..00ad89c2cf1
--- /dev/null
+++ b/blocks/amd/src/events.js
@@ -0,0 +1,75 @@
+// This file is part of Moodle - http://moodle.org/ //
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see .
+
+/**
+ * Javascript events for the `core_block` subsystem.
+ *
+ * @module core_block/events
+ * @copyright 2021 Andrew Nicols
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since 4.0
+ */
+
+import {dispatchEvent} from 'core/event_dispatcher';
+
+/**
+ * Events for `core_block`.
+ *
+ * @constant
+ * @property {String} blockContentUpdated See {@link event:blockContentUpdated}
+ */
+export const eventTypes = {
+ /**
+ * An event triggered when the content of a block has changed.
+ *
+ * @event blockContentUpdated
+ * @type {CustomEvent}
+ * @property {HTMLElement} target The block element that was updated
+ * @property {Number} instanceId The block instance id
+ */
+ blockContentUpdated: 'core_block/contentUpdated',
+};
+
+/**
+ * Trigger an event to indicate that the content of a block was updated.
+ *
+ * @method notifyBlockContentUpdated
+ * @param {HTMLElement} element The HTMLElement containing the updated block.
+ * @returns {CustomEvent}
+ * @fires blockContentUpdated
+ */
+export const notifyBlockContentUpdated = element => dispatchEvent(
+ eventTypes.blockContentUpdated,
+ {
+ instanceId: element.dataset.instanceId,
+ },
+ element
+);
+
+let legacyEventsRegistered = false;
+if (!legacyEventsRegistered) {
+ // The following event triggers are legacy and will be removed in the future.
+ // The following approach provides a backwards-compatability layer for the new events.
+ // Code should be updated to make use of native events.
+
+ Y.use('event', 'moodle-core-event', Y => {
+ // Provide a backwards-compatability layer for YUI Events.
+ document.addEventListener(eventTypes.blockContentUpdated, e => {
+ // Trigger the legacy YUI event.
+ Y.Global.fire(M.core.event.BLOCK_CONTENT_UPDATED, {instanceid: e.detail.instanceId});
+ });
+ });
+
+ legacyEventsRegistered = true;
+}
diff --git a/blocks/navigation/amd/build/navblock.min.js b/blocks/navigation/amd/build/navblock.min.js
index fe24b09b595..040e89a1c37 100644
--- a/blocks/navigation/amd/build/navblock.min.js
+++ b/blocks/navigation/amd/build/navblock.min.js
@@ -1,2 +1,2 @@
-define ("block_navigation/navblock",["jquery","core/tree"],function(a,b){return{init:function init(a){var c=new b(".block_navigation .block_tree");c.finishExpandingGroup=function(c){b.prototype.finishExpandingGroup.call(this,c);Y.use("moodle-core-event",function(){Y.Global.fire(M.core.globalEvents.BLOCK_CONTENT_UPDATED,{instanceid:a})})};c.collapseGroup=function(c){b.prototype.collapseGroup.call(this,c);Y.use("moodle-core-event",function(){Y.Global.fire(M.core.globalEvents.BLOCK_CONTENT_UPDATED,{instanceid:a})})}}}});
+define ("block_navigation/navblock",["exports","core_block/events","core/tree"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;c=function(a){return a&&a.__esModule?a:{default:a}}(c);var d=function(a){var d=new c.default(".block_navigation .block_tree"),e=document.querySelector("[data-instance-id=\"".concat(a,"\"]"));d.finishExpandingGroup=function(a){c.default.prototype.finishExpandingGroup.call(d,a);(0,b.notifyBlockContentUpdated)(e)};d.collapseGroup=function(a){c.default.prototype.collapseGroup.call(d,a);(0,b.notifyBlockContentUpdated)(e)}};a.init=d});
//# sourceMappingURL=navblock.min.js.map
diff --git a/blocks/navigation/amd/build/navblock.min.js.map b/blocks/navigation/amd/build/navblock.min.js.map
index f93c05d4349..cb6850264a3 100644
--- a/blocks/navigation/amd/build/navblock.min.js.map
+++ b/blocks/navigation/amd/build/navblock.min.js.map
@@ -1 +1 @@
-{"version":3,"sources":["../src/navblock.js"],"names":["define","$","Tree","init","instanceid","navTree","finishExpandingGroup","item","prototype","call","Y","use","Global","fire","M","core","globalEvents","BLOCK_CONTENT_UPDATED","collapseGroup"],"mappings":"AAuBAA,OAAM,6BAAC,CAAC,QAAD,CAAW,WAAX,CAAD,CAA0B,SAASC,CAAT,CAAYC,CAAZ,CAAkB,CAC9C,MAAO,CACHC,IAAI,CAAE,cAASC,CAAT,CAAqB,CACvB,GAAIC,CAAAA,CAAO,CAAG,GAAIH,CAAAA,CAAJ,CAAS,+BAAT,CAAd,CACAG,CAAO,CAACC,oBAAR,CAA+B,SAASC,CAAT,CAAe,CAC1CL,CAAI,CAACM,SAAL,CAAeF,oBAAf,CAAoCG,IAApC,CAAyC,IAAzC,CAA+CF,CAA/C,EACAG,CAAC,CAACC,GAAF,CAAM,mBAAN,CAA2B,UAAW,CAClCD,CAAC,CAACE,MAAF,CAASC,IAAT,CAAcC,CAAC,CAACC,IAAF,CAAOC,YAAP,CAAoBC,qBAAlC,CAAyD,CACrDb,UAAU,CAAEA,CADyC,CAAzD,CAGH,CAJD,CAKH,CAPD,CAQAC,CAAO,CAACa,aAAR,CAAwB,SAASX,CAAT,CAAe,CACnCL,CAAI,CAACM,SAAL,CAAeU,aAAf,CAA6BT,IAA7B,CAAkC,IAAlC,CAAwCF,CAAxC,EACAG,CAAC,CAACC,GAAF,CAAM,mBAAN,CAA2B,UAAW,CAClCD,CAAC,CAACE,MAAF,CAASC,IAAT,CAAcC,CAAC,CAACC,IAAF,CAAOC,YAAP,CAAoBC,qBAAlC,CAAyD,CACrDb,UAAU,CAAEA,CADyC,CAAzD,CAGH,CAJD,CAKH,CACJ,CAnBE,CAqBV,CAtBK,CAAN","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 * Load the navigation tree javascript.\n *\n * @module block_navigation/navblock\n * @package core\n * @copyright 2015 John Okely \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/tree'], function($, Tree) {\n return {\n init: function(instanceid) {\n var navTree = new Tree(\".block_navigation .block_tree\");\n navTree.finishExpandingGroup = function(item) {\n Tree.prototype.finishExpandingGroup.call(this, item);\n Y.use('moodle-core-event', function() {\n Y.Global.fire(M.core.globalEvents.BLOCK_CONTENT_UPDATED, {\n instanceid: instanceid\n });\n });\n };\n navTree.collapseGroup = function(item) {\n Tree.prototype.collapseGroup.call(this, item);\n Y.use('moodle-core-event', function() {\n Y.Global.fire(M.core.globalEvents.BLOCK_CONTENT_UPDATED, {\n instanceid: instanceid\n });\n });\n };\n }\n };\n});\n"],"file":"navblock.min.js"}
\ No newline at end of file
+{"version":3,"sources":["../src/navblock.js"],"names":["init","instanceId","navTree","Tree","blockNode","document","querySelector","finishExpandingGroup","item","prototype","call","collapseGroup"],"mappings":"4KAwBA,uDAQO,GAAMA,CAAAA,CAAI,CAAG,SAAAC,CAAU,CAAI,IACxBC,CAAAA,CAAO,CAAG,GAAIC,UAAJ,CAAS,+BAAT,CADc,CAExBC,CAAS,CAAGC,QAAQ,CAACC,aAAT,+BAA6CL,CAA7C,QAFY,CAW9BC,CAAO,CAACK,oBAAR,CAA+B,SAAAC,CAAI,CAAI,CACnCL,UAAKM,SAAL,CAAeF,oBAAf,CAAoCG,IAApC,CAAyCR,CAAzC,CAAkDM,CAAlD,EACA,gCAA0BJ,CAA1B,CACH,CAHD,CAYAF,CAAO,CAACS,aAAR,CAAwB,SAAAH,CAAI,CAAI,CAC5BL,UAAKM,SAAL,CAAeE,aAAf,CAA6BD,IAA7B,CAAkCR,CAAlC,CAA2CM,CAA3C,EACA,gCAA0BJ,CAA1B,CACH,CACJ,CA3BM,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 * Load the navigation tree javascript.\n *\n * @module block_navigation/navblock\n * @package core\n * @copyright 2015 John Okely \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport {notifyBlockContentUpdated} from 'core_block/events';\nimport Tree from 'core/tree';\n\n/**\n * Initialise the navblock javascript for the specified block instance.\n *\n * @method\n * @param {Number} instanceId\n */\nexport const init = instanceId => {\n const navTree = new Tree(\".block_navigation .block_tree\");\n const blockNode = document.querySelector(`[data-instance-id=\"${instanceId}\"]`);\n\n /**\n * The method to call when then the navtree finishes expanding a group.\n *\n * @method finishExpandingGroup\n * @param {Object} item\n * @fires event:blockContentUpdated\n */\n navTree.finishExpandingGroup = item => {\n Tree.prototype.finishExpandingGroup.call(navTree, item);\n notifyBlockContentUpdated(blockNode);\n };\n\n /**\n * The method to call whe then the navtree collapses a group\n *\n * @method collapseGroup\n * @param {Object} item\n * @fires event:blockContentUpdated\n */\n navTree.collapseGroup = item => {\n Tree.prototype.collapseGroup.call(navTree, item);\n notifyBlockContentUpdated(blockNode);\n };\n};\n"],"file":"navblock.min.js"}
\ No newline at end of file
diff --git a/blocks/navigation/amd/src/navblock.js b/blocks/navigation/amd/src/navblock.js
index 40e8678e370..b3ed755c2a5 100644
--- a/blocks/navigation/amd/src/navblock.js
+++ b/blocks/navigation/amd/src/navblock.js
@@ -21,26 +21,40 @@
* @copyright 2015 John Okely
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-define(['jquery', 'core/tree'], function($, Tree) {
- return {
- init: function(instanceid) {
- var navTree = new Tree(".block_navigation .block_tree");
- navTree.finishExpandingGroup = function(item) {
- Tree.prototype.finishExpandingGroup.call(this, item);
- Y.use('moodle-core-event', function() {
- Y.Global.fire(M.core.globalEvents.BLOCK_CONTENT_UPDATED, {
- instanceid: instanceid
- });
- });
- };
- navTree.collapseGroup = function(item) {
- Tree.prototype.collapseGroup.call(this, item);
- Y.use('moodle-core-event', function() {
- Y.Global.fire(M.core.globalEvents.BLOCK_CONTENT_UPDATED, {
- instanceid: instanceid
- });
- });
- };
- }
+import {notifyBlockContentUpdated} from 'core_block/events';
+import Tree from 'core/tree';
+
+/**
+ * Initialise the navblock javascript for the specified block instance.
+ *
+ * @method
+ * @param {Number} instanceId
+ */
+export const init = instanceId => {
+ const navTree = new Tree(".block_navigation .block_tree");
+ const blockNode = document.querySelector(`[data-instance-id="${instanceId}"]`);
+
+ /**
+ * The method to call when then the navtree finishes expanding a group.
+ *
+ * @method finishExpandingGroup
+ * @param {Object} item
+ * @fires event:blockContentUpdated
+ */
+ navTree.finishExpandingGroup = item => {
+ Tree.prototype.finishExpandingGroup.call(navTree, item);
+ notifyBlockContentUpdated(blockNode);
};
-});
+
+ /**
+ * The method to call whe then the navtree collapses a group
+ *
+ * @method collapseGroup
+ * @param {Object} item
+ * @fires event:blockContentUpdated
+ */
+ navTree.collapseGroup = item => {
+ Tree.prototype.collapseGroup.call(navTree, item);
+ notifyBlockContentUpdated(blockNode);
+ };
+};
diff --git a/blocks/settings/amd/build/settingsblock.min.js b/blocks/settings/amd/build/settingsblock.min.js
index 1bce461ca90..c6815839b16 100644
--- a/blocks/settings/amd/build/settingsblock.min.js
+++ b/blocks/settings/amd/build/settingsblock.min.js
@@ -1,2 +1,2 @@
-define ("block_settings/settingsblock",["jquery","core/tree"],function(a,b){return{init:function init(a,c){var d=new b(".block_settings .block_tree");if(c){var e=d.treeRoot.find("#"+c),f=e.children("a").first();f.replaceWith(""+f.html()+"")}d.finishExpandingGroup=function(c){b.prototype.finishExpandingGroup.call(this,c);Y.use("moodle-core-event",function(){Y.Global.fire(M.core.globalEvents.BLOCK_CONTENT_UPDATED,{instanceid:a})})};d.collapseGroup=function(c){b.prototype.collapseGroup.call(this,c);Y.use("moodle-core-event",function(){Y.Global.fire(M.core.globalEvents.BLOCK_CONTENT_UPDATED,{instanceid:a})})}}}});
+define ("block_settings/settingsblock",["exports","core_block/events","core/tree"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;c=function(a){return a&&a.__esModule?a:{default:a}}(c);var d=function(a,d){var e=new c.default(".block_settings .block_tree"),f=document.querySelector("[data-instance-id=\"".concat(a,"\"]"));if(d){var g=e.treeRoot.get(0).querySelector("#".concat(d," a")),h=document.createElement("span");h.setAttribute("tabindex","0");g.childNodes.forEach(function(a){return h.appendChild(a)});g.replaceWith(h)}e.finishExpandingGroup=function(a){c.default.prototype.finishExpandingGroup.call(e,a);(0,b.notifyBlockContentUpdated)(f)};e.collapseGroup=function(a){c.default.prototype.collapseGroup.call(e,a);(0,b.notifyBlockContentUpdated)(f)}};a.init=d});
//# sourceMappingURL=settingsblock.min.js.map
diff --git a/blocks/settings/amd/build/settingsblock.min.js.map b/blocks/settings/amd/build/settingsblock.min.js.map
index 1696676c470..3c94ae3e0ac 100644
--- a/blocks/settings/amd/build/settingsblock.min.js.map
+++ b/blocks/settings/amd/build/settingsblock.min.js.map
@@ -1 +1 @@
-{"version":3,"sources":["../src/settingsblock.js"],"names":["define","$","Tree","init","instanceid","siteAdminNodeId","adminTree","siteAdminNode","treeRoot","find","siteAdminLink","children","first","replaceWith","html","finishExpandingGroup","item","prototype","call","Y","use","Global","fire","M","core","globalEvents","BLOCK_CONTENT_UPDATED","collapseGroup"],"mappings":"AAuBAA,OAAM,gCAAC,CAAC,QAAD,CAAW,WAAX,CAAD,CAA0B,SAASC,CAAT,CAAYC,CAAZ,CAAkB,CAC9C,MAAO,CACHC,IAAI,CAAE,cAASC,CAAT,CAAqBC,CAArB,CAAsC,CACxC,GAAIC,CAAAA,CAAS,CAAG,GAAIJ,CAAAA,CAAJ,CAAS,6BAAT,CAAhB,CACA,GAAIG,CAAJ,CAAqB,IACbE,CAAAA,CAAa,CAAGD,CAAS,CAACE,QAAV,CAAmBC,IAAnB,CAAwB,IAAMJ,CAA9B,CADH,CAEbK,CAAa,CAAGH,CAAa,CAACI,QAAd,CAAuB,GAAvB,EAA4BC,KAA5B,EAFH,CAGjBF,CAAa,CAACG,WAAd,CAA0B,wBAAwBH,CAAa,CAACI,IAAd,EAAxB,CAA+C,SAAzE,CACH,CACDR,CAAS,CAACS,oBAAV,CAAiC,SAASC,CAAT,CAAe,CAC5Cd,CAAI,CAACe,SAAL,CAAeF,oBAAf,CAAoCG,IAApC,CAAyC,IAAzC,CAA+CF,CAA/C,EACAG,CAAC,CAACC,GAAF,CAAM,mBAAN,CAA2B,UAAW,CAClCD,CAAC,CAACE,MAAF,CAASC,IAAT,CAAcC,CAAC,CAACC,IAAF,CAAOC,YAAP,CAAoBC,qBAAlC,CAAyD,CACrDtB,UAAU,CAAEA,CADyC,CAAzD,CAGH,CAJD,CAKH,CAPD,CAQAE,CAAS,CAACqB,aAAV,CAA0B,SAASX,CAAT,CAAe,CACrCd,CAAI,CAACe,SAAL,CAAeU,aAAf,CAA6BT,IAA7B,CAAkC,IAAlC,CAAwCF,CAAxC,EACAG,CAAC,CAACC,GAAF,CAAM,mBAAN,CAA2B,UAAW,CAClCD,CAAC,CAACE,MAAF,CAASC,IAAT,CAAcC,CAAC,CAACC,IAAF,CAAOC,YAAP,CAAoBC,qBAAlC,CAAyD,CACrDtB,UAAU,CAAEA,CADyC,CAAzD,CAGH,CAJD,CAKH,CACJ,CAxBE,CA0BV,CA3BK,CAAN","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 * Load the settings block tree javscript\n *\n * @module block_settings/settingsblock\n * @package core\n * @copyright 2015 John Okely \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/tree'], function($, Tree) {\n return {\n init: function(instanceid, siteAdminNodeId) {\n var adminTree = new Tree(\".block_settings .block_tree\");\n if (siteAdminNodeId) {\n var siteAdminNode = adminTree.treeRoot.find('#' + siteAdminNodeId);\n var siteAdminLink = siteAdminNode.children('a').first();\n siteAdminLink.replaceWith('' + siteAdminLink.html() + '');\n }\n adminTree.finishExpandingGroup = function(item) {\n Tree.prototype.finishExpandingGroup.call(this, item);\n Y.use('moodle-core-event', function() {\n Y.Global.fire(M.core.globalEvents.BLOCK_CONTENT_UPDATED, {\n instanceid: instanceid\n });\n });\n };\n adminTree.collapseGroup = function(item) {\n Tree.prototype.collapseGroup.call(this, item);\n Y.use('moodle-core-event', function() {\n Y.Global.fire(M.core.globalEvents.BLOCK_CONTENT_UPDATED, {\n instanceid: instanceid\n });\n });\n };\n }\n };\n});\n"],"file":"settingsblock.min.js"}
\ No newline at end of file
+{"version":3,"sources":["../src/settingsblock.js"],"names":["init","instanceId","siteAdminNodeId","adminTree","Tree","blockNode","document","querySelector","siteAdminLink","treeRoot","get","newContainer","createElement","setAttribute","childNodes","forEach","node","appendChild","replaceWith","finishExpandingGroup","item","prototype","call","collapseGroup"],"mappings":"+KAwBA,uDAEO,GAAMA,CAAAA,CAAI,CAAG,SAACC,CAAD,CAAaC,CAAb,CAAiC,IAC3CC,CAAAA,CAAS,CAAG,GAAIC,UAAJ,CAAS,6BAAT,CAD+B,CAE3CC,CAAS,CAAGC,QAAQ,CAACC,aAAT,+BAA6CN,CAA7C,QAF+B,CAIjD,GAAIC,CAAJ,CAAqB,IACXM,CAAAA,CAAa,CAAGL,CAAS,CAACM,QAAV,CAAmBC,GAAnB,CAAuB,CAAvB,EAA0BH,aAA1B,YAA4CL,CAA5C,OADL,CAEXS,CAAY,CAAGL,QAAQ,CAACM,aAAT,CAAuB,MAAvB,CAFJ,CAGjBD,CAAY,CAACE,YAAb,CAA0B,UAA1B,CAAsC,GAAtC,EACAL,CAAa,CAACM,UAAd,CAAyBC,OAAzB,CAAiC,SAAAC,CAAI,QAAIL,CAAAA,CAAY,CAACM,WAAb,CAAyBD,CAAzB,CAAJ,CAArC,EACAR,CAAa,CAACU,WAAd,CAA0BP,CAA1B,CACH,CASDR,CAAS,CAACgB,oBAAV,CAAiC,SAASC,CAAT,CAAe,CAC5ChB,UAAKiB,SAAL,CAAeF,oBAAf,CAAoCG,IAApC,CAAyCnB,CAAzC,CAAoDiB,CAApD,EACA,gCAA0Bf,CAA1B,CACH,CAHD,CAYAF,CAAS,CAACoB,aAAV,CAA0B,SAASH,CAAT,CAAe,CACrChB,UAAKiB,SAAL,CAAeE,aAAf,CAA6BD,IAA7B,CAAkCnB,CAAlC,CAA6CiB,CAA7C,EACA,gCAA0Bf,CAA1B,CACH,CACJ,CAnCM,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 * Load the settings block tree javscript\n *\n * @module block_settings/settingsblock\n * @package core\n * @copyright 2015 John Okely \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport {notifyBlockContentUpdated} from 'core_block/events';\nimport Tree from 'core/tree';\n\nexport const init = (instanceId, siteAdminNodeId) => {\n const adminTree = new Tree(\".block_settings .block_tree\");\n const blockNode = document.querySelector(`[data-instance-id=\"${instanceId}\"]`);\n\n if (siteAdminNodeId) {\n const siteAdminLink = adminTree.treeRoot.get(0).querySelector(`#${siteAdminNodeId} a`);\n const newContainer = document.createElement('span');\n newContainer.setAttribute('tabindex', '0');\n siteAdminLink.childNodes.forEach(node => newContainer.appendChild(node));\n siteAdminLink.replaceWith(newContainer);\n }\n\n /**\n * The method to call when then the navtree finishes expanding a group.\n *\n * @method finishExpandingGroup\n * @param {Object} item\n * @fires event:blockContentUpdated\n */\n adminTree.finishExpandingGroup = function(item) {\n Tree.prototype.finishExpandingGroup.call(adminTree, item);\n notifyBlockContentUpdated(blockNode);\n };\n\n /**\n * The method to call whe then the navtree collapses a group\n *\n * @method collapseGroup\n * @param {Object} item\n * @fires event:blockContentUpdated\n */\n adminTree.collapseGroup = function(item) {\n Tree.prototype.collapseGroup.call(adminTree, item);\n notifyBlockContentUpdated(blockNode);\n };\n};\n"],"file":"settingsblock.min.js"}
\ No newline at end of file
diff --git a/blocks/settings/amd/src/settingsblock.js b/blocks/settings/amd/src/settingsblock.js
index f17553f1822..4fbd72dfba9 100644
--- a/blocks/settings/amd/src/settingsblock.js
+++ b/blocks/settings/amd/src/settingsblock.js
@@ -21,31 +21,42 @@
* @copyright 2015 John Okely
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-define(['jquery', 'core/tree'], function($, Tree) {
- return {
- init: function(instanceid, siteAdminNodeId) {
- var adminTree = new Tree(".block_settings .block_tree");
- if (siteAdminNodeId) {
- var siteAdminNode = adminTree.treeRoot.find('#' + siteAdminNodeId);
- var siteAdminLink = siteAdminNode.children('a').first();
- siteAdminLink.replaceWith('' + siteAdminLink.html() + '');
- }
- adminTree.finishExpandingGroup = function(item) {
- Tree.prototype.finishExpandingGroup.call(this, item);
- Y.use('moodle-core-event', function() {
- Y.Global.fire(M.core.globalEvents.BLOCK_CONTENT_UPDATED, {
- instanceid: instanceid
- });
- });
- };
- adminTree.collapseGroup = function(item) {
- Tree.prototype.collapseGroup.call(this, item);
- Y.use('moodle-core-event', function() {
- Y.Global.fire(M.core.globalEvents.BLOCK_CONTENT_UPDATED, {
- instanceid: instanceid
- });
- });
- };
- }
+import {notifyBlockContentUpdated} from 'core_block/events';
+import Tree from 'core/tree';
+
+export const init = (instanceId, siteAdminNodeId) => {
+ const adminTree = new Tree(".block_settings .block_tree");
+ const blockNode = document.querySelector(`[data-instance-id="${instanceId}"]`);
+
+ if (siteAdminNodeId) {
+ const siteAdminLink = adminTree.treeRoot.get(0).querySelector(`#${siteAdminNodeId} a`);
+ const newContainer = document.createElement('span');
+ newContainer.setAttribute('tabindex', '0');
+ siteAdminLink.childNodes.forEach(node => newContainer.appendChild(node));
+ siteAdminLink.replaceWith(newContainer);
+ }
+
+ /**
+ * The method to call when then the navtree finishes expanding a group.
+ *
+ * @method finishExpandingGroup
+ * @param {Object} item
+ * @fires event:blockContentUpdated
+ */
+ adminTree.finishExpandingGroup = function(item) {
+ Tree.prototype.finishExpandingGroup.call(adminTree, item);
+ notifyBlockContentUpdated(blockNode);
};
-});
+
+ /**
+ * The method to call whe then the navtree collapses a group
+ *
+ * @method collapseGroup
+ * @param {Object} item
+ * @fires event:blockContentUpdated
+ */
+ adminTree.collapseGroup = function(item) {
+ Tree.prototype.collapseGroup.call(adminTree, item);
+ notifyBlockContentUpdated(blockNode);
+ };
+};
diff --git a/calendar/amd/build/modal_event_form.min.js b/calendar/amd/build/modal_event_form.min.js
index 334707013c8..1e89f7f1131 100644
--- a/calendar/amd/build/modal_event_form.min.js
+++ b/calendar/amd/build/modal_event_form.min.js
@@ -1,2 +1,2 @@
-define ("core_calendar/modal_event_form",["jquery","core/event","core/str","core/notification","core/templates","core/custom_interaction_events","core/modal","core/modal_registry","core/fragment","core_calendar/events","core_calendar/repository"],function(a,b,c,d,e,f,g,h,i,j,k){var l=!1,m={SAVE_BUTTON:"[data-action=\"save\"]",LOADING_ICON_CONTAINER:"[data-region=\"loading-icon-container\"]"},n=function(a){g.call(this,a);this.eventId=null;this.startTime=null;this.courseId=null;this.categoryId=null;this.contextId=null;this.reloadingBody=!1;this.reloadingTitle=!1;this.saveButton=this.getFooter().find(m.SAVE_BUTTON)};n.TYPE="core_calendar-modal_event_form";n.prototype=Object.create(g.prototype);n.prototype.constructor=n;n.prototype.setContextId=function(a){this.contextId=a};n.prototype.getContextId=function(){return this.contextId};n.prototype.setCourseId=function(a){this.courseId=a};n.prototype.getCourseId=function(){return this.courseId};n.prototype.setCategoryId=function(a){this.categoryId=a};n.prototype.getCategoryId=function(){return this.categoryId};n.prototype.hasCourseId=function(){return null!==this.courseId};n.prototype.hasCategoryId=function(){return null!==this.categoryId};n.prototype.setEventId=function(a){this.eventId=a};n.prototype.getEventId=function(){return this.eventId};n.prototype.hasEventId=function(){return null!==this.eventId};n.prototype.setStartTime=function(a){this.startTime=a};n.prototype.getStartTime=function(){return this.startTime};n.prototype.hasStartTime=function(){return null!==this.startTime};n.prototype.getForm=function(){return this.getBody().find("form")};n.prototype.disableButtons=function(){this.saveButton.prop("disabled",!0)};n.prototype.enableButtons=function(){this.saveButton.prop("disabled",!1)};n.prototype.reloadTitleContent=function(){if(this.reloadingTitle){return this.titlePromise}this.reloadingTitle=!0;if(this.hasEventId()){this.titlePromise=c.get_string("editevent","calendar")}else{this.titlePromise=c.get_string("newevent","calendar")}this.titlePromise.then(function(a){this.setTitle(a);return a}.bind(this)).always(function(){this.reloadingTitle=!1}.bind(this)).fail(d.exception);return this.titlePromise};n.prototype.reloadBodyContent=function(a){if(this.reloadingBody){return this.bodyPromise}this.reloadingBody=!0;this.disableButtons();var b={};if(this.hasEventId()){b.eventid=this.getEventId()}if(this.hasStartTime()){b.starttime=this.getStartTime()}if(this.hasCourseId()){b.courseid=this.getCourseId()}if(this.hasCategoryId()){b.categoryid=this.getCategoryId()}if("undefined"!=typeof a){b.formdata=a}this.bodyPromise=i.loadFragment("calendar","event_form",this.getContextId(),b);this.setBody(this.bodyPromise);this.bodyPromise.then(function(){this.enableButtons()}.bind(this)).fail(d.exception).always(function(){this.reloadingBody=!1}.bind(this)).fail(d.exception);return this.bodyPromise};n.prototype.reloadAllContent=function(){return a.when(this.reloadTitleContent(),this.reloadBodyContent())};n.prototype.show=function(){this.reloadAllContent();g.prototype.show.call(this)};n.prototype.hide=function(){g.prototype.hide.call(this);this.setEventId(null);this.setStartTime(null);this.setCourseId(null);this.setCategoryId(null)};n.prototype.getFormData=function(){return this.getForm().serialize()};n.prototype.save=function(){var b,c=this.saveButton.find(m.LOADING_ICON_CONTAINER);b=this.getForm().find("[aria-invalid=\"true\"]");if(b.length){b.first().focus();return}c.removeClass("hidden");this.disableButtons();var e=this.getFormData();return k.submitCreateUpdateForm(e).then(function(b){if(b.validationerror){this.reloadBodyContent(e)}else{var c=this.hasEventId();this.hide();if(c){a("body").trigger(j.updated,[b.event])}else{a("body").trigger(j.created,[b.event])}}}.bind(this)).always(function(){c.addClass("hidden");this.enableButtons()}.bind(this)).fail(d.exception)};n.prototype.registerEventListeners=function(){g.prototype.registerEventListeners.call(this);this.getModal().on(f.events.activate,m.SAVE_BUTTON,function(a,b){this.getForm().submit();b.originalEvent.preventDefault();a.stopPropagation()}.bind(this));this.getModal().on("submit",function(a){b.notifyFormSubmitAjax(this.getForm()[0]);this.save();a.preventDefault();a.stopPropagation()}.bind(this))};if(!l){h.register(n.TYPE,n,"calendar/modal_event_form");l=!0}return n});
+define ("core_calendar/modal_event_form",["jquery","core_form/events","core/str","core/notification","core/templates","core/custom_interaction_events","core/modal","core/modal_registry","core/fragment","core_calendar/events","core_calendar/repository"],function(a,b,c,d,e,f,g,h,i,j,k){var l=!1,m={SAVE_BUTTON:"[data-action=\"save\"]",LOADING_ICON_CONTAINER:"[data-region=\"loading-icon-container\"]"},n=function(a){g.call(this,a);this.eventId=null;this.startTime=null;this.courseId=null;this.categoryId=null;this.contextId=null;this.reloadingBody=!1;this.reloadingTitle=!1;this.saveButton=this.getFooter().find(m.SAVE_BUTTON)};n.TYPE="core_calendar-modal_event_form";n.prototype=Object.create(g.prototype);n.prototype.constructor=n;n.prototype.setContextId=function(a){this.contextId=a};n.prototype.getContextId=function(){return this.contextId};n.prototype.setCourseId=function(a){this.courseId=a};n.prototype.getCourseId=function(){return this.courseId};n.prototype.setCategoryId=function(a){this.categoryId=a};n.prototype.getCategoryId=function(){return this.categoryId};n.prototype.hasCourseId=function(){return null!==this.courseId};n.prototype.hasCategoryId=function(){return null!==this.categoryId};n.prototype.setEventId=function(a){this.eventId=a};n.prototype.getEventId=function(){return this.eventId};n.prototype.hasEventId=function(){return null!==this.eventId};n.prototype.setStartTime=function(a){this.startTime=a};n.prototype.getStartTime=function(){return this.startTime};n.prototype.hasStartTime=function(){return null!==this.startTime};n.prototype.getForm=function(){return this.getBody().find("form")};n.prototype.disableButtons=function(){this.saveButton.prop("disabled",!0)};n.prototype.enableButtons=function(){this.saveButton.prop("disabled",!1)};n.prototype.reloadTitleContent=function(){if(this.reloadingTitle){return this.titlePromise}this.reloadingTitle=!0;if(this.hasEventId()){this.titlePromise=c.get_string("editevent","calendar")}else{this.titlePromise=c.get_string("newevent","calendar")}this.titlePromise.then(function(a){this.setTitle(a);return a}.bind(this)).always(function(){this.reloadingTitle=!1}.bind(this)).fail(d.exception);return this.titlePromise};n.prototype.reloadBodyContent=function(a){if(this.reloadingBody){return this.bodyPromise}this.reloadingBody=!0;this.disableButtons();var b={};if(this.hasEventId()){b.eventid=this.getEventId()}if(this.hasStartTime()){b.starttime=this.getStartTime()}if(this.hasCourseId()){b.courseid=this.getCourseId()}if(this.hasCategoryId()){b.categoryid=this.getCategoryId()}if("undefined"!=typeof a){b.formdata=a}this.bodyPromise=i.loadFragment("calendar","event_form",this.getContextId(),b);this.setBody(this.bodyPromise);this.bodyPromise.then(function(){this.enableButtons()}.bind(this)).fail(d.exception).always(function(){this.reloadingBody=!1}.bind(this)).fail(d.exception);return this.bodyPromise};n.prototype.reloadAllContent=function(){return a.when(this.reloadTitleContent(),this.reloadBodyContent())};n.prototype.show=function(){this.reloadAllContent();g.prototype.show.call(this)};n.prototype.hide=function(){g.prototype.hide.call(this);this.setEventId(null);this.setStartTime(null);this.setCourseId(null);this.setCategoryId(null)};n.prototype.getFormData=function(){return this.getForm().serialize()};n.prototype.save=function(){var b,c=this.saveButton.find(m.LOADING_ICON_CONTAINER);b=this.getForm().find("[aria-invalid=\"true\"]");if(b.length){b.first().focus();return Promise.resolve()}c.removeClass("hidden");this.disableButtons();var e=this.getFormData();return k.submitCreateUpdateForm(e).then(function(b){if(b.validationerror){this.reloadBodyContent(e)}else{var c=this.hasEventId();this.hide();if(c){a("body").trigger(j.updated,[b.event])}else{a("body").trigger(j.created,[b.event])}}}.bind(this)).always(function(){c.addClass("hidden");this.enableButtons()}.bind(this)).fail(d.exception)};n.prototype.registerEventListeners=function(){g.prototype.registerEventListeners.call(this);this.getModal().on(f.events.activate,m.SAVE_BUTTON,function(a,b){this.getForm().submit();b.originalEvent.preventDefault();a.stopPropagation()}.bind(this));this.getModal().on("submit",function(a){b.notifyFormSubmittedByJavascript(this.getForm()[0]);this.save();a.preventDefault();a.stopPropagation()}.bind(this))};if(!l){h.register(n.TYPE,n,"calendar/modal_event_form");l=!0}return n});
//# sourceMappingURL=modal_event_form.min.js.map
diff --git a/calendar/amd/build/modal_event_form.min.js.map b/calendar/amd/build/modal_event_form.min.js.map
index 6962097c568..0ea25bcd9fd 100644
--- a/calendar/amd/build/modal_event_form.min.js.map
+++ b/calendar/amd/build/modal_event_form.min.js.map
@@ -1 +1 @@
-{"version":3,"sources":["../src/modal_event_form.js"],"names":["define","$","Event","Str","Notification","Templates","CustomEvents","Modal","ModalRegistry","Fragment","CalendarEvents","Repository","registered","SELECTORS","SAVE_BUTTON","LOADING_ICON_CONTAINER","ModalEventForm","root","call","eventId","startTime","courseId","categoryId","contextId","reloadingBody","reloadingTitle","saveButton","getFooter","find","TYPE","prototype","Object","create","constructor","setContextId","id","getContextId","setCourseId","getCourseId","setCategoryId","getCategoryId","hasCourseId","hasCategoryId","setEventId","getEventId","hasEventId","setStartTime","time","getStartTime","hasStartTime","getForm","getBody","disableButtons","prop","enableButtons","reloadTitleContent","titlePromise","get_string","then","string","setTitle","bind","always","fail","exception","reloadBodyContent","formData","bodyPromise","args","eventid","starttime","courseid","categoryid","formdata","loadFragment","setBody","reloadAllContent","when","show","hide","getFormData","serialize","save","invalid","loadingContainer","length","first","focus","removeClass","submitCreateUpdateForm","response","validationerror","isExisting","trigger","updated","event","created","addClass","registerEventListeners","getModal","on","events","activate","e","data","submit","originalEvent","preventDefault","stopPropagation","notifyFormSubmitAjax","register"],"mappings":"AAwBAA,OAAM,kCAAC,CACK,QADL,CAEK,YAFL,CAGK,UAHL,CAIK,mBAJL,CAKK,gBALL,CAMK,gCANL,CAOK,YAPL,CAQK,qBARL,CASK,eATL,CAUK,sBAVL,CAWK,0BAXL,CAAD,CAaE,SACIC,CADJ,CAEIC,CAFJ,CAGIC,CAHJ,CAIIC,CAJJ,CAKIC,CALJ,CAMIC,CANJ,CAOIC,CAPJ,CAQIC,CARJ,CASIC,CATJ,CAUIC,CAVJ,CAWIC,CAXJ,CAYE,IAEFC,CAAAA,CAAU,GAFR,CAGFC,CAAS,CAAG,CACZC,WAAW,CAAE,wBADD,CAEZC,sBAAsB,CAAE,0CAFZ,CAHV,CAaFC,CAAc,CAAG,SAASC,CAAT,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KA,KAAKiF,QAAL,GAAgBC,EAAhB,CAAmB9F,CAAY,CAAC+F,MAAb,CAAoBC,QAAvC,CAAiDzF,CAAS,CAACC,WAA3D,CAAwE,SAASyF,CAAT,CAAYC,CAAZ,CAAkB,CACtF,KAAKtD,OAAL,GAAeuD,MAAf,GACAD,CAAI,CAACE,aAAL,CAAmBC,cAAnB,GACAJ,CAAC,CAACK,eAAF,EACH,CAJuE,CAItE/C,IAJsE,CAIjE,IAJiE,CAAxE,EAQA,KAAKsC,QAAL,GAAgBC,EAAhB,CAAmB,QAAnB,CAA6B,SAASG,CAAT,CAAY,CACrCrG,CAAK,CAAC2G,oBAAN,CAA2B,KAAK3D,OAAL,GAAe,CAAf,CAA3B,EAEA,KAAKgC,IAAL,GAIAqB,CAAC,CAACI,cAAF,GACAJ,CAAC,CAACK,eAAF,EACH,CAT4B,CAS3B/C,IAT2B,CAStB,IATsB,CAA7B,CAUH,CAzBD,CA6BA,GAAI,CAACjD,CAAL,CAAiB,CACbJ,CAAa,CAACsG,QAAd,CAAuB9F,CAAc,CAACa,IAAtC,CAA4Cb,CAA5C,CAA4D,2BAA5D,EACAJ,CAAU,GACb,CAED,MAAOI,CAAAA,CACV,CA/dK,CAAN","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 the quick add or update event modal.\n *\n * @module calendar/modal_quick_add_event\n * @class modal_quick_add_event\n * @package core\n * @copyright 2017 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([\n 'jquery',\n 'core/event',\n 'core/str',\n 'core/notification',\n 'core/templates',\n 'core/custom_interaction_events',\n 'core/modal',\n 'core/modal_registry',\n 'core/fragment',\n 'core_calendar/events',\n 'core_calendar/repository'\n ],\n function(\n $,\n Event,\n Str,\n Notification,\n Templates,\n CustomEvents,\n Modal,\n ModalRegistry,\n Fragment,\n CalendarEvents,\n Repository\n ) {\n\n var registered = false;\n var SELECTORS = {\n SAVE_BUTTON: '[data-action=\"save\"]',\n LOADING_ICON_CONTAINER: '[data-region=\"loading-icon-container\"]',\n };\n\n /**\n * Constructor for the Modal.\n *\n * @param {object} root The root jQuery element for the modal\n */\n var ModalEventForm = function(root) {\n Modal.call(this, root);\n this.eventId = null;\n this.startTime = null;\n this.courseId = null;\n this.categoryId = null;\n this.contextId = null;\n this.reloadingBody = false;\n this.reloadingTitle = false;\n this.saveButton = this.getFooter().find(SELECTORS.SAVE_BUTTON);\n };\n\n ModalEventForm.TYPE = 'core_calendar-modal_event_form';\n ModalEventForm.prototype = Object.create(Modal.prototype);\n ModalEventForm.prototype.constructor = ModalEventForm;\n\n /**\n * Set the context id to the given value.\n *\n * @method setContextId\n * @param {Number} id The event id\n */\n ModalEventForm.prototype.setContextId = function(id) {\n this.contextId = id;\n };\n\n /**\n * Retrieve the current context id, if any.\n *\n * @method getContextId\n * @return {Number|null} The event id\n */\n ModalEventForm.prototype.getContextId = function() {\n return this.contextId;\n };\n\n /**\n * Set the course id to the given value.\n *\n * @method setCourseId\n * @param {int} id The event id\n */\n ModalEventForm.prototype.setCourseId = function(id) {\n this.courseId = id;\n };\n\n /**\n * Retrieve the current course id, if any.\n *\n * @method getCourseId\n * @return {int|null} The event id\n */\n ModalEventForm.prototype.getCourseId = function() {\n return this.courseId;\n };\n\n /**\n * Set the category id to the given value.\n *\n * @method setCategoryId\n * @param {int} id The event id\n */\n ModalEventForm.prototype.setCategoryId = function(id) {\n this.categoryId = id;\n };\n\n /**\n * Retrieve the current category id, if any.\n *\n * @method getCategoryId\n * @return {int|null} The event id\n */\n ModalEventForm.prototype.getCategoryId = function() {\n return this.categoryId;\n };\n\n /**\n * Check if the modal has an course id.\n *\n * @method hasCourseId\n * @return {bool}\n */\n ModalEventForm.prototype.hasCourseId = function() {\n return this.courseId !== null;\n };\n\n /**\n * Check if the modal has an category id.\n *\n * @method hasCategoryId\n * @return {bool}\n */\n ModalEventForm.prototype.hasCategoryId = function() {\n return this.categoryId !== null;\n };\n\n /**\n * Set the event id to the given value.\n *\n * @method setEventId\n * @param {int} id The event id\n */\n ModalEventForm.prototype.setEventId = function(id) {\n this.eventId = id;\n };\n\n /**\n * Retrieve the current event id, if any.\n *\n * @method getEventId\n * @return {int|null} The event id\n */\n ModalEventForm.prototype.getEventId = function() {\n return this.eventId;\n };\n\n /**\n * Check if the modal has an event id.\n *\n * @method hasEventId\n * @return {bool}\n */\n ModalEventForm.prototype.hasEventId = function() {\n return this.eventId !== null;\n };\n\n /**\n * Set the start time to the given value.\n *\n * @method setStartTime\n * @param {int} time The start time\n */\n ModalEventForm.prototype.setStartTime = function(time) {\n this.startTime = time;\n };\n\n /**\n * Retrieve the current start time, if any.\n *\n * @method getStartTime\n * @return {int|null} The start time\n */\n ModalEventForm.prototype.getStartTime = function() {\n return this.startTime;\n };\n\n /**\n * Check if the modal has start time.\n *\n * @method hasStartTime\n * @return {bool}\n */\n ModalEventForm.prototype.hasStartTime = function() {\n return this.startTime !== null;\n };\n\n /**\n * Get the form element from the modal.\n *\n * @method getForm\n * @return {object}\n */\n ModalEventForm.prototype.getForm = function() {\n return this.getBody().find('form');\n };\n\n /**\n * Disable the buttons in the footer.\n *\n * @method disableButtons\n */\n ModalEventForm.prototype.disableButtons = function() {\n this.saveButton.prop('disabled', true);\n };\n\n /**\n * Enable the buttons in the footer.\n *\n * @method enableButtons\n */\n ModalEventForm.prototype.enableButtons = function() {\n this.saveButton.prop('disabled', false);\n };\n\n /**\n * Reload the title for the modal to the appropriate value\n * depending on whether we are creating a new event or\n * editing an existing event.\n *\n * @method reloadTitleContent\n * @return {object} A promise resolved with the new title text\n */\n ModalEventForm.prototype.reloadTitleContent = function() {\n if (this.reloadingTitle) {\n return this.titlePromise;\n }\n\n this.reloadingTitle = true;\n\n if (this.hasEventId()) {\n this.titlePromise = Str.get_string('editevent', 'calendar');\n } else {\n this.titlePromise = Str.get_string('newevent', 'calendar');\n }\n\n this.titlePromise.then(function(string) {\n this.setTitle(string);\n return string;\n }.bind(this))\n .always(function() {\n this.reloadingTitle = false;\n return;\n }.bind(this))\n .fail(Notification.exception);\n\n return this.titlePromise;\n };\n\n /**\n * Send a request to the server to get the event_form in a fragment\n * and render the result in the body of the modal.\n *\n * If serialised form data is provided then it will be sent in the\n * request to the server to have the form rendered with the data. This\n * is used when the form had a server side error and we need the server\n * to re-render it for us to display the error to the user.\n *\n * @method reloadBodyContent\n * @param {string} formData The serialised form data\n * @return {object} A promise resolved with the fragment html and js from\n */\n ModalEventForm.prototype.reloadBodyContent = function(formData) {\n if (this.reloadingBody) {\n return this.bodyPromise;\n }\n\n this.reloadingBody = true;\n this.disableButtons();\n\n var args = {};\n\n if (this.hasEventId()) {\n args.eventid = this.getEventId();\n }\n\n if (this.hasStartTime()) {\n args.starttime = this.getStartTime();\n }\n\n if (this.hasCourseId()) {\n args.courseid = this.getCourseId();\n }\n\n if (this.hasCategoryId()) {\n args.categoryid = this.getCategoryId();\n }\n\n if (typeof formData !== 'undefined') {\n args.formdata = formData;\n }\n\n this.bodyPromise = Fragment.loadFragment('calendar', 'event_form', this.getContextId(), args);\n\n this.setBody(this.bodyPromise);\n\n this.bodyPromise.then(function() {\n this.enableButtons();\n return;\n }.bind(this))\n .fail(Notification.exception)\n .always(function() {\n this.reloadingBody = false;\n return;\n }.bind(this))\n .fail(Notification.exception);\n\n return this.bodyPromise;\n };\n\n /**\n * Reload both the title and body content.\n *\n * @method reloadAllContent\n * @return {object} promise\n */\n ModalEventForm.prototype.reloadAllContent = function() {\n return $.when(this.reloadTitleContent(), this.reloadBodyContent());\n };\n\n /**\n * Kick off a reload the modal content before showing it. This\n * is to allow us to re-use the same modal for creating and\n * editing different events within the page.\n *\n * We do the reload when showing the modal rather than hiding it\n * to save a request to the server if the user closes the modal\n * and never re-opens it.\n *\n * @method show\n */\n ModalEventForm.prototype.show = function() {\n this.reloadAllContent();\n Modal.prototype.show.call(this);\n };\n\n /**\n * Clear the event id from the modal when it's closed so\n * that it is loaded fresh next time it's displayed.\n *\n * The event id will be set by the calling code if it wants\n * to edit a specific event.\n *\n * @method hide\n */\n ModalEventForm.prototype.hide = function() {\n Modal.prototype.hide.call(this);\n this.setEventId(null);\n this.setStartTime(null);\n this.setCourseId(null);\n this.setCategoryId(null);\n };\n\n /**\n * Get the serialised form data.\n *\n * @method getFormData\n * @return {string} serialised form data\n */\n ModalEventForm.prototype.getFormData = function() {\n return this.getForm().serialize();\n };\n\n /**\n * Send the form data to the server to create or update\n * an event.\n *\n * If there is a server side validation error then we re-request the\n * rendered form (with the data) from the server in order to get the\n * server side errors to display.\n *\n * On success the modal is hidden and the page is reloaded so that the\n * new event will display.\n *\n * @method save\n * @return {object} A promise\n */\n ModalEventForm.prototype.save = function() {\n var invalid,\n loadingContainer = this.saveButton.find(SELECTORS.LOADING_ICON_CONTAINER);\n\n // Now the change events have run, see if there are any \"invalid\" form fields.\n invalid = this.getForm().find('[aria-invalid=\"true\"]');\n\n // If we found invalid fields, focus on the first one and do not submit via ajax.\n if (invalid.length) {\n invalid.first().focus();\n return;\n }\n\n loadingContainer.removeClass('hidden');\n this.disableButtons();\n\n var formData = this.getFormData();\n // Send the form data to the server for processing.\n return Repository.submitCreateUpdateForm(formData)\n .then(function(response) {\n if (response.validationerror) {\n // If there was a server side validation error then\n // we need to re-request the rendered form from the server\n // in order to display the error for the user.\n this.reloadBodyContent(formData);\n return;\n } else {\n // Check whether this was a new event or not.\n // The hide function unsets the form data so grab this before the hide.\n var isExisting = this.hasEventId();\n\n // No problemo! Our work here is done.\n this.hide();\n\n // Trigger the appropriate calendar event so that the view can be updated.\n if (isExisting) {\n $('body').trigger(CalendarEvents.updated, [response.event]);\n } else {\n $('body').trigger(CalendarEvents.created, [response.event]);\n }\n }\n\n return;\n }.bind(this))\n .always(function() {\n // Regardless of success or error we should always stop\n // the loading icon and re-enable the buttons.\n loadingContainer.addClass('hidden');\n this.enableButtons();\n\n return;\n }.bind(this))\n .fail(Notification.exception);\n };\n\n /**\n * Set up all of the event handling for the modal.\n *\n * @method registerEventListeners\n */\n ModalEventForm.prototype.registerEventListeners = function() {\n // Apply parent event listeners.\n Modal.prototype.registerEventListeners.call(this);\n\n // When the user clicks the save button we trigger the form submission. We need to\n // trigger an actual submission because there is some JS code in the form that is\n // listening for this event and doing some stuff (e.g. saving draft areas etc).\n this.getModal().on(CustomEvents.events.activate, SELECTORS.SAVE_BUTTON, function(e, data) {\n this.getForm().submit();\n data.originalEvent.preventDefault();\n e.stopPropagation();\n }.bind(this));\n\n // Catch the submit event before it is actually processed by the browser and\n // prevent the submission. We'll take it from here.\n this.getModal().on('submit', function(e) {\n Event.notifyFormSubmitAjax(this.getForm()[0]);\n\n this.save();\n\n // Stop the form from actually submitting and prevent it's\n // propagation because we have already handled the event.\n e.preventDefault();\n e.stopPropagation();\n }.bind(this));\n };\n\n // Automatically register with the modal registry the first time this module is imported so that you can create modals\n // of this type using the modal factory.\n if (!registered) {\n ModalRegistry.register(ModalEventForm.TYPE, ModalEventForm, 'calendar/modal_event_form');\n registered = true;\n }\n\n return ModalEventForm;\n});\n"],"file":"modal_event_form.min.js"}
\ No newline at end of file
+{"version":3,"sources":["../src/modal_event_form.js"],"names":["define","$","FormEvents","Str","Notification","Templates","CustomEvents","Modal","ModalRegistry","Fragment","CalendarEvents","Repository","registered","SELECTORS","SAVE_BUTTON","LOADING_ICON_CONTAINER","ModalEventForm","root","call","eventId","startTime","courseId","categoryId","contextId","reloadingBody","reloadingTitle","saveButton","getFooter","find","TYPE","prototype","Object","create","constructor","setContextId","id","getContextId","setCourseId","getCourseId","setCategoryId","getCategoryId","hasCourseId","hasCategoryId","setEventId","getEventId","hasEventId","setStartTime","time","getStartTime","hasStartTime","getForm","getBody","disableButtons","prop","enableButtons","reloadTitleContent","titlePromise","get_string","then","string","setTitle","bind","always","fail","exception","reloadBodyContent","formData","bodyPromise","args","eventid","starttime","courseid","categoryid","formdata","loadFragment","setBody","reloadAllContent","when","show","hide","getFormData","serialize","save","invalid","loadingContainer","length","first","focus","Promise","resolve","removeClass","submitCreateUpdateForm","response","validationerror","isExisting","trigger","updated","event","created","addClass","registerEventListeners","getModal","on","events","activate","e","data","submit","originalEvent","preventDefault","stopPropagation","notifyFormSubmittedByJavascript","register"],"mappings":"AAwBAA,OAAM,kCAAC,CACH,QADG,CAEH,kBAFG,CAGH,UAHG,CAIH,mBAJG,CAKH,gBALG,CAMH,gCANG,CAOH,YAPG,CAQH,qBARG,CASH,eATG,CAUH,sBAVG,CAWH,0BAXG,CAAD,CAaN,SACIC,CADJ,CAEIC,CAFJ,CAGIC,CAHJ,CAIIC,CAJJ,CAKIC,CALJ,CAMIC,CANJ,CAOIC,CAPJ,CAQIC,CARJ,CASIC,CATJ,CAUIC,CAVJ,CAWIC,CAXJ,CAYE,IACMC,CAAAA,CAAU,GADhB,CAEMC,CAAS,CAAG,CACZC,WAAW,CAAE,wBADD,CAEZC,sBAAsB,CAAE,0CAFZ,CAFlB,CAYMC,CAAc,CAAG,SAASC,CAAT,CAAe,CAChCV,CAAK,CAACW,IAAN,CAAW,IAAX,CAAiBD,CAAjB,EACA,KAAKE,OAAL,CAAe,IAAf,CACA,KAAKC,SAAL,CAAiB,IAAjB,CACA,KAAKC,QAAL,CAAgB,IAAhB,CACA,KAAKC,UAAL,CAAkB,IAAlB,CACA,KAAKC,SAAL,CAAiB,IAAjB,CACA,KAAKC,aAAL,IACA,KAAKC,cAAL,IACA,KAAKC,UAAL,CAAkB,KAAKC,SAAL,GAAiBC,IAAjB,CAAsBf,CAAS,CAACC,WAAhC,CACrB,CAtBH,CAwBEE,CAAc,CAACa,IAAf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AAnB,CAA6B,SAASG,CAAT,CAAY,CACrCvG,CAAU,CAAC6G,+BAAX,CAA2C,KAAK7D,OAAL,GAAe,CAAf,CAA3C,EAEA,KAAKgC,IAAL,GAIAuB,CAAC,CAACI,cAAF,GACAJ,CAAC,CAACK,eAAF,EACH,CAT4B,CAS3BjD,IAT2B,CAStB,IATsB,CAA7B,CAUH,CAzBD,CA6BA,GAAI,CAACjD,CAAL,CAAiB,CACbJ,CAAa,CAACwG,QAAd,CAAuBhG,CAAc,CAACa,IAAtC,CAA4Cb,CAA5C,CAA4D,2BAA5D,EACAJ,CAAU,GACb,CAED,MAAOI,CAAAA,CACV,CAheK,CAAN","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 the quick add or update event modal.\n *\n * @module calendar/modal_quick_add_event\n * @class modal_quick_add_event\n * @package core\n * @copyright 2017 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([\n 'jquery',\n 'core_form/events',\n 'core/str',\n 'core/notification',\n 'core/templates',\n 'core/custom_interaction_events',\n 'core/modal',\n 'core/modal_registry',\n 'core/fragment',\n 'core_calendar/events',\n 'core_calendar/repository'\n],\nfunction(\n $,\n FormEvents,\n Str,\n Notification,\n Templates,\n CustomEvents,\n Modal,\n ModalRegistry,\n Fragment,\n CalendarEvents,\n Repository\n) {\n var registered = false;\n var SELECTORS = {\n SAVE_BUTTON: '[data-action=\"save\"]',\n LOADING_ICON_CONTAINER: '[data-region=\"loading-icon-container\"]',\n };\n\n /**\n * Constructor for the Modal.\n *\n * @param {object} root The root jQuery element for the modal\n */\n var ModalEventForm = function(root) {\n Modal.call(this, root);\n this.eventId = null;\n this.startTime = null;\n this.courseId = null;\n this.categoryId = null;\n this.contextId = null;\n this.reloadingBody = false;\n this.reloadingTitle = false;\n this.saveButton = this.getFooter().find(SELECTORS.SAVE_BUTTON);\n };\n\n ModalEventForm.TYPE = 'core_calendar-modal_event_form';\n ModalEventForm.prototype = Object.create(Modal.prototype);\n ModalEventForm.prototype.constructor = ModalEventForm;\n\n /**\n * Set the context id to the given value.\n *\n * @method setContextId\n * @param {Number} id The event id\n */\n ModalEventForm.prototype.setContextId = function(id) {\n this.contextId = id;\n };\n\n /**\n * Retrieve the current context id, if any.\n *\n * @method getContextId\n * @return {Number|null} The event id\n */\n ModalEventForm.prototype.getContextId = function() {\n return this.contextId;\n };\n\n /**\n * Set the course id to the given value.\n *\n * @method setCourseId\n * @param {int} id The event id\n */\n ModalEventForm.prototype.setCourseId = function(id) {\n this.courseId = id;\n };\n\n /**\n * Retrieve the current course id, if any.\n *\n * @method getCourseId\n * @return {int|null} The event id\n */\n ModalEventForm.prototype.getCourseId = function() {\n return this.courseId;\n };\n\n /**\n * Set the category id to the given value.\n *\n * @method setCategoryId\n * @param {int} id The event id\n */\n ModalEventForm.prototype.setCategoryId = function(id) {\n this.categoryId = id;\n };\n\n /**\n * Retrieve the current category id, if any.\n *\n * @method getCategoryId\n * @return {int|null} The event id\n */\n ModalEventForm.prototype.getCategoryId = function() {\n return this.categoryId;\n };\n\n /**\n * Check if the modal has an course id.\n *\n * @method hasCourseId\n * @return {bool}\n */\n ModalEventForm.prototype.hasCourseId = function() {\n return this.courseId !== null;\n };\n\n /**\n * Check if the modal has an category id.\n *\n * @method hasCategoryId\n * @return {bool}\n */\n ModalEventForm.prototype.hasCategoryId = function() {\n return this.categoryId !== null;\n };\n\n /**\n * Set the event id to the given value.\n *\n * @method setEventId\n * @param {int} id The event id\n */\n ModalEventForm.prototype.setEventId = function(id) {\n this.eventId = id;\n };\n\n /**\n * Retrieve the current event id, if any.\n *\n * @method getEventId\n * @return {int|null} The event id\n */\n ModalEventForm.prototype.getEventId = function() {\n return this.eventId;\n };\n\n /**\n * Check if the modal has an event id.\n *\n * @method hasEventId\n * @return {bool}\n */\n ModalEventForm.prototype.hasEventId = function() {\n return this.eventId !== null;\n };\n\n /**\n * Set the start time to the given value.\n *\n * @method setStartTime\n * @param {int} time The start time\n */\n ModalEventForm.prototype.setStartTime = function(time) {\n this.startTime = time;\n };\n\n /**\n * Retrieve the current start time, if any.\n *\n * @method getStartTime\n * @return {int|null} The start time\n */\n ModalEventForm.prototype.getStartTime = function() {\n return this.startTime;\n };\n\n /**\n * Check if the modal has start time.\n *\n * @method hasStartTime\n * @return {bool}\n */\n ModalEventForm.prototype.hasStartTime = function() {\n return this.startTime !== null;\n };\n\n /**\n * Get the form element from the modal.\n *\n * @method getForm\n * @return {object}\n */\n ModalEventForm.prototype.getForm = function() {\n return this.getBody().find('form');\n };\n\n /**\n * Disable the buttons in the footer.\n *\n * @method disableButtons\n */\n ModalEventForm.prototype.disableButtons = function() {\n this.saveButton.prop('disabled', true);\n };\n\n /**\n * Enable the buttons in the footer.\n *\n * @method enableButtons\n */\n ModalEventForm.prototype.enableButtons = function() {\n this.saveButton.prop('disabled', false);\n };\n\n /**\n * Reload the title for the modal to the appropriate value\n * depending on whether we are creating a new event or\n * editing an existing event.\n *\n * @method reloadTitleContent\n * @return {object} A promise resolved with the new title text\n */\n ModalEventForm.prototype.reloadTitleContent = function() {\n if (this.reloadingTitle) {\n return this.titlePromise;\n }\n\n this.reloadingTitle = true;\n\n if (this.hasEventId()) {\n this.titlePromise = Str.get_string('editevent', 'calendar');\n } else {\n this.titlePromise = Str.get_string('newevent', 'calendar');\n }\n\n this.titlePromise.then(function(string) {\n this.setTitle(string);\n return string;\n }.bind(this))\n .always(function() {\n this.reloadingTitle = false;\n return;\n }.bind(this))\n .fail(Notification.exception);\n\n return this.titlePromise;\n };\n\n /**\n * Send a request to the server to get the event_form in a fragment\n * and render the result in the body of the modal.\n *\n * If serialised form data is provided then it will be sent in the\n * request to the server to have the form rendered with the data. This\n * is used when the form had a server side error and we need the server\n * to re-render it for us to display the error to the user.\n *\n * @method reloadBodyContent\n * @param {string} formData The serialised form data\n * @return {object} A promise resolved with the fragment html and js from\n */\n ModalEventForm.prototype.reloadBodyContent = function(formData) {\n if (this.reloadingBody) {\n return this.bodyPromise;\n }\n\n this.reloadingBody = true;\n this.disableButtons();\n\n var args = {};\n\n if (this.hasEventId()) {\n args.eventid = this.getEventId();\n }\n\n if (this.hasStartTime()) {\n args.starttime = this.getStartTime();\n }\n\n if (this.hasCourseId()) {\n args.courseid = this.getCourseId();\n }\n\n if (this.hasCategoryId()) {\n args.categoryid = this.getCategoryId();\n }\n\n if (typeof formData !== 'undefined') {\n args.formdata = formData;\n }\n\n this.bodyPromise = Fragment.loadFragment('calendar', 'event_form', this.getContextId(), args);\n\n this.setBody(this.bodyPromise);\n\n this.bodyPromise.then(function() {\n this.enableButtons();\n return;\n }.bind(this))\n .fail(Notification.exception)\n .always(function() {\n this.reloadingBody = false;\n return;\n }.bind(this))\n .fail(Notification.exception);\n\n return this.bodyPromise;\n };\n\n /**\n * Reload both the title and body content.\n *\n * @method reloadAllContent\n * @return {object} promise\n */\n ModalEventForm.prototype.reloadAllContent = function() {\n return $.when(this.reloadTitleContent(), this.reloadBodyContent());\n };\n\n /**\n * Kick off a reload the modal content before showing it. This\n * is to allow us to re-use the same modal for creating and\n * editing different events within the page.\n *\n * We do the reload when showing the modal rather than hiding it\n * to save a request to the server if the user closes the modal\n * and never re-opens it.\n *\n * @method show\n */\n ModalEventForm.prototype.show = function() {\n this.reloadAllContent();\n Modal.prototype.show.call(this);\n };\n\n /**\n * Clear the event id from the modal when it's closed so\n * that it is loaded fresh next time it's displayed.\n *\n * The event id will be set by the calling code if it wants\n * to edit a specific event.\n *\n * @method hide\n */\n ModalEventForm.prototype.hide = function() {\n Modal.prototype.hide.call(this);\n this.setEventId(null);\n this.setStartTime(null);\n this.setCourseId(null);\n this.setCategoryId(null);\n };\n\n /**\n * Get the serialised form data.\n *\n * @method getFormData\n * @return {string} serialised form data\n */\n ModalEventForm.prototype.getFormData = function() {\n return this.getForm().serialize();\n };\n\n /**\n * Send the form data to the server to create or update\n * an event.\n *\n * If there is a server side validation error then we re-request the\n * rendered form (with the data) from the server in order to get the\n * server side errors to display.\n *\n * On success the modal is hidden and the page is reloaded so that the\n * new event will display.\n *\n * @method save\n * @return {object} A promise\n */\n ModalEventForm.prototype.save = function() {\n var invalid,\n loadingContainer = this.saveButton.find(SELECTORS.LOADING_ICON_CONTAINER);\n\n // Now the change events have run, see if there are any \"invalid\" form fields.\n invalid = this.getForm().find('[aria-invalid=\"true\"]');\n\n // If we found invalid fields, focus on the first one and do not submit via ajax.\n if (invalid.length) {\n invalid.first().focus();\n return Promise.resolve();\n }\n\n loadingContainer.removeClass('hidden');\n this.disableButtons();\n\n var formData = this.getFormData();\n // Send the form data to the server for processing.\n return Repository.submitCreateUpdateForm(formData)\n .then(function(response) {\n if (response.validationerror) {\n // If there was a server side validation error then\n // we need to re-request the rendered form from the server\n // in order to display the error for the user.\n this.reloadBodyContent(formData);\n return;\n } else {\n // Check whether this was a new event or not.\n // The hide function unsets the form data so grab this before the hide.\n var isExisting = this.hasEventId();\n\n // No problemo! Our work here is done.\n this.hide();\n\n // Trigger the appropriate calendar event so that the view can be updated.\n if (isExisting) {\n $('body').trigger(CalendarEvents.updated, [response.event]);\n } else {\n $('body').trigger(CalendarEvents.created, [response.event]);\n }\n }\n\n return;\n }.bind(this))\n .always(function() {\n // Regardless of success or error we should always stop\n // the loading icon and re-enable the buttons.\n loadingContainer.addClass('hidden');\n this.enableButtons();\n\n return;\n }.bind(this))\n .fail(Notification.exception);\n };\n\n /**\n * Set up all of the event handling for the modal.\n *\n * @method registerEventListeners\n * @fires event:uploadStarted\n * @fires event:formSubmittedByJavascript\n */\n ModalEventForm.prototype.registerEventListeners = function() {\n // Apply parent event listeners.\n Modal.prototype.registerEventListeners.call(this);\n\n // When the user clicks the save button we trigger the form submission. We need to\n // trigger an actual submission because there is some JS code in the form that is\n // listening for this event and doing some stuff (e.g. saving draft areas etc).\n this.getModal().on(CustomEvents.events.activate, SELECTORS.SAVE_BUTTON, function(e, data) {\n this.getForm().submit();\n data.originalEvent.preventDefault();\n e.stopPropagation();\n }.bind(this));\n\n // Catch the submit event before it is actually processed by the browser and\n // prevent the submission. We'll take it from here.\n this.getModal().on('submit', function(e) {\n FormEvents.notifyFormSubmittedByJavascript(this.getForm()[0]);\n\n this.save();\n\n // Stop the form from actually submitting and prevent it's\n // propagation because we have already handled the event.\n e.preventDefault();\n e.stopPropagation();\n }.bind(this));\n };\n\n // Automatically register with the modal registry the first time this module is imported so that you can create modals\n // of this type using the modal factory.\n if (!registered) {\n ModalRegistry.register(ModalEventForm.TYPE, ModalEventForm, 'calendar/modal_event_form');\n registered = true;\n }\n\n return ModalEventForm;\n});\n"],"file":"modal_event_form.min.js"}
\ No newline at end of file
diff --git a/calendar/amd/src/modal_event_form.js b/calendar/amd/src/modal_event_form.js
index be7f718e17e..5f3f5f7f009 100644
--- a/calendar/amd/src/modal_event_form.js
+++ b/calendar/amd/src/modal_event_form.js
@@ -23,32 +23,31 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define([
- 'jquery',
- 'core/event',
- 'core/str',
- 'core/notification',
- 'core/templates',
- 'core/custom_interaction_events',
- 'core/modal',
- 'core/modal_registry',
- 'core/fragment',
- 'core_calendar/events',
- 'core_calendar/repository'
- ],
- function(
- $,
- Event,
- Str,
- Notification,
- Templates,
- CustomEvents,
- Modal,
- ModalRegistry,
- Fragment,
- CalendarEvents,
- Repository
- ) {
-
+ 'jquery',
+ 'core_form/events',
+ 'core/str',
+ 'core/notification',
+ 'core/templates',
+ 'core/custom_interaction_events',
+ 'core/modal',
+ 'core/modal_registry',
+ 'core/fragment',
+ 'core_calendar/events',
+ 'core_calendar/repository'
+],
+function(
+ $,
+ FormEvents,
+ Str,
+ Notification,
+ Templates,
+ CustomEvents,
+ Modal,
+ ModalRegistry,
+ Fragment,
+ CalendarEvents,
+ Repository
+) {
var registered = false;
var SELECTORS = {
SAVE_BUTTON: '[data-action="save"]',
@@ -416,7 +415,7 @@ define([
// If we found invalid fields, focus on the first one and do not submit via ajax.
if (invalid.length) {
invalid.first().focus();
- return;
+ return Promise.resolve();
}
loadingContainer.removeClass('hidden');
@@ -465,6 +464,8 @@ define([
* Set up all of the event handling for the modal.
*
* @method registerEventListeners
+ * @fires event:uploadStarted
+ * @fires event:formSubmittedByJavascript
*/
ModalEventForm.prototype.registerEventListeners = function() {
// Apply parent event listeners.
@@ -482,7 +483,7 @@ define([
// Catch the submit event before it is actually processed by the browser and
// prevent the submission. We'll take it from here.
this.getModal().on('submit', function(e) {
- Event.notifyFormSubmitAjax(this.getForm()[0]);
+ FormEvents.notifyFormSubmittedByJavascript(this.getForm()[0]);
this.save();
diff --git a/course/dndupload.js b/course/dndupload.js
index 918417cb0f8..da539559bcd 100644
--- a/course/dndupload.js
+++ b/course/dndupload.js
@@ -765,7 +765,7 @@ M.course_dndupload = {
this.originalUnloadEvent = window.onbeforeunload;
// Trigger form upload start events.
require(['core_form/events'], function(FormEvent) {
- FormEvent.triggerUploadStarted(section.get('id'));
+ FormEvent.notifyUploadStarted(section.get('id'));
});
}
if (xhr.readyState == 4) {
@@ -796,7 +796,7 @@ M.course_dndupload = {
}
// Trigger form upload complete events.
require(['core_form/events'], function(FormEvent) {
- FormEvent.triggerUploadCompleted(section.get('id'));
+ FormEvent.notifyUploadCompleted(section.get('id'));
});
}
};
@@ -1031,7 +1031,7 @@ M.course_dndupload = {
this.originalUnloadEvent = window.onbeforeunload;
// Trigger form upload start events.
require(['core_form/events'], function(FormEvent) {
- FormEvent.triggerUploadStarted(section.get('id'));
+ FormEvent.notifyUploadStarted(section.get('id'));
});
}
if (xhr.readyState == 4) {
@@ -1052,7 +1052,7 @@ M.course_dndupload = {
resel.parent.removeChild(resel.li);
// Trigger form upload complete events.
require(['core_form/events'], function(FormEvent) {
- FormEvent.triggerUploadCompleted(section.get('id'));
+ FormEvent.notifyUploadCompleted(section.get('id'));
});
new M.core.alert({message: result.error});
}
@@ -1060,13 +1060,13 @@ M.course_dndupload = {
} else {
// Trigger form upload complete events.
require(['core_form/events'], function(FormEvent) {
- FormEvent.triggerUploadCompleted(section.get('id'));
+ FormEvent.notifyUploadCompleted(section.get('id'));
});
new M.core.alert({message: M.util.get_string('servererror', 'moodle')});
}
// Trigger form upload complete events.
require(['core_form/events'], function(FormEvent) {
- FormEvent.triggerUploadCompleted(section.get('id'));
+ FormEvent.notifyUploadCompleted(section.get('id'));
});
}
};
diff --git a/filter/amd/build/events.min.js b/filter/amd/build/events.min.js
new file mode 100644
index 00000000000..644ee2f094a
--- /dev/null
+++ b/filter/amd/build/events.min.js
@@ -0,0 +1,2 @@
+define ("core_filters/events",["exports","core/event_dispatcher","core/normalise","jquery"],function(a,b,c,d){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.notifyFilterContentUpdated=a.eventTypes=void 0;d=function(a){return a&&a.__esModule?a:{default:a}}(d);var e={filterContentUpdated:"core_filters/contentUpdated"};a.eventTypes=e;a.notifyFilterContentUpdated=function notifyFilterContentUpdated(a){a=(0,c.getList)(a);return(0,b.dispatchEvent)(e.filterContentUpdated,{nodes:a})};var f=!1;if(!f){Y.use("event","moodle-core-event",function(){document.addEventListener(e.filterContentUpdated,function(a){(0,d.default)(document).trigger(M.core.event.FILTER_CONTENT_UPDATED,[(0,d.default)(a.detail.nodes)]);Y.fire(M.core.event.FILTER_CONTENT_UPDATED,{nodes:new Y.NodeList(a.detail.nodes)})})});f=!0}});
+//# sourceMappingURL=events.min.js.map
diff --git a/filter/amd/build/events.min.js.map b/filter/amd/build/events.min.js.map
new file mode 100644
index 00000000000..f7d5accbc2b
--- /dev/null
+++ b/filter/amd/build/events.min.js.map
@@ -0,0 +1 @@
+{"version":3,"sources":["../src/events.js"],"names":["eventTypes","filterContentUpdated","notifyFilterContentUpdated","nodes","legacyEventsRegistered","Y","use","document","addEventListener","e","trigger","M","core","event","FILTER_CONTENT_UPDATED","detail","fire","NodeList"],"mappings":"6NAyBA,uDAQO,GAAMA,CAAAA,CAAU,CAAG,CAWtBC,oBAAoB,CAAE,6BAXA,CAAnB,C,4CAsBmC,QAA7BC,CAAAA,0BAA6B,CAAAC,CAAK,CAAI,CAG/CA,CAAK,CAAG,cAAkBA,CAAlB,CAAR,CAEA,MAAO,oBAAcH,CAAU,CAACC,oBAAzB,CAA+C,CAACE,KAAK,CAALA,CAAD,CAA/C,CACV,C,CAED,GAAIC,CAAAA,CAAsB,GAA1B,CACA,GAAI,CAACA,CAAL,CAA6B,CAKzBC,CAAC,CAACC,GAAF,CAAM,OAAN,CAAe,mBAAf,CAAoC,UAAM,CAEtCC,QAAQ,CAACC,gBAAT,CAA0BR,CAAU,CAACC,oBAArC,CAA2D,SAAAQ,CAAC,CAAI,CAE5D,cAAOF,QAAP,EAAiBG,OAAjB,CAAyBC,CAAC,CAACC,IAAF,CAAOC,KAAP,CAAaC,sBAAtC,CAA8D,CAAC,cAAOL,CAAC,CAACM,MAAF,CAASZ,KAAhB,CAAD,CAA9D,EAGAE,CAAC,CAACW,IAAF,CAAOL,CAAC,CAACC,IAAF,CAAOC,KAAP,CAAaC,sBAApB,CAA4C,CAACX,KAAK,CAAE,GAAIE,CAAAA,CAAC,CAACY,QAAN,CAAeR,CAAC,CAACM,MAAF,CAASZ,KAAxB,CAAR,CAA5C,CACH,CAND,CAOH,CATD,EAWAC,CAAsB,GACzB,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/ //\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 * Javascript events for the `core_filter` subsystem.\n *\n * @module core_filters/events\n * @copyright 2021 Andrew Nicols \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 4.0\n */\n\nimport {dispatchEvent} from 'core/event_dispatcher';\nimport {getList as normalistNodeList} from 'core/normalise';\nimport jQuery from 'jquery';\n\n/**\n * Events for the `core_filter` subsystem.\n *\n * @constant\n * @property {String} filterContentUpdated See {@link event:filterContentUpdated}\n */\nexport const eventTypes = {\n /**\n * An event triggered when page content is updated and must be processed by the filter system.\n *\n * An example of this is loading user text that could have equations in it. MathJax can typeset the equations but\n * only if it is notified that there are new nodes in the page that need processing.\n *\n * @event filterContentUpdated\n * @type {CustomEvent}\n * @property {Array} nodes The list of parent nodes which were updated\n */\n filterContentUpdated: 'core_filters/contentUpdated',\n};\n\n/**\n * Trigger an event to indicate that the specified nodes were updated and should be processed by the filter system.\n *\n * @method notifyFilterContentUpdated\n * @param {jQuery|Array} nodes\n * @returns {CustomEvent}\n * @fires filterContentUpdated\n */\nexport const notifyFilterContentUpdated = nodes => {\n // Historically this could be a jQuery Object.\n // Normalise the list of nodes to a NodeList.\n nodes = normalistNodeList(nodes);\n\n return dispatchEvent(eventTypes.filterContentUpdated, {nodes});\n};\n\nlet legacyEventsRegistered = false;\nif (!legacyEventsRegistered) {\n // The following event triggers are legacy and will be removed in the future.\n // The following approach provides a backwards-compatability layer for the new events.\n // Code should be updated to make use of native events.\n\n Y.use('event', 'moodle-core-event', () => {\n // Provide a backwards-compatability layer for YUI Events.\n document.addEventListener(eventTypes.filterContentUpdated, e => {\n // Trigger the legacy jQuery event.\n jQuery(document).trigger(M.core.event.FILTER_CONTENT_UPDATED, [jQuery(e.detail.nodes)]);\n\n // Trigger the legacy YUI event.\n Y.fire(M.core.event.FILTER_CONTENT_UPDATED, {nodes: new Y.NodeList(e.detail.nodes)});\n });\n });\n\n legacyEventsRegistered = true;\n}\n"],"file":"events.min.js"}
\ No newline at end of file
diff --git a/filter/amd/src/events.js b/filter/amd/src/events.js
new file mode 100644
index 00000000000..1220f94a866
--- /dev/null
+++ b/filter/amd/src/events.js
@@ -0,0 +1,82 @@
+// This file is part of Moodle - http://moodle.org/ //
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see .
+
+/**
+ * Javascript events for the `core_filter` subsystem.
+ *
+ * @module core_filters/events
+ * @copyright 2021 Andrew Nicols
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since 4.0
+ */
+
+import {dispatchEvent} from 'core/event_dispatcher';
+import {getList as normalistNodeList} from 'core/normalise';
+import jQuery from 'jquery';
+
+/**
+ * Events for the `core_filter` subsystem.
+ *
+ * @constant
+ * @property {String} filterContentUpdated See {@link event:filterContentUpdated}
+ */
+export const eventTypes = {
+ /**
+ * An event triggered when page content is updated and must be processed by the filter system.
+ *
+ * An example of this is loading user text that could have equations in it. MathJax can typeset the equations but
+ * only if it is notified that there are new nodes in the page that need processing.
+ *
+ * @event filterContentUpdated
+ * @type {CustomEvent}
+ * @property {Array} nodes The list of parent nodes which were updated
+ */
+ filterContentUpdated: 'core_filters/contentUpdated',
+};
+
+/**
+ * Trigger an event to indicate that the specified nodes were updated and should be processed by the filter system.
+ *
+ * @method notifyFilterContentUpdated
+ * @param {jQuery|Array} nodes
+ * @returns {CustomEvent}
+ * @fires filterContentUpdated
+ */
+export const notifyFilterContentUpdated = nodes => {
+ // Historically this could be a jQuery Object.
+ // Normalise the list of nodes to a NodeList.
+ nodes = normalistNodeList(nodes);
+
+ return dispatchEvent(eventTypes.filterContentUpdated, {nodes});
+};
+
+let legacyEventsRegistered = false;
+if (!legacyEventsRegistered) {
+ // The following event triggers are legacy and will be removed in the future.
+ // The following approach provides a backwards-compatability layer for the new events.
+ // Code should be updated to make use of native events.
+
+ Y.use('event', 'moodle-core-event', () => {
+ // Provide a backwards-compatability layer for YUI Events.
+ document.addEventListener(eventTypes.filterContentUpdated, e => {
+ // Trigger the legacy jQuery event.
+ jQuery(document).trigger(M.core.event.FILTER_CONTENT_UPDATED, [jQuery(e.detail.nodes)]);
+
+ // Trigger the legacy YUI event.
+ Y.fire(M.core.event.FILTER_CONTENT_UPDATED, {nodes: new Y.NodeList(e.detail.nodes)});
+ });
+ });
+
+ legacyEventsRegistered = true;
+}
diff --git a/lib/amd/build/event.min.js b/lib/amd/build/event.min.js
index 3541d3199fb..1d56d250c5e 100644
--- a/lib/amd/build/event.min.js
+++ b/lib/amd/build/event.min.js
@@ -1,2 +1,2 @@
-define ("core/event",["jquery","core/yui"],function(a,b){return{Events:{FORM_FIELD_VALIDATION:"core_form-field-validation"},getLegacyEvents:function getLegacyEvents(){var c=a.Deferred();b.use("event","moodle-core-event",function(){c.resolve(window.M.core.event)});return c.promise()},notifyFilterContentUpdated:function notifyFilterContentUpdated(c){c=a(c);b.use("event","moodle-core-event",function(b){a(document).trigger(M.core.event.FILTER_CONTENT_UPDATED,[c]);var d=new b.NodeList(c.get());b.fire(M.core.event.FILTER_CONTENT_UPDATED,{nodes:d})})},notifyFormSubmitAjax:function notifyFormSubmitAjax(c,d){d=d||!1;b.use("event","moodle-core-event",function(b){if(d){window.skipClientValidation=!0}a(c).trigger(M.core.event.FORM_SUBMIT_AJAX);b.one(c).fire(M.core.event.FORM_SUBMIT_AJAX,{currentTarget:b.one(c)});if(d){window.skipClientValidation=!1}})},notifyEditorContentRestored:function notifyEditorContentRestored(){b.use("event","moodle-core-event",function(b){a(document).trigger(M.core.event.EDITOR_CONTENT_RESTORED);b.fire(M.core.event.EDITOR_CONTENT_RESTORED)})}}});
+define ("core/event",["exports","core_editor/events","core_filters/events","core_form/events","jquery","core/yui"],function(a,b,c,d,e,f){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;e=g(e);f=g(f);function g(a){return a&&a.__esModule?a:{default:a}}var h=function(){var a=e.default.Deferred();window.console.warn("The getLegacyEvents function has been deprecated. Please update your code to use native events.");f.default.use("event","moodle-core-event",function(){a.resolve(window.M.core.event)});return a.promise()},i=function(a,b,c,d){return function(){window.console.warn("The core/event::".concat(a,"() function has been moved to ").concat(b,"::").concat(c,". ")+"Please update your code to use the new module.");return d.apply(void 0,arguments)}},j={Events:{FORM_FIELD_VALIDATION:"core_form-field-validation"},getLegacyEvents:h,notifyEditorContentRestored:i("notifyEditorContentRestored","core_editor/events","notifyEditorContentRestored",b.notifyEditorContentRestored),notifyFilterContentUpdated:i("notifyFilterContentUpdated","core_filters/events","notifyFilterContentUpdated",c.notifyFilterContentUpdated),notifyFormSubmitAjax:i("notifyFormSubmitAjax","core_form/events","notifyFormSubmittedByJavascript",d.notifyFormSubmittedByJavascript)};a.default=j;return a.default});
//# sourceMappingURL=event.min.js.map
diff --git a/lib/amd/build/event.min.js.map b/lib/amd/build/event.min.js.map
index 38e1a2d518d..ed46fc9d436 100644
--- a/lib/amd/build/event.min.js.map
+++ b/lib/amd/build/event.min.js.map
@@ -1 +1 @@
-{"version":3,"sources":["../src/event.js"],"names":["define","$","Y","Events","FORM_FIELD_VALIDATION","getLegacyEvents","result","Deferred","use","resolve","window","M","core","event","promise","notifyFilterContentUpdated","nodes","document","trigger","FILTER_CONTENT_UPDATED","yuiNodes","NodeList","get","fire","notifyFormSubmitAjax","form","skipValidation","skipClientValidation","FORM_SUBMIT_AJAX","one","currentTarget","notifyEditorContentRestored","EDITOR_CONTENT_RESTORED"],"mappings":"AAyBAA,OAAM,cAAC,CAAC,QAAD,CAAW,UAAX,CAAD,CACC,SAASC,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AAOC,KAAP,CAAae,gBAA7B,EAGA1B,CAAC,CAAC2B,GAAF,CAAMJ,CAAN,EAAYF,IAAZ,CAAiBZ,CAAC,CAACC,IAAF,CAAOC,KAAP,CAAae,gBAA9B,CAAgD,CAACE,aAAa,CAAE5B,CAAC,CAAC2B,GAAF,CAAMJ,CAAN,CAAhB,CAAhD,EAEA,GAAIC,CAAJ,CAAoB,CAChBhB,MAAM,CAACiB,oBAAP,GACH,CACJ,CAbD,CAcH,CArEkC,CA6EnCI,2BAA2B,CAAE,sCAAW,CACpC7B,CAAC,CAACM,GAAF,CAAM,OAAN,CAAe,mBAAf,CAAoC,SAASN,CAAT,CAAY,CAE5CD,CAAC,CAACgB,QAAD,CAAD,CAAYC,OAAZ,CAAoBP,CAAC,CAACC,IAAF,CAAOC,KAAP,CAAamB,uBAAjC,EAGA9B,CAAC,CAACqB,IAAF,CAAOZ,CAAC,CAACC,IAAF,CAAOC,KAAP,CAAamB,uBAApB,CACH,CAND,CAOH,CArFkC,CAuF1C,CA1FK,CAAN","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 * Global registry of core events that can be triggered/listened for.\n *\n * @module core/event\n * @package core\n * @class event\n * @copyright 2015 Damyon Wiese \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 3.0\n */\ndefine(['jquery', 'core/yui'],\n function($, Y) {\n\n return /** @alias module:core/event */ {\n\n\n // Public variables and functions.\n // These are AMD only events - no backwards compatibility for new things.\n Events: {\n FORM_FIELD_VALIDATION: \"core_form-field-validation\"\n },\n\n /**\n * Load the legacy YUI module which defines events in M.core.event and return it.\n *\n * @method getLegacyEvents\n * @return {Promise}\n */\n getLegacyEvents: function() {\n var result = $.Deferred();\n Y.use('event', 'moodle-core-event', function() {\n result.resolve(window.M.core.event);\n });\n return result.promise();\n },\n\n /**\n * Trigger an event using both JQuery and YUI\n *\n * @method notifyFilterContentUpdated\n * @param {string|JQuery} nodes - Selector or list of elements that were inserted.\n */\n notifyFilterContentUpdated: function(nodes) {\n nodes = $(nodes);\n Y.use('event', 'moodle-core-event', function(Y) {\n // Trigger it the JQuery way.\n $(document).trigger(M.core.event.FILTER_CONTENT_UPDATED, [nodes]);\n\n // Create a YUI NodeList from our JQuery Object.\n var yuiNodes = new Y.NodeList(nodes.get());\n\n // And again for YUI.\n Y.fire(M.core.event.FILTER_CONTENT_UPDATED, {nodes: yuiNodes});\n });\n },\n\n /**\n * Trigger an event using both JQuery and YUI\n *\n * @method notifyFormSubmittedAjax\n * @param {DOMElement} form\n * @param {boolean} skipValidation Submit the form without validation. E.g. \"Cancel\".\n */\n notifyFormSubmitAjax: function(form, skipValidation) {\n\n // Argument is optional.\n skipValidation = skipValidation || false;\n\n Y.use('event', 'moodle-core-event', function(Y) {\n if (skipValidation) {\n window.skipClientValidation = true;\n }\n // Trigger it the JQuery way.\n $(form).trigger(M.core.event.FORM_SUBMIT_AJAX);\n\n // And again for YUI.\n Y.one(form).fire(M.core.event.FORM_SUBMIT_AJAX, {currentTarget: Y.one(form)});\n\n if (skipValidation) {\n window.skipClientValidation = false;\n }\n });\n },\n\n /**\n * Trigger an event using both JQuery and YUI\n * This event alerts the world that the editor has restored some content.\n *\n * @method notifyEditorContentRestored\n */\n notifyEditorContentRestored: function() {\n Y.use('event', 'moodle-core-event', function(Y) {\n // Trigger it the JQuery way.\n $(document).trigger(M.core.event.EDITOR_CONTENT_RESTORED);\n\n // And again for YUI.\n Y.fire(M.core.event.EDITOR_CONTENT_RESTORED);\n });\n },\n };\n});\n"],"file":"event.min.js"}
\ No newline at end of file
+{"version":3,"sources":["../src/event.js"],"names":["getLegacyEvents","result","$","Deferred","window","console","warn","Y","use","resolve","M","core","event","promise","getRenamedLegacyFunction","oldFunctionName","newModule","newFunctionName","newFunctionRef","Events","FORM_FIELD_VALIDATION","notifyEditorContentRestored","notifyFilterContentUpdated","notifyFormSubmitAjax","notifyFormSubmittedByJavascript"],"mappings":"wNA6BA,OACA,O,sDAeMA,CAAAA,CAAe,CAAG,UAAM,CAC1B,GAAMC,CAAAA,CAAM,CAAGC,UAAEC,QAAF,EAAf,CACAC,MAAM,CAACC,OAAP,CAAeC,IAAf,CAAoB,iGAApB,EAEAC,UAAEC,GAAF,CAAM,OAAN,CAAe,mBAAf,CAAoC,UAAW,CAC3CP,CAAM,CAACQ,OAAP,CAAeL,MAAM,CAACM,CAAP,CAASC,IAAT,CAAcC,KAA7B,CACH,CAFD,EAGA,MAAOX,CAAAA,CAAM,CAACY,OAAP,EACV,C,CAWKC,CAAwB,CAAG,SAACC,CAAD,CAAkBC,CAAlB,CAA6BC,CAA7B,CAA8CC,CAA9C,QAAiE,WAAa,CAC3Gd,MAAM,CAACC,OAAP,CAAeC,IAAf,CACI,0BAAmBS,CAAnB,0CAAmEC,CAAnE,cAAiFC,CAAjF,uDADJ,EAKA,MAAOC,CAAAA,CAAc,MAAd,kBACV,CAPgC,C,GASlB,CACXC,MAAM,CAxCK,CACXC,qBAAqB,CAAE,4BADZ,CAuCA,CAEXpB,eAAe,CAAfA,CAFW,CAIXqB,2BAA2B,CAAEP,CAAwB,CACjD,6BADiD,CAEjD,oBAFiD,CAGjD,6BAHiD,CAIjDO,6BAJiD,CAJ1C,CAWXC,0BAA0B,CAAER,CAAwB,CAChD,4BADgD,CAEhD,qBAFgD,CAGhD,4BAHgD,CAIhDQ,4BAJgD,CAXzC,CAkBXC,oBAAoB,CAAET,CAAwB,CAC1C,sBAD0C,CAE1C,kBAF0C,CAG1C,iCAH0C,CAI1CU,iCAJ0C,CAlBnC,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 * Global registry of core events that can be triggered/listened for.\n *\n * @module core/event\n * @copyright 2015 Damyon Wiese \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 3.0\n */\n\nimport {notifyEditorContentRestored} from 'core_editor/events';\nimport {notifyFilterContentUpdated} from 'core_filters/events';\nimport {notifyFormSubmittedByJavascript} from 'core_form/events';\n\n// These are only imported for legacy.\nimport $ from 'jquery';\nimport Y from 'core/yui';\n\n// These are AMD only events - no backwards compatibility for new things.\n// Note: No new events should be created here.\nconst Events = {\n FORM_FIELD_VALIDATION: \"core_form-field-validation\"\n};\n\n/**\n * Load the legacy YUI module which defines events in M.core.event and return it.\n *\n * @method getLegacyEvents\n * @return {Promise}\n * @deprecated\n */\nconst getLegacyEvents = () => {\n const result = $.Deferred();\n window.console.warn(\"The getLegacyEvents function has been deprecated. Please update your code to use native events.\");\n\n Y.use('event', 'moodle-core-event', function() {\n result.resolve(window.M.core.event);\n });\n return result.promise();\n};\n\n/**\n * Get a curried function to warn that a function has been moved and renamed\n *\n * @param {String} oldFunctionName\n * @param {String} newModule\n * @param {String} newFunctionName\n * @param {Function} newFunctionRef\n * @returns {Function}\n */\nconst getRenamedLegacyFunction = (oldFunctionName, newModule, newFunctionName, newFunctionRef) => (...args) => {\n window.console.warn(\n `The core/event::${oldFunctionName}() function has been moved to ${newModule}::${newFunctionName}. ` +\n `Please update your code to use the new module.`\n );\n\n return newFunctionRef(...args);\n};\n\nexport default {\n Events,\n getLegacyEvents,\n\n notifyEditorContentRestored: getRenamedLegacyFunction(\n 'notifyEditorContentRestored',\n 'core_editor/events',\n 'notifyEditorContentRestored',\n notifyEditorContentRestored\n ),\n\n notifyFilterContentUpdated: getRenamedLegacyFunction(\n 'notifyFilterContentUpdated',\n 'core_filters/events',\n 'notifyFilterContentUpdated',\n notifyFilterContentUpdated\n ),\n\n notifyFormSubmitAjax: getRenamedLegacyFunction(\n 'notifyFormSubmitAjax',\n 'core_form/events',\n 'notifyFormSubmittedByJavascript',\n notifyFormSubmittedByJavascript\n ),\n};\n"],"file":"event.min.js"}
\ No newline at end of file
diff --git a/lib/amd/build/event_dispatcher.min.js b/lib/amd/build/event_dispatcher.min.js
new file mode 100644
index 00000000000..534d3bd3d3d
--- /dev/null
+++ b/lib/amd/build/event_dispatcher.min.js
@@ -0,0 +1,2 @@
+define ("core/event_dispatcher",["exports"],function(a){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.dispatchEvent=void 0;a.dispatchEvent=function dispatchEvent(a){var b=1.\n\n/**\n * Event dispatcher used to dispatch Native JS CustomEvent objects.\n *\n * @module core/event_dispatcher\n * @copyright 2021 Andrew Nicols \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 4.0\n */\n\n/**\n * Dispatch an event as a CustomEvent on the specified container.\n * By default events are bubbled, and cancelable.\n *\n * The eventName should typically by sourced using a constant, for example:\n *\n * // mod/example/amd/src/events.js\n *\n * import {dispatchEvent} from 'core/event_dispatcher';\n *\n * export const eventTypes = {\n * exampleDataDisplayed: 'mod_example/exampleDataDisplayed',\n * };\n *\n * export const notifyExampleDisplayed = someArgument => dispatchEvent(eventTypes.exampleDataDisplayed, {\n * someArgument,\n * }, document, {\n * cancelable: false,\n * });\n *\n * Note: This function uses native events. Any additional details are passed to the function in event.detail.\n *\n * This function mimics the behaviour of EventTarget.dispatchEvent but bubbles by default.\n *\n * @method dispatchEvent\n * @param {String} eventName The name of the event\n * @param {Object} detail Any additional details to pass into the eveent\n * @param {HTMLElement} container The point at which to dispatch the event\n * @param {Object} options\n * @param {Boolean} options.bubbles Whether to bubble up the DOM\n * @param {Boolean} options.cancelable Whether preventDefault() can be called\n * @param {Boolean} options.composed Whether the event can bubble across the ShadowDOM bounadry\n * @returns {CustomEvent}\n */\nexport const dispatchEvent = (\n eventName,\n detail = {},\n container = document,\n {\n bubbles = true,\n cancelable = false,\n composed = false,\n } = {}\n) => {\n const customEvent = new CustomEvent(\n eventName,\n {\n bubbles,\n cancelable,\n composed,\n detail,\n }\n );\n\n container.dispatchEvent(customEvent);\n\n return customEvent;\n};\n"],"file":"event_dispatcher.min.js"}
\ No newline at end of file
diff --git a/lib/amd/build/modal.min.js b/lib/amd/build/modal.min.js
index 1a7b16798e5..b5ad493b8d8 100644
--- a/lib/amd/build/modal.min.js
+++ b/lib/amd/build/modal.min.js
@@ -1,2 +1,2 @@
-function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core/modal",["jquery","core/templates","core/notification","core/key_codes","core/custom_interaction_events","core/modal_backdrop","core/event","core/modal_events","core/local/aria/focuslock","core/pending","core/aria","core/fullscreen"],function(a,b,c,d,e,f,g,h,i,j,k,l){var m={CONTAINER:"[data-region=\"modal-container\"]",MODAL:"[data-region=\"modal\"]",HEADER:"[data-region=\"header\"]",TITLE:"[data-region=\"title\"]",BODY:"[data-region=\"body\"]",FOOTER:"[data-region=\"footer\"]",HIDE:"[data-action=\"hide\"]",DIALOG:"[role=dialog]",FORM:"form",MENU_BAR:"[role=menubar]",HAS_Z_INDEX:".moodle-has-zindex",CAN_RECEIVE_FOCUS:"input:not([type=\"hidden\"]), a[href], button, textarea, select, [tabindex]"},n={LOADING:"core/loading",BACKDROP:"core/modal_backdrop"},o,p=0,q=function(b){this.root=a(b);this.modal=this.root.find(m.MODAL);this.header=this.modal.find(m.HEADER);this.headerPromise=a.Deferred();this.title=this.header.find(m.TITLE);this.titlePromise=a.Deferred();this.body=this.modal.find(m.BODY);this.bodyPromise=a.Deferred();this.footer=this.modal.find(m.FOOTER);this.footerPromise=a.Deferred();this.hiddenSiblings=[];this.isAttached=!1;this.bodyJS=null;this.footerJS=null;this.modalCount=p++;this.attachmentPoint=document.createElement("div");document.body.append(this.attachmentPoint);if(!this.root.is(m.CONTAINER)){c.exception({message:"Element is not a modal container"})}if(!this.modal.length){c.exception({message:"Container does not contain a modal"})}if(!this.header.length){c.exception({message:"Modal is missing a header region"})}if(!this.title.length){c.exception({message:"Modal header is missing a title region"})}if(!this.body.length){c.exception({message:"Modal is missing a body region"})}if(!this.footer.length){c.exception({message:"Modal is missing a footer region"})}this.registerEventListeners()};q.prototype.attachToDOM=function(){this.getAttachmentPoint().append(this.root);if(this.isAttached){return}i.trapFocus(this.root[0]);if(this.bodyJS){b.runTemplateJS(this.bodyJS);this.bodyJS=null}if(this.footerJS){b.runTemplateJS(this.footerJS);this.footerJS=null}this.isAttached=!0};q.prototype.countOtherVisibleModals=function(){var b=0;a("body").find(m.CONTAINER).each(function(c,d){d=a(d);if(!this.root.is(d)&&d.hasClass("show")){b++}}.bind(this));return b};q.prototype.getBackdrop=function(){if(!o){o=b.render(n.BACKDROP,{}).then(function(b){var c=a(b);return new f(c)}).fail(c.exception)}return o};q.prototype.getRoot=function(){return this.root};q.prototype.getModal=function(){return this.modal};q.prototype.getTitle=function(){return this.title};q.prototype.getBody=function(){return this.body};q.prototype.getFooter=function(){return this.footer};q.prototype.getTitlePromise=function(){return this.titlePromise};q.prototype.getBodyPromise=function(){return this.bodyPromise};q.prototype.getFooterPromise=function(){return this.footerPromise};q.prototype.getModalCount=function(){return this.modalCount};q.prototype.setTitle=function(b){var d=this.getTitle();this.titlePromise=a.Deferred();this.asyncSet(b,d.html.bind(d)).then(function(){this.titlePromise.resolve(d)}.bind(this)).catch(c.exception)};q.prototype.setBody=function(d){this.bodyPromise=a.Deferred();var e=this.getBody();if("string"==typeof d){e.html(d);g.notifyFilterContentUpdated(e);this.getRoot().trigger(h.bodyRendered,this);this.bodyPromise.resolve(e)}else{var f="amd-modal-js-pending-id-"+this.getModalCount();M.util.js_pending(f);var i=null;e.css("overflow","hidden");d=a.when(d);if("pending"==d.state()){var j=e.innerHeight();if(100>j){j=100}e.animate({height:j+"px"},150);e.html("");i=b.render(n.LOADING,{}).then(function(b){var c=a(b).hide();e.html(c);c.fadeIn(150);return a.when(c.promise(),d)}).then(function(a){return a.fadeOut(100).promise()}).then(function(){return d})}else{i=d}i.then(function(a,c){var d=null;if(this.isVisible()){e.css("opacity",0);var f=e.innerHeight();e.html(a);e.css("height","");var g=e.innerHeight();e.css("height",f+"px");d=e.animate({height:g+"px",opacity:1},{duration:150,queue:!1}).promise()}else{e.html(a)}if(c){if(this.isAttached){b.runTemplateJS(c)}else{this.bodyJS=c}}return d}.bind(this)).then(function(a){g.notifyFilterContentUpdated(e);this.getRoot().trigger(h.bodyRendered,this);return a}.bind(this)).then(function(){this.bodyPromise.resolve(e)}.bind(this)).fail(c.exception).always(function(){e.css("height","");e.css("overflow","");e.css("opacity","");M.util.js_complete(f)}).fail(c.exception)}};q.prototype.setBodyContent=function(b){var c=this;return b.then(function(b){var d=b.html,e=b.js;return c.setBody(a.when(d,e))}).catch(function(a){c.hide();throw a})};q.prototype.setFooter=function(d){this.showFooter();this.footerPromise=a.Deferred();var e=this.getFooter();if("string"==typeof d){e.html(d);this.footerPromise.resolve(e)}else{b.render(n.LOADING,{}).then(function(a){e.html(a);return d}).then(function(a,c){e.html(a);if(c){if(this.isAttached){b.runTemplateJS(c)}else{this.footerJS=c}}return e}.bind(this)).then(function(a){this.footerPromise.resolve(a)}.bind(this)).catch(c.exception)}};q.prototype.hasFooterContent=function(){return this.getFooter().children().length?!0:!1};q.prototype.hideFooter=function(){this.getFooter().addClass("hidden")};q.prototype.showFooter=function(){this.getFooter().removeClass("hidden")};q.prototype.setLarge=function(){if(this.isLarge()){return}this.getModal().addClass("modal-lg")};q.prototype.isLarge=function(){return this.getModal().hasClass("modal-lg")};q.prototype.setSmall=function(){if(this.isSmall()){return}this.getModal().removeClass("modal-lg")};q.prototype.isSmall=function(){return!this.getModal().hasClass("modal-lg")};q.prototype.setScrollable=function(a){if(!a){this.getModal()[0].classList.remove("modal-dialog-scrollable");return}this.getModal()[0].classList.add("modal-dialog-scrollable")};q.prototype.calculateZIndex=function(){var b=a(m.DIALOG+", "+m.MENU_BAR+", "+m.HAS_Z_INDEX),c=parseInt(this.root.css("z-index"));b.each(function(b,d){d=a(d);var e=d.css("z-index")?parseInt(d.css("z-index")):0;if(e>c){c=e}});return c};q.prototype.isVisible=function(){return this.root.hasClass("show")};q.prototype.hasFocus=function(){var b=a(document.activeElement);return this.root.is(b)||this.root.has(b).length};q.prototype.hasTransitions=function(){return this.getRoot().hasClass("fade")};q.prototype.getAttachmentPoint=function(){return a(l.getElement()||this.attachmentPoint)};q.prototype.show=function(){if(this.isVisible()){return a.Deferred().resolve()}var b=new j("core/modal:show");if(this.hasFooterContent()){this.showFooter()}else{this.hideFooter()}this.attachToDOM();return this.getBackdrop().then(function(b){var c=this.calculateZIndex(),d=c+2;this.root.css("z-index",d);b.setZIndex(d-1);b.show();this.root.removeClass("hide").addClass("show");this.accessibilityShow();this.getModal().focus();a("body").addClass("modal-open");this.root.trigger(h.shown,this)}.bind(this)).then(b.resolve)};q.prototype.hideIfNotForm=function(){var a=this.modal.find(m.FORM);if(0==a.length){this.hide()}};q.prototype.hide=function(){this.getBackdrop().done(function(b){i.untrapFocus();if(!this.countOtherVisibleModals()){b.hide();a("body").removeClass("modal-open")}var c=parseInt(this.root.css("z-index"));this.root.css("z-index","");b.setZIndex(c-3);this.accessibilityHide();if(this.hasTransitions()){this.getRoot().one("transitionend webkitTransitionEnd oTransitionEnd",function(){this.getRoot().removeClass("show").addClass("hide")}.bind(this))}else{this.getRoot().removeClass("show").addClass("hide")}if(a(document.body).find(this.getRoot()).length){a(document.body).append(this.getRoot())}this.root.trigger(h.hidden,this)}.bind(this))};q.prototype.destroy=function(){this.hide();this.root.remove();this.root.trigger(h.destroyed,this);this.attachmentPoint.remove()};q.prototype.accessibilityShow=function(){k.unhide(this.root.get());k.hideSiblings(this.root.get()[0])};q.prototype.accessibilityHide=function(){k.unhideSiblings(this.root.get()[0]);k.hide(this.root.get())};q.prototype.registerEventListeners=function(){this.getRoot().on("keydown",function(a){if(!this.isVisible()){return}if(a.keyCode==d.escape){if(this.removeOnClose){this.destroy()}else{this.hide()}}}.bind(this));this.getRoot().click(function(b){if(!a(b.target).closest(m.MODAL).length){if(a(b.target).closest(m.CONTAINER).length){var c=a.Event(h.outsideClick);this.getRoot().trigger(c,this);if(!c.isDefaultPrevented()){this.hideIfNotForm()}}}}.bind(this));e.define(this.getModal(),[e.events.activate]);this.getModal().on(e.events.activate,m.HIDE,function(a,b){this.hide();b.originalEvent.preventDefault()}.bind(this))};q.prototype.registerCloseOnCancel=function(){this.getModal().on(e.events.activate,this.getActionSelector("cancel"),function(b,c){var d=a.Event(h.cancel);this.getRoot().trigger(d,this);if(!d.isDefaultPrevented()){c.originalEvent.preventDefault();if(this.removeOnClose){this.destroy()}else{this.hide()}}}.bind(this))};q.prototype.registerCloseOnSave=function(){this.getModal().on(e.events.activate,this.getActionSelector("save"),function(b,c){var d=a.Event(h.save);this.getRoot().trigger(d,this);if(!d.isDefaultPrevented()){c.originalEvent.preventDefault();if(this.removeOnClose){this.destroy()}else{this.hide()}}}.bind(this))};q.prototype.asyncSet=function(b,d){var e=b;if("object"!==_typeof(b)||!b.hasOwnProperty("then")){e=a.Deferred();e.resolve(b)}e.then(function(a){d(a)}).fail(c.exception);return e};q.prototype.setButtonText=function(a,b){var c=this.getFooter().find(this.getActionSelector(a));if(!c){throw new Error("Unable to find the '"+a+"' button")}return this.asyncSet(b,c.text.bind(c))};q.prototype.getActionSelector=function(a){return"[data-action='"+a+"']"};q.prototype.setRemoveOnClose=function(a){this.removeOnClose=a};return q});
+function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core/modal",["jquery","core/templates","core/notification","core/key_codes","core/custom_interaction_events","core/modal_backdrop","core_filters/events","core/modal_events","core/local/aria/focuslock","core/pending","core/aria","core/fullscreen"],function(a,b,c,d,e,f,g,h,i,j,k,l){var m={CONTAINER:"[data-region=\"modal-container\"]",MODAL:"[data-region=\"modal\"]",HEADER:"[data-region=\"header\"]",TITLE:"[data-region=\"title\"]",BODY:"[data-region=\"body\"]",FOOTER:"[data-region=\"footer\"]",HIDE:"[data-action=\"hide\"]",DIALOG:"[role=dialog]",FORM:"form",MENU_BAR:"[role=menubar]",HAS_Z_INDEX:".moodle-has-zindex",CAN_RECEIVE_FOCUS:"input:not([type=\"hidden\"]), a[href], button, textarea, select, [tabindex]"},n={LOADING:"core/loading",BACKDROP:"core/modal_backdrop"},o,p=0,q=function(b){this.root=a(b);this.modal=this.root.find(m.MODAL);this.header=this.modal.find(m.HEADER);this.headerPromise=a.Deferred();this.title=this.header.find(m.TITLE);this.titlePromise=a.Deferred();this.body=this.modal.find(m.BODY);this.bodyPromise=a.Deferred();this.footer=this.modal.find(m.FOOTER);this.footerPromise=a.Deferred();this.hiddenSiblings=[];this.isAttached=!1;this.bodyJS=null;this.footerJS=null;this.modalCount=p++;this.attachmentPoint=document.createElement("div");document.body.append(this.attachmentPoint);if(!this.root.is(m.CONTAINER)){c.exception({message:"Element is not a modal container"})}if(!this.modal.length){c.exception({message:"Container does not contain a modal"})}if(!this.header.length){c.exception({message:"Modal is missing a header region"})}if(!this.title.length){c.exception({message:"Modal header is missing a title region"})}if(!this.body.length){c.exception({message:"Modal is missing a body region"})}if(!this.footer.length){c.exception({message:"Modal is missing a footer region"})}this.registerEventListeners()};q.prototype.attachToDOM=function(){this.getAttachmentPoint().append(this.root);if(this.isAttached){return}i.trapFocus(this.root[0]);if(this.bodyJS){b.runTemplateJS(this.bodyJS);this.bodyJS=null}if(this.footerJS){b.runTemplateJS(this.footerJS);this.footerJS=null}this.isAttached=!0};q.prototype.countOtherVisibleModals=function(){var b=0;a("body").find(m.CONTAINER).each(function(c,d){d=a(d);if(!this.root.is(d)&&d.hasClass("show")){b++}}.bind(this));return b};q.prototype.getBackdrop=function(){if(!o){o=b.render(n.BACKDROP,{}).then(function(b){var c=a(b);return new f(c)}).fail(c.exception)}return o};q.prototype.getRoot=function(){return this.root};q.prototype.getModal=function(){return this.modal};q.prototype.getTitle=function(){return this.title};q.prototype.getBody=function(){return this.body};q.prototype.getFooter=function(){return this.footer};q.prototype.getTitlePromise=function(){return this.titlePromise};q.prototype.getBodyPromise=function(){return this.bodyPromise};q.prototype.getFooterPromise=function(){return this.footerPromise};q.prototype.getModalCount=function(){return this.modalCount};q.prototype.setTitle=function(b){var d=this.getTitle();this.titlePromise=a.Deferred();this.asyncSet(b,d.html.bind(d)).then(function(){this.titlePromise.resolve(d)}.bind(this)).catch(c.exception)};q.prototype.setBody=function(d){this.bodyPromise=a.Deferred();var e=this.getBody();if("string"==typeof d){e.html(d);g.notifyFilterContentUpdated(e);this.getRoot().trigger(h.bodyRendered,this);this.bodyPromise.resolve(e)}else{var f="amd-modal-js-pending-id-"+this.getModalCount();M.util.js_pending(f);var i=null;e.css("overflow","hidden");d=a.when(d);if("pending"==d.state()){var j=e.innerHeight();if(100>j){j=100}e.animate({height:j+"px"},150);e.html("");i=b.render(n.LOADING,{}).then(function(b){var c=a(b).hide();e.html(c);c.fadeIn(150);return a.when(c.promise(),d)}).then(function(a){return a.fadeOut(100).promise()}).then(function(){return d})}else{i=d}i.then(function(a,c){var d=null;if(this.isVisible()){e.css("opacity",0);var f=e.innerHeight();e.html(a);e.css("height","");var g=e.innerHeight();e.css("height",f+"px");d=e.animate({height:g+"px",opacity:1},{duration:150,queue:!1}).promise()}else{e.html(a)}if(c){if(this.isAttached){b.runTemplateJS(c)}else{this.bodyJS=c}}return d}.bind(this)).then(function(a){g.notifyFilterContentUpdated(e);this.getRoot().trigger(h.bodyRendered,this);return a}.bind(this)).then(function(){this.bodyPromise.resolve(e)}.bind(this)).fail(c.exception).always(function(){e.css("height","");e.css("overflow","");e.css("opacity","");M.util.js_complete(f)}).fail(c.exception)}};q.prototype.setBodyContent=function(b){var c=this;return b.then(function(b){var d=b.html,e=b.js;return c.setBody(a.when(d,e))}).catch(function(a){c.hide();throw a})};q.prototype.setFooter=function(d){this.showFooter();this.footerPromise=a.Deferred();var e=this.getFooter();if("string"==typeof d){e.html(d);this.footerPromise.resolve(e)}else{b.render(n.LOADING,{}).then(function(a){e.html(a);return d}).then(function(a,c){e.html(a);if(c){if(this.isAttached){b.runTemplateJS(c)}else{this.footerJS=c}}return e}.bind(this)).then(function(a){this.footerPromise.resolve(a)}.bind(this)).catch(c.exception)}};q.prototype.hasFooterContent=function(){return this.getFooter().children().length?!0:!1};q.prototype.hideFooter=function(){this.getFooter().addClass("hidden")};q.prototype.showFooter=function(){this.getFooter().removeClass("hidden")};q.prototype.setLarge=function(){if(this.isLarge()){return}this.getModal().addClass("modal-lg")};q.prototype.isLarge=function(){return this.getModal().hasClass("modal-lg")};q.prototype.setSmall=function(){if(this.isSmall()){return}this.getModal().removeClass("modal-lg")};q.prototype.isSmall=function(){return!this.getModal().hasClass("modal-lg")};q.prototype.setScrollable=function(a){if(!a){this.getModal()[0].classList.remove("modal-dialog-scrollable");return}this.getModal()[0].classList.add("modal-dialog-scrollable")};q.prototype.calculateZIndex=function(){var b=a(m.DIALOG+", "+m.MENU_BAR+", "+m.HAS_Z_INDEX),c=parseInt(this.root.css("z-index"));b.each(function(b,d){d=a(d);var e=d.css("z-index")?parseInt(d.css("z-index")):0;if(e>c){c=e}});return c};q.prototype.isVisible=function(){return this.root.hasClass("show")};q.prototype.hasFocus=function(){var b=a(document.activeElement);return this.root.is(b)||this.root.has(b).length};q.prototype.hasTransitions=function(){return this.getRoot().hasClass("fade")};q.prototype.getAttachmentPoint=function(){return a(l.getElement()||this.attachmentPoint)};q.prototype.show=function(){if(this.isVisible()){return a.Deferred().resolve()}var b=new j("core/modal:show");if(this.hasFooterContent()){this.showFooter()}else{this.hideFooter()}this.attachToDOM();return this.getBackdrop().then(function(b){var c=this.calculateZIndex(),d=c+2;this.root.css("z-index",d);b.setZIndex(d-1);b.show();this.root.removeClass("hide").addClass("show");this.accessibilityShow();this.getModal().focus();a("body").addClass("modal-open");this.root.trigger(h.shown,this)}.bind(this)).then(b.resolve)};q.prototype.hideIfNotForm=function(){var a=this.modal.find(m.FORM);if(0==a.length){this.hide()}};q.prototype.hide=function(){this.getBackdrop().done(function(b){i.untrapFocus();if(!this.countOtherVisibleModals()){b.hide();a("body").removeClass("modal-open")}var c=parseInt(this.root.css("z-index"));this.root.css("z-index","");b.setZIndex(c-3);this.accessibilityHide();if(this.hasTransitions()){this.getRoot().one("transitionend webkitTransitionEnd oTransitionEnd",function(){this.getRoot().removeClass("show").addClass("hide")}.bind(this))}else{this.getRoot().removeClass("show").addClass("hide")}if(a(document.body).find(this.getRoot()).length){a(document.body).append(this.getRoot())}this.root.trigger(h.hidden,this)}.bind(this))};q.prototype.destroy=function(){this.hide();this.root.remove();this.root.trigger(h.destroyed,this);this.attachmentPoint.remove()};q.prototype.accessibilityShow=function(){k.unhide(this.root.get());k.hideSiblings(this.root.get()[0])};q.prototype.accessibilityHide=function(){k.unhideSiblings(this.root.get()[0]);k.hide(this.root.get())};q.prototype.registerEventListeners=function(){this.getRoot().on("keydown",function(a){if(!this.isVisible()){return}if(a.keyCode==d.escape){if(this.removeOnClose){this.destroy()}else{this.hide()}}}.bind(this));this.getRoot().click(function(b){if(!a(b.target).closest(m.MODAL).length){if(a(b.target).closest(m.CONTAINER).length){var c=a.Event(h.outsideClick);this.getRoot().trigger(c,this);if(!c.isDefaultPrevented()){this.hideIfNotForm()}}}}.bind(this));e.define(this.getModal(),[e.events.activate]);this.getModal().on(e.events.activate,m.HIDE,function(a,b){this.hide();b.originalEvent.preventDefault()}.bind(this))};q.prototype.registerCloseOnCancel=function(){this.getModal().on(e.events.activate,this.getActionSelector("cancel"),function(b,c){var d=a.Event(h.cancel);this.getRoot().trigger(d,this);if(!d.isDefaultPrevented()){c.originalEvent.preventDefault();if(this.removeOnClose){this.destroy()}else{this.hide()}}}.bind(this))};q.prototype.registerCloseOnSave=function(){this.getModal().on(e.events.activate,this.getActionSelector("save"),function(b,c){var d=a.Event(h.save);this.getRoot().trigger(d,this);if(!d.isDefaultPrevented()){c.originalEvent.preventDefault();if(this.removeOnClose){this.destroy()}else{this.hide()}}}.bind(this))};q.prototype.asyncSet=function(b,d){var e=b;if("object"!==_typeof(b)||!b.hasOwnProperty("then")){e=a.Deferred();e.resolve(b)}e.then(function(a){d(a)}).fail(c.exception);return e};q.prototype.setButtonText=function(a,b){var c=this.getFooter().find(this.getActionSelector(a));if(!c){throw new Error("Unable to find the '"+a+"' button")}return this.asyncSet(b,c.text.bind(c))};q.prototype.getActionSelector=function(a){return"[data-action='"+a+"']"};q.prototype.setRemoveOnClose=function(a){this.removeOnClose=a};return q});
//# sourceMappingURL=modal.min.js.map
diff --git a/lib/amd/build/modal.min.js.map b/lib/amd/build/modal.min.js.map
index 74341cf6b5d..4a057a23637 100644
--- a/lib/amd/build/modal.min.js.map
+++ b/lib/amd/build/modal.min.js.map
@@ -1 +1 @@
-{"version":3,"sources":["../src/modal.js"],"names":["define","$","Templates","Notification","KeyCodes","CustomEvents","ModalBackdrop","Event","ModalEvents","FocusLock","Pending","Aria","Fullscreen","SELECTORS","CONTAINER","MODAL","HEADER","TITLE","BODY","FOOTER","HIDE","DIALOG","FORM","MENU_BAR","HAS_Z_INDEX","CAN_RECEIVE_FOCUS","TEMPLATES","LOADING","BACKDROP","backdropPromise","modalCounter","Modal","root","modal","find","header","headerPromise","Deferred","title","titlePromise","body","bodyPromise","footer","footerPromise","hiddenSiblings","isAttached","bodyJS","footerJS","modalCount","attachmentPoint","document","createElement","append","is","exception","message","length","registerEventListeners","prototype","attachToDOM","getAttachmentPoint","trapFocus","runTemplateJS","countOtherVisibleModals","count","each","index","element","hasClass","bind","getBackdrop","render","then","html","fail","getRoot","getModal","getTitle","getBody","getFooter","getTitlePromise","getBodyPromise","getFooterPromise","getModalCount","setTitle","value","asyncSet","resolve","catch","setBody","notifyFilterContentUpdated","trigger","bodyRendered","jsPendingId","M","util","js_pending","contentPromise","css","when","state","height","innerHeight","animate","loadingIcon","hide","fadeIn","promise","fadeOut","js","result","isVisible","currentHeight","newHeight","opacity","duration","queue","always","js_complete","setBodyContent","setFooter","showFooter","hasFooterContent","children","hideFooter","addClass","removeClass","setLarge","isLarge","setSmall","isSmall","setScrollable","classList","remove","add","calculateZIndex","items","zIndex","parseInt","item","itemZIndex","hasFocus","target","activeElement","has","hasTransitions","getElement","show","pendingPromise","backdrop","currentIndex","newIndex","setZIndex","accessibilityShow","focus","shown","hideIfNotForm","formElement","done","untrapFocus","accessibilityHide","one","hidden","destroy","destroyed","unhide","get","hideSiblings","unhideSiblings","on","e","keyCode","escape","removeOnClose","click","closest","outsideClickEvent","outsideClick","isDefaultPrevented","events","activate","data","originalEvent","preventDefault","registerCloseOnCancel","getActionSelector","cancelEvent","cancel","registerCloseOnSave","saveEvent","save","setFunction","p","hasOwnProperty","content","setButtonText","action","button","Error","text","setRemoveOnClose"],"mappings":"mSAwBAA,OAAM,cAAC,CACH,QADG,CAEH,gBAFG,CAGH,mBAHG,CAIH,gBAJG,CAKH,gCALG,CAMH,qBANG,CAOH,YAPG,CAQH,mBARG,CASH,2BATG,CAUH,cAVG,CAWH,WAXG,CAYH,iBAZG,CAAD,CAaH,SACCC,CADD,CAECC,CAFD,CAGCC,CAHD,CAICC,CAJD,CAKCC,CALD,CAMCC,CAND,CAOCC,CAPD,CAQCC,CARD,CASCC,CATD,CAUCC,CAVD,CAWCC,CAXD,C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CAAqB,MAArB,CAAlC,CAAgE,CAC5DD,CAAC,CAAG/L,CAAC,CAACoC,QAAF,EAAJ,CACA2J,CAAC,CAACzG,OAAF,CAAUF,CAAV,CACH,CAED2G,CAAC,CAACxH,IAAF,CAAO,SAAS0H,CAAT,CAAkB,CACrBH,CAAW,CAACG,CAAD,CAGd,CAJD,EAKCxH,IALD,CAKMvE,CAAY,CAACmD,SALnB,EAOA,MAAO0I,CAAAA,CACV,CAfD,CA2BAjK,CAAK,CAAC2B,SAAN,CAAgByI,aAAhB,CAAgC,SAASC,CAAT,CAAiB/G,CAAjB,CAAwB,CACpD,GAAMgH,CAAAA,CAAM,CAAG,KAAKtH,SAAL,GAAiB7C,IAAjB,CAAsB,KAAKuJ,iBAAL,CAAuBW,CAAvB,CAAtB,CAAf,CAEA,GAAI,CAACC,CAAL,CAAa,CACT,KAAM,IAAIC,CAAAA,KAAJ,CAAU,uBAAyBF,CAAzB,CAAkC,UAA5C,CACT,CAED,MAAO,MAAK9G,QAAL,CAAcD,CAAd,CAAqBgH,CAAM,CAACE,IAAP,CAAYlI,IAAZ,CAAiBgI,CAAjB,CAArB,CACV,CARD,CAgBAtK,CAAK,CAAC2B,SAAN,CAAgB+H,iBAAhB,CAAoC,SAASW,CAAT,CAAiB,CACjD,MAAO,iBAAmBA,CAAnB,CAA4B,IACtC,CAFD,CASArK,CAAK,CAAC2B,SAAN,CAAgB8I,gBAAhB,CAAmC,SAASnE,CAAT,CAAiB,CAChD,KAAKwC,aAAL,CAAqBxC,CACxB,CAFD,CAIA,MAAOtG,CAAAA,CACV,CA76BK,CAAN","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 modals.\n *\n * @module core/modal\n * @class modal\n * @package core\n * @copyright 2016 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([\n 'jquery',\n 'core/templates',\n 'core/notification',\n 'core/key_codes',\n 'core/custom_interaction_events',\n 'core/modal_backdrop',\n 'core/event',\n 'core/modal_events',\n 'core/local/aria/focuslock',\n 'core/pending',\n 'core/aria',\n 'core/fullscreen'\n], function(\n $,\n Templates,\n Notification,\n KeyCodes,\n CustomEvents,\n ModalBackdrop,\n Event,\n ModalEvents,\n FocusLock,\n Pending,\n Aria,\n Fullscreen\n) {\n\n var SELECTORS = {\n CONTAINER: '[data-region=\"modal-container\"]',\n MODAL: '[data-region=\"modal\"]',\n HEADER: '[data-region=\"header\"]',\n TITLE: '[data-region=\"title\"]',\n BODY: '[data-region=\"body\"]',\n FOOTER: '[data-region=\"footer\"]',\n HIDE: '[data-action=\"hide\"]',\n DIALOG: '[role=dialog]',\n FORM: 'form',\n MENU_BAR: '[role=menubar]',\n HAS_Z_INDEX: '.moodle-has-zindex',\n CAN_RECEIVE_FOCUS: 'input:not([type=\"hidden\"]), a[href], button, textarea, select, [tabindex]',\n };\n\n var TEMPLATES = {\n LOADING: 'core/loading',\n BACKDROP: 'core/modal_backdrop',\n };\n\n /**\n * Module singleton for the backdrop to be reused by all Modal instances.\n */\n var backdropPromise;\n\n /**\n * A counter that gets incremented for each modal created. This can be\n * used to generate unique values for the modals.\n */\n var modalCounter = 0;\n\n /**\n * Constructor for the Modal.\n *\n * @param {object} root The root jQuery element for the modal\n */\n var Modal = function(root) {\n this.root = $(root);\n this.modal = this.root.find(SELECTORS.MODAL);\n this.header = this.modal.find(SELECTORS.HEADER);\n this.headerPromise = $.Deferred();\n this.title = this.header.find(SELECTORS.TITLE);\n this.titlePromise = $.Deferred();\n this.body = this.modal.find(SELECTORS.BODY);\n this.bodyPromise = $.Deferred();\n this.footer = this.modal.find(SELECTORS.FOOTER);\n this.footerPromise = $.Deferred();\n this.hiddenSiblings = [];\n this.isAttached = false;\n this.bodyJS = null;\n this.footerJS = null;\n this.modalCount = modalCounter++;\n this.attachmentPoint = document.createElement('div');\n document.body.append(this.attachmentPoint);\n\n if (!this.root.is(SELECTORS.CONTAINER)) {\n Notification.exception({message: 'Element is not a modal container'});\n }\n\n if (!this.modal.length) {\n Notification.exception({message: 'Container does not contain a modal'});\n }\n\n if (!this.header.length) {\n Notification.exception({message: 'Modal is missing a header region'});\n }\n\n if (!this.title.length) {\n Notification.exception({message: 'Modal header is missing a title region'});\n }\n\n if (!this.body.length) {\n Notification.exception({message: 'Modal is missing a body region'});\n }\n\n if (!this.footer.length) {\n Notification.exception({message: 'Modal is missing a footer region'});\n }\n\n this.registerEventListeners();\n };\n\n /**\n * Attach the modal to the correct part of the page.\n *\n * If it hasn't already been added it runs any\n * javascript that has been cached until now.\n *\n * @method attachToDOM\n */\n Modal.prototype.attachToDOM = function() {\n this.getAttachmentPoint().append(this.root);\n\n if (this.isAttached) {\n return;\n }\n\n FocusLock.trapFocus(this.root[0]);\n\n // If we'd cached any JS then we can run it how that the modal is\n // attached to the DOM.\n if (this.bodyJS) {\n Templates.runTemplateJS(this.bodyJS);\n this.bodyJS = null;\n }\n\n if (this.footerJS) {\n Templates.runTemplateJS(this.footerJS);\n this.footerJS = null;\n }\n\n this.isAttached = true;\n };\n\n /**\n * Count the number of other visible modals (not including this one).\n *\n * @method countOtherVisibleModals\n * @return {int}\n */\n Modal.prototype.countOtherVisibleModals = function() {\n var count = 0;\n $('body').find(SELECTORS.CONTAINER).each(function(index, element) {\n element = $(element);\n\n // If we haven't found ourself and the element is visible.\n if (!this.root.is(element) && element.hasClass('show')) {\n count++;\n }\n }.bind(this));\n\n return count;\n };\n\n /**\n * Get the modal backdrop.\n *\n * @method getBackdrop\n * @return {object} jQuery promise\n */\n Modal.prototype.getBackdrop = function() {\n if (!backdropPromise) {\n backdropPromise = Templates.render(TEMPLATES.BACKDROP, {})\n .then(function(html) {\n var element = $(html);\n\n return new ModalBackdrop(element);\n })\n .fail(Notification.exception);\n }\n\n return backdropPromise;\n };\n\n /**\n * Get the root element of this modal.\n *\n * @method getRoot\n * @return {object} jQuery object\n */\n Modal.prototype.getRoot = function() {\n return this.root;\n };\n\n /**\n * Get the modal element of this modal.\n *\n * @method getModal\n * @return {object} jQuery object\n */\n Modal.prototype.getModal = function() {\n return this.modal;\n };\n\n /**\n * Get the modal title element.\n *\n * @method getTitle\n * @return {object} jQuery object\n */\n Modal.prototype.getTitle = function() {\n return this.title;\n };\n\n /**\n * Get the modal body element.\n *\n * @method getBody\n * @return {object} jQuery object\n */\n Modal.prototype.getBody = function() {\n return this.body;\n };\n\n /**\n * Get the modal footer element.\n *\n * @method getFooter\n * @return {object} jQuery object\n */\n Modal.prototype.getFooter = function() {\n return this.footer;\n };\n\n /**\n * Get a promise resolving to the title region.\n *\n * @method getTitlePromise\n * @return {Promise}\n */\n Modal.prototype.getTitlePromise = function() {\n return this.titlePromise;\n };\n\n /**\n * Get a promise resolving to the body region.\n *\n * @method getBodyPromise\n * @return {object} jQuery object\n */\n Modal.prototype.getBodyPromise = function() {\n return this.bodyPromise;\n };\n\n /**\n * Get a promise resolving to the footer region.\n *\n * @method getFooterPromise\n * @return {object} jQuery object\n */\n Modal.prototype.getFooterPromise = function() {\n return this.footerPromise;\n };\n\n /**\n * Get the unique modal count.\n *\n * @method getModalCount\n * @return {int}\n */\n Modal.prototype.getModalCount = function() {\n return this.modalCount;\n };\n\n /**\n * Set the modal title element.\n *\n * This method is overloaded to take either a string value for the title or a jQuery promise that is resolved with\n * HTML most commonly from a Str.get_string call.\n *\n * @method setTitle\n * @param {(string|object)} value The title string or jQuery promise which resolves to the title.\n */\n Modal.prototype.setTitle = function(value) {\n var title = this.getTitle();\n this.titlePromise = $.Deferred();\n\n this.asyncSet(value, title.html.bind(title))\n .then(function() {\n this.titlePromise.resolve(title);\n }.bind(this))\n .catch(Notification.exception);\n };\n\n /**\n * Set the modal body element.\n *\n * This method is overloaded to take either a string value for the body or a jQuery promise that is resolved with\n * HTML and Javascript most commonly from a Templates.render call.\n *\n * @method setBody\n * @param {(string|object)} value The body string or jQuery promise which resolves to the body.\n */\n Modal.prototype.setBody = function(value) {\n this.bodyPromise = $.Deferred();\n\n var body = this.getBody();\n\n if (typeof value === 'string') {\n // Just set the value if it's a string.\n body.html(value);\n Event.notifyFilterContentUpdated(body);\n this.getRoot().trigger(ModalEvents.bodyRendered, this);\n this.bodyPromise.resolve(body);\n } else {\n var jsPendingId = 'amd-modal-js-pending-id-' + this.getModalCount();\n M.util.js_pending(jsPendingId);\n // Otherwise we assume it's a promise to be resolved with\n // html and javascript.\n var contentPromise = null;\n body.css('overflow', 'hidden');\n\n // Ensure that the `value` is a jQuery Promise.\n value = $.when(value);\n\n if (value.state() == 'pending') {\n // We're still waiting for the body promise to resolve so\n // let's show a loading icon.\n var height = body.innerHeight();\n if (height < 100) {\n height = 100;\n }\n\n body.animate({height: height + 'px'}, 150);\n\n body.html('');\n contentPromise = Templates.render(TEMPLATES.LOADING, {})\n .then(function(html) {\n var loadingIcon = $(html).hide();\n body.html(loadingIcon);\n loadingIcon.fadeIn(150);\n\n // We only want the loading icon to fade out\n // when the content for the body has finished\n // loading.\n return $.when(loadingIcon.promise(), value);\n })\n .then(function(loadingIcon) {\n // Once the content has finished loading and\n // the loading icon has been shown then we can\n // fade the icon away to reveal the content.\n return loadingIcon.fadeOut(100).promise();\n })\n .then(function() {\n return value;\n });\n } else {\n // The content is already loaded so let's just display\n // it to the user. No need for a loading icon.\n contentPromise = value;\n }\n\n // Now we can actually display the content.\n contentPromise.then(function(html, js) {\n var result = null;\n\n if (this.isVisible()) {\n // If the modal is visible then we should display\n // the content gracefully for the user.\n body.css('opacity', 0);\n var currentHeight = body.innerHeight();\n body.html(html);\n // We need to clear any height values we've set here\n // in order to measure the height of the content being\n // added. This then allows us to animate the height\n // transition.\n body.css('height', '');\n var newHeight = body.innerHeight();\n body.css('height', currentHeight + 'px');\n result = body.animate(\n {height: newHeight + 'px', opacity: 1},\n {duration: 150, queue: false}\n ).promise();\n } else {\n // Since the modal isn't visible we can just immediately\n // set the content. No need to animate it.\n body.html(html);\n }\n\n if (js) {\n if (this.isAttached) {\n // If we're in the DOM then run the JS immediately.\n Templates.runTemplateJS(js);\n } else {\n // Otherwise cache it to be run when we're attached.\n this.bodyJS = js;\n }\n }\n\n return result;\n }.bind(this))\n .then(function(result) {\n Event.notifyFilterContentUpdated(body);\n this.getRoot().trigger(ModalEvents.bodyRendered, this);\n return result;\n }.bind(this))\n .then(function() {\n this.bodyPromise.resolve(body);\n return;\n }.bind(this))\n .fail(Notification.exception)\n .always(function() {\n // When we're done displaying all of the content we need\n // to clear the custom values we've set here.\n body.css('height', '');\n body.css('overflow', '');\n body.css('opacity', '');\n M.util.js_complete(jsPendingId);\n\n return;\n })\n .fail(Notification.exception);\n }\n };\n\n /**\n * Alternative to setBody() that can be used from non-Jquery modules\n *\n * @param {Promise} promise promise that returns {html, js} object\n * @return {Promise}\n */\n Modal.prototype.setBodyContent = function(promise) {\n // Call the leegacy API for now and pass it a jQuery Promise.\n // This is a non-spec feature of jQuery and cannot be produced with spec promises.\n // We can encourage people to migrate to this approach, and in future we can swap\n // it so that setBody() calls setBodyPromise().\n return promise.then(({html, js}) => this.setBody($.when(html, js)))\n .catch(exception => {\n this.hide();\n throw exception;\n });\n };\n\n /**\n * Set the modal footer element. The footer element is made visible, if it\n * isn't already.\n *\n * This method is overloaded to take either a string\n * value for the body or a jQuery promise that is resolved with HTML and Javascript\n * most commonly from a Templates.render call.\n *\n * @method setFooter\n * @param {(string|object)} value The footer string or jQuery promise\n */\n Modal.prototype.setFooter = function(value) {\n // Make sure the footer is visible.\n this.showFooter();\n this.footerPromise = $.Deferred();\n\n var footer = this.getFooter();\n\n if (typeof value === 'string') {\n // Just set the value if it's a string.\n footer.html(value);\n this.footerPromise.resolve(footer);\n } else {\n // Otherwise we assume it's a promise to be resolved with\n // html and javascript.\n Templates.render(TEMPLATES.LOADING, {})\n .then(function(html) {\n footer.html(html);\n\n return value;\n })\n .then(function(html, js) {\n footer.html(html);\n\n if (js) {\n if (this.isAttached) {\n // If we're in the DOM then run the JS immediately.\n Templates.runTemplateJS(js);\n } else {\n // Otherwise cache it to be run when we're attached.\n this.footerJS = js;\n }\n }\n\n return footer;\n }.bind(this))\n .then(function(footer) {\n this.footerPromise.resolve(footer);\n return;\n }.bind(this))\n .catch(Notification.exception);\n }\n };\n\n /**\n * Check if the footer has any content in it.\n *\n * @method hasFooterContent\n * @return {bool}\n */\n Modal.prototype.hasFooterContent = function() {\n return this.getFooter().children().length ? true : false;\n };\n\n /**\n * Hide the footer element.\n *\n * @method hideFooter\n */\n Modal.prototype.hideFooter = function() {\n this.getFooter().addClass('hidden');\n };\n\n /**\n * Show the footer element.\n *\n * @method showFooter\n */\n Modal.prototype.showFooter = function() {\n this.getFooter().removeClass('hidden');\n };\n\n /**\n * Mark the modal as a large modal.\n *\n * @method setLarge\n */\n Modal.prototype.setLarge = function() {\n if (this.isLarge()) {\n return;\n }\n\n this.getModal().addClass('modal-lg');\n };\n\n /**\n * Check if the modal is a large modal.\n *\n * @method isLarge\n * @return {bool}\n */\n Modal.prototype.isLarge = function() {\n return this.getModal().hasClass('modal-lg');\n };\n\n /**\n * Mark the modal as a small modal.\n *\n * @method setSmall\n */\n Modal.prototype.setSmall = function() {\n if (this.isSmall()) {\n return;\n }\n\n this.getModal().removeClass('modal-lg');\n };\n\n /**\n * Check if the modal is a small modal.\n *\n * @method isSmall\n * @return {bool}\n */\n Modal.prototype.isSmall = function() {\n return !this.getModal().hasClass('modal-lg');\n };\n\n /**\n * Set this modal to be scrollable or not.\n *\n * @method setScrollable\n * @param {bool} value Whether the modal is scrollable or not\n */\n Modal.prototype.setScrollable = function(value) {\n if (!value) {\n this.getModal()[0].classList.remove('modal-dialog-scrollable');\n return;\n }\n\n this.getModal()[0].classList.add('modal-dialog-scrollable');\n };\n\n\n /**\n * Determine the highest z-index value currently on the page.\n *\n * @method calculateZIndex\n * @return {int}\n */\n Modal.prototype.calculateZIndex = function() {\n var items = $(SELECTORS.DIALOG + ', ' + SELECTORS.MENU_BAR + ', ' + SELECTORS.HAS_Z_INDEX);\n var zIndex = parseInt(this.root.css('z-index'));\n\n items.each(function(index, item) {\n item = $(item);\n // Note that webkit browsers won't return the z-index value from the CSS stylesheet\n // if the element doesn't have a position specified. Instead it'll return \"auto\".\n var itemZIndex = item.css('z-index') ? parseInt(item.css('z-index')) : 0;\n\n if (itemZIndex > zIndex) {\n zIndex = itemZIndex;\n }\n });\n\n return zIndex;\n };\n\n /**\n * Check if this modal is visible.\n *\n * @method isVisible\n * @return {bool}\n */\n Modal.prototype.isVisible = function() {\n return this.root.hasClass('show');\n };\n\n /**\n * Check if this modal has focus.\n *\n * @method hasFocus\n * @return {bool}\n */\n Modal.prototype.hasFocus = function() {\n var target = $(document.activeElement);\n return this.root.is(target) || this.root.has(target).length;\n };\n\n /**\n * Check if this modal has CSS transitions applied.\n *\n * @method hasTransitions\n * @return {bool}\n */\n Modal.prototype.hasTransitions = function() {\n return this.getRoot().hasClass('fade');\n };\n\n /**\n * Gets the jQuery wrapped node that the Modal should be attached to.\n *\n * @returns {jQuery}\n */\n Modal.prototype.getAttachmentPoint = function() {\n return $(Fullscreen.getElement() || this.attachmentPoint);\n };\n\n /**\n * Display this modal. The modal will be attached to the DOM if it hasn't\n * already been.\n *\n * @method show\n * @returns {Promise}\n */\n Modal.prototype.show = function() {\n if (this.isVisible()) {\n return $.Deferred().resolve();\n }\n\n var pendingPromise = new Pending('core/modal:show');\n\n if (this.hasFooterContent()) {\n this.showFooter();\n } else {\n this.hideFooter();\n }\n\n this.attachToDOM();\n\n return this.getBackdrop()\n .then(function(backdrop) {\n var currentIndex = this.calculateZIndex();\n var newIndex = currentIndex + 2;\n var newBackdropIndex = newIndex - 1;\n this.root.css('z-index', newIndex);\n backdrop.setZIndex(newBackdropIndex);\n backdrop.show();\n\n this.root.removeClass('hide').addClass('show');\n this.accessibilityShow();\n this.getModal().focus();\n $('body').addClass('modal-open');\n this.root.trigger(ModalEvents.shown, this);\n\n return;\n }.bind(this))\n .then(pendingPromise.resolve);\n };\n\n /**\n * Hide this modal if it does not contain a form.\n *\n * @method hideIfNotForm\n */\n Modal.prototype.hideIfNotForm = function() {\n var formElement = this.modal.find(SELECTORS.FORM);\n if (formElement.length == 0) {\n this.hide();\n }\n };\n\n /**\n * Hide this modal.\n *\n * @method hide\n */\n Modal.prototype.hide = function() {\n this.getBackdrop().done(function(backdrop) {\n FocusLock.untrapFocus();\n\n if (!this.countOtherVisibleModals()) {\n // Hide the backdrop if we're the last open modal.\n backdrop.hide();\n $('body').removeClass('modal-open');\n }\n\n var currentIndex = parseInt(this.root.css('z-index'));\n this.root.css('z-index', '');\n backdrop.setZIndex(currentIndex - 3);\n\n this.accessibilityHide();\n\n if (this.hasTransitions()) {\n // Wait for CSS transitions to complete before hiding the element.\n this.getRoot().one('transitionend webkitTransitionEnd oTransitionEnd', function() {\n this.getRoot().removeClass('show').addClass('hide');\n }.bind(this));\n } else {\n this.getRoot().removeClass('show').addClass('hide');\n }\n\n // Ensure the modal is moved onto the body node if it is still attached to the DOM.\n if ($(document.body).find(this.getRoot()).length) {\n $(document.body).append(this.getRoot());\n }\n\n this.root.trigger(ModalEvents.hidden, this);\n }.bind(this));\n };\n\n /**\n * Remove this modal from the DOM.\n *\n * @method destroy\n */\n Modal.prototype.destroy = function() {\n this.hide();\n this.root.remove();\n this.root.trigger(ModalEvents.destroyed, this);\n this.attachmentPoint.remove();\n };\n\n /**\n * Sets the appropriate aria attributes on this dialogue and the other\n * elements in the DOM to ensure that screen readers are able to navigate\n * the dialogue popup correctly.\n *\n * @method accessibilityShow\n */\n Modal.prototype.accessibilityShow = function() {\n // Make us visible to screen readers.\n Aria.unhide(this.root.get());\n\n // Hide siblings.\n Aria.hideSiblings(this.root.get()[0]);\n };\n\n /**\n * Restores the aria visibility on the DOM elements changed when displaying\n * the dialogue popup and makes the dialogue aria hidden to allow screen\n * readers to navigate the main page correctly when the dialogue is closed.\n *\n * @method accessibilityHide\n */\n Modal.prototype.accessibilityHide = function() {\n // Unhide siblings.\n Aria.unhideSiblings(this.root.get()[0]);\n\n // Hide this modal.\n Aria.hide(this.root.get());\n };\n\n /**\n * Set up all of the event handling for the modal.\n *\n * @method registerEventListeners\n */\n Modal.prototype.registerEventListeners = function() {\n this.getRoot().on('keydown', function(e) {\n if (!this.isVisible()) {\n return;\n }\n\n if (e.keyCode == KeyCodes.escape) {\n if (this.removeOnClose) {\n this.destroy();\n } else {\n this.hide();\n }\n }\n }.bind(this));\n\n // Listen for clicks on the modal container.\n this.getRoot().click(function(e) {\n // If the click wasn't inside the modal element then we should\n // hide the modal.\n if (!$(e.target).closest(SELECTORS.MODAL).length) {\n // The check above fails to detect the click was inside the modal when the DOM tree is already changed.\n // So, we check if we can still find the container element or not. If not, then the DOM tree is changed.\n // It's best not to hide the modal in that case.\n if ($(e.target).closest(SELECTORS.CONTAINER).length) {\n var outsideClickEvent = $.Event(ModalEvents.outsideClick);\n this.getRoot().trigger(outsideClickEvent, this);\n\n if (!outsideClickEvent.isDefaultPrevented()) {\n this.hideIfNotForm();\n }\n }\n }\n }.bind(this));\n\n CustomEvents.define(this.getModal(), [CustomEvents.events.activate]);\n this.getModal().on(CustomEvents.events.activate, SELECTORS.HIDE, function(e, data) {\n this.hide();\n data.originalEvent.preventDefault();\n }.bind(this));\n };\n\n /**\n * Register a listener to close the dialogue when the cancel button is pressed.\n *\n * @method registerCloseOnCancel\n */\n Modal.prototype.registerCloseOnCancel = function() {\n // Handle the clicking of the Cancel button.\n this.getModal().on(CustomEvents.events.activate, this.getActionSelector('cancel'), function(e, data) {\n var cancelEvent = $.Event(ModalEvents.cancel);\n this.getRoot().trigger(cancelEvent, this);\n\n if (!cancelEvent.isDefaultPrevented()) {\n data.originalEvent.preventDefault();\n\n if (this.removeOnClose) {\n this.destroy();\n } else {\n this.hide();\n }\n }\n }.bind(this));\n };\n\n /**\n * Register a listener to close the dialogue when the save button is pressed.\n *\n * @method registerCloseOnSave\n */\n Modal.prototype.registerCloseOnSave = function() {\n // Handle the clicking of the Cancel button.\n this.getModal().on(CustomEvents.events.activate, this.getActionSelector('save'), function(e, data) {\n var saveEvent = $.Event(ModalEvents.save);\n this.getRoot().trigger(saveEvent, this);\n\n if (!saveEvent.isDefaultPrevented()) {\n data.originalEvent.preventDefault();\n\n if (this.removeOnClose) {\n this.destroy();\n } else {\n this.hide();\n }\n }\n }.bind(this));\n };\n\n /**\n * Set or resolve and set the value using the function.\n *\n * @method asyncSet\n * @param {(string|object)} value The string or jQuery promise.\n * @param {function} setFunction The setter\n * @return {Promise}\n */\n Modal.prototype.asyncSet = function(value, setFunction) {\n var p = value;\n if (typeof value !== 'object' || !value.hasOwnProperty('then')) {\n p = $.Deferred();\n p.resolve(value);\n }\n\n p.then(function(content) {\n setFunction(content);\n\n return;\n })\n .fail(Notification.exception);\n\n return p;\n };\n\n /**\n * Set the title text of a button.\n *\n * This method is overloaded to take either a string value for the button title or a jQuery promise that is resolved with\n * text most commonly from a Str.get_string call.\n *\n * @param {DOMString} action The action of the button\n * @param {(String|object)} value The button text, or a promise which will resolve to it\n * @returns {Promise}\n */\n Modal.prototype.setButtonText = function(action, value) {\n const button = this.getFooter().find(this.getActionSelector(action));\n\n if (!button) {\n throw new Error(\"Unable to find the '\" + action + \"' button\");\n }\n\n return this.asyncSet(value, button.text.bind(button));\n };\n\n /**\n * Get the Selector for an action.\n *\n * @param {String} action\n * @returns {DOMString}\n */\n Modal.prototype.getActionSelector = function(action) {\n return \"[data-action='\" + action + \"']\";\n };\n\n /**\n * Set the flag to remove the modal from the DOM on close.\n *\n * @param {Boolean} remove\n */\n Modal.prototype.setRemoveOnClose = function(remove) {\n this.removeOnClose = remove;\n };\n\n return Modal;\n});\n"],"file":"modal.min.js"}
\ No newline at end of file
+{"version":3,"sources":["../src/modal.js"],"names":["define","$","Templates","Notification","KeyCodes","CustomEvents","ModalBackdrop","FilterEvents","ModalEvents","FocusLock","Pending","Aria","Fullscreen","SELECTORS","CONTAINER","MODAL","HEADER","TITLE","BODY","FOOTER","HIDE","DIALOG","FORM","MENU_BAR","HAS_Z_INDEX","CAN_RECEIVE_FOCUS","TEMPLATES","LOADING","BACKDROP","backdropPromise","modalCounter","Modal","root","modal","find","header","headerPromise","Deferred","title","titlePromise","body","bodyPromise","footer","footerPromise","hiddenSiblings","isAttached","bodyJS","footerJS","modalCount","attachmentPoint","document","createElement","append","is","exception","message","length","registerEventListeners","prototype","attachToDOM","getAttachmentPoint","trapFocus","runTemplateJS","countOtherVisibleModals","count","each","index","element","hasClass","bind","getBackdrop","render","then","html","fail","getRoot","getModal","getTitle","getBody","getFooter","getTitlePromise","getBodyPromise","getFooterPromise","getModalCount","setTitle","value","asyncSet","resolve","catch","setBody","notifyFilterContentUpdated","trigger","bodyRendered","jsPendingId","M","util","js_pending","contentPromise","css","when","state","height","innerHeight","animate","loadingIcon","hide","fadeIn","promise","fadeOut","js","result","isVisible","currentHeight","newHeight","opacity","duration","queue","always","js_complete","setBodyContent","setFooter","showFooter","hasFooterContent","children","hideFooter","addClass","removeClass","setLarge","isLarge","setSmall","isSmall","setScrollable","classList","remove","add","calculateZIndex","items","zIndex","parseInt","item","itemZIndex","hasFocus","target","activeElement","has","hasTransitions","getElement","show","pendingPromise","backdrop","currentIndex","newIndex","setZIndex","accessibilityShow","focus","shown","hideIfNotForm","formElement","done","untrapFocus","accessibilityHide","one","hidden","destroy","destroyed","unhide","get","hideSiblings","unhideSiblings","on","e","keyCode","escape","removeOnClose","click","closest","outsideClickEvent","Event","outsideClick","isDefaultPrevented","events","activate","data","originalEvent","preventDefault","registerCloseOnCancel","getActionSelector","cancelEvent","cancel","registerCloseOnSave","saveEvent","save","setFunction","p","hasOwnProperty","content","setButtonText","action","button","Error","text","set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AmC,SAASpE,CAAT,CAAiB,CAChD,KAAKwC,aAAL,CAAqBxC,CACxB,CAFD,CAIA,MAAOtG,CAAAA,CACV,CA96BK,CAAN","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 modals.\n *\n * @module core/modal\n * @class modal\n * @package core\n * @copyright 2016 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([\n 'jquery',\n 'core/templates',\n 'core/notification',\n 'core/key_codes',\n 'core/custom_interaction_events',\n 'core/modal_backdrop',\n 'core_filters/events',\n 'core/modal_events',\n 'core/local/aria/focuslock',\n 'core/pending',\n 'core/aria',\n 'core/fullscreen'\n], function(\n $,\n Templates,\n Notification,\n KeyCodes,\n CustomEvents,\n ModalBackdrop,\n FilterEvents,\n ModalEvents,\n FocusLock,\n Pending,\n Aria,\n Fullscreen\n) {\n\n var SELECTORS = {\n CONTAINER: '[data-region=\"modal-container\"]',\n MODAL: '[data-region=\"modal\"]',\n HEADER: '[data-region=\"header\"]',\n TITLE: '[data-region=\"title\"]',\n BODY: '[data-region=\"body\"]',\n FOOTER: '[data-region=\"footer\"]',\n HIDE: '[data-action=\"hide\"]',\n DIALOG: '[role=dialog]',\n FORM: 'form',\n MENU_BAR: '[role=menubar]',\n HAS_Z_INDEX: '.moodle-has-zindex',\n CAN_RECEIVE_FOCUS: 'input:not([type=\"hidden\"]), a[href], button, textarea, select, [tabindex]',\n };\n\n var TEMPLATES = {\n LOADING: 'core/loading',\n BACKDROP: 'core/modal_backdrop',\n };\n\n /**\n * Module singleton for the backdrop to be reused by all Modal instances.\n */\n var backdropPromise;\n\n /**\n * A counter that gets incremented for each modal created. This can be\n * used to generate unique values for the modals.\n */\n var modalCounter = 0;\n\n /**\n * Constructor for the Modal.\n *\n * @param {object} root The root jQuery element for the modal\n */\n var Modal = function(root) {\n this.root = $(root);\n this.modal = this.root.find(SELECTORS.MODAL);\n this.header = this.modal.find(SELECTORS.HEADER);\n this.headerPromise = $.Deferred();\n this.title = this.header.find(SELECTORS.TITLE);\n this.titlePromise = $.Deferred();\n this.body = this.modal.find(SELECTORS.BODY);\n this.bodyPromise = $.Deferred();\n this.footer = this.modal.find(SELECTORS.FOOTER);\n this.footerPromise = $.Deferred();\n this.hiddenSiblings = [];\n this.isAttached = false;\n this.bodyJS = null;\n this.footerJS = null;\n this.modalCount = modalCounter++;\n this.attachmentPoint = document.createElement('div');\n document.body.append(this.attachmentPoint);\n\n if (!this.root.is(SELECTORS.CONTAINER)) {\n Notification.exception({message: 'Element is not a modal container'});\n }\n\n if (!this.modal.length) {\n Notification.exception({message: 'Container does not contain a modal'});\n }\n\n if (!this.header.length) {\n Notification.exception({message: 'Modal is missing a header region'});\n }\n\n if (!this.title.length) {\n Notification.exception({message: 'Modal header is missing a title region'});\n }\n\n if (!this.body.length) {\n Notification.exception({message: 'Modal is missing a body region'});\n }\n\n if (!this.footer.length) {\n Notification.exception({message: 'Modal is missing a footer region'});\n }\n\n this.registerEventListeners();\n };\n\n /**\n * Attach the modal to the correct part of the page.\n *\n * If it hasn't already been added it runs any\n * javascript that has been cached until now.\n *\n * @method attachToDOM\n */\n Modal.prototype.attachToDOM = function() {\n this.getAttachmentPoint().append(this.root);\n\n if (this.isAttached) {\n return;\n }\n\n FocusLock.trapFocus(this.root[0]);\n\n // If we'd cached any JS then we can run it how that the modal is\n // attached to the DOM.\n if (this.bodyJS) {\n Templates.runTemplateJS(this.bodyJS);\n this.bodyJS = null;\n }\n\n if (this.footerJS) {\n Templates.runTemplateJS(this.footerJS);\n this.footerJS = null;\n }\n\n this.isAttached = true;\n };\n\n /**\n * Count the number of other visible modals (not including this one).\n *\n * @method countOtherVisibleModals\n * @return {int}\n */\n Modal.prototype.countOtherVisibleModals = function() {\n var count = 0;\n $('body').find(SELECTORS.CONTAINER).each(function(index, element) {\n element = $(element);\n\n // If we haven't found ourself and the element is visible.\n if (!this.root.is(element) && element.hasClass('show')) {\n count++;\n }\n }.bind(this));\n\n return count;\n };\n\n /**\n * Get the modal backdrop.\n *\n * @method getBackdrop\n * @return {object} jQuery promise\n */\n Modal.prototype.getBackdrop = function() {\n if (!backdropPromise) {\n backdropPromise = Templates.render(TEMPLATES.BACKDROP, {})\n .then(function(html) {\n var element = $(html);\n\n return new ModalBackdrop(element);\n })\n .fail(Notification.exception);\n }\n\n return backdropPromise;\n };\n\n /**\n * Get the root element of this modal.\n *\n * @method getRoot\n * @return {object} jQuery object\n */\n Modal.prototype.getRoot = function() {\n return this.root;\n };\n\n /**\n * Get the modal element of this modal.\n *\n * @method getModal\n * @return {object} jQuery object\n */\n Modal.prototype.getModal = function() {\n return this.modal;\n };\n\n /**\n * Get the modal title element.\n *\n * @method getTitle\n * @return {object} jQuery object\n */\n Modal.prototype.getTitle = function() {\n return this.title;\n };\n\n /**\n * Get the modal body element.\n *\n * @method getBody\n * @return {object} jQuery object\n */\n Modal.prototype.getBody = function() {\n return this.body;\n };\n\n /**\n * Get the modal footer element.\n *\n * @method getFooter\n * @return {object} jQuery object\n */\n Modal.prototype.getFooter = function() {\n return this.footer;\n };\n\n /**\n * Get a promise resolving to the title region.\n *\n * @method getTitlePromise\n * @return {Promise}\n */\n Modal.prototype.getTitlePromise = function() {\n return this.titlePromise;\n };\n\n /**\n * Get a promise resolving to the body region.\n *\n * @method getBodyPromise\n * @return {object} jQuery object\n */\n Modal.prototype.getBodyPromise = function() {\n return this.bodyPromise;\n };\n\n /**\n * Get a promise resolving to the footer region.\n *\n * @method getFooterPromise\n * @return {object} jQuery object\n */\n Modal.prototype.getFooterPromise = function() {\n return this.footerPromise;\n };\n\n /**\n * Get the unique modal count.\n *\n * @method getModalCount\n * @return {int}\n */\n Modal.prototype.getModalCount = function() {\n return this.modalCount;\n };\n\n /**\n * Set the modal title element.\n *\n * This method is overloaded to take either a string value for the title or a jQuery promise that is resolved with\n * HTML most commonly from a Str.get_string call.\n *\n * @method setTitle\n * @param {(string|object)} value The title string or jQuery promise which resolves to the title.\n */\n Modal.prototype.setTitle = function(value) {\n var title = this.getTitle();\n this.titlePromise = $.Deferred();\n\n this.asyncSet(value, title.html.bind(title))\n .then(function() {\n this.titlePromise.resolve(title);\n }.bind(this))\n .catch(Notification.exception);\n };\n\n /**\n * Set the modal body element.\n *\n * This method is overloaded to take either a string value for the body or a jQuery promise that is resolved with\n * HTML and Javascript most commonly from a Templates.render call.\n *\n * @method setBody\n * @param {(string|object)} value The body string or jQuery promise which resolves to the body.\n * @fires event:filterContentUpdated\n */\n Modal.prototype.setBody = function(value) {\n this.bodyPromise = $.Deferred();\n\n var body = this.getBody();\n\n if (typeof value === 'string') {\n // Just set the value if it's a string.\n body.html(value);\n FilterEvents.notifyFilterContentUpdated(body);\n this.getRoot().trigger(ModalEvents.bodyRendered, this);\n this.bodyPromise.resolve(body);\n } else {\n var jsPendingId = 'amd-modal-js-pending-id-' + this.getModalCount();\n M.util.js_pending(jsPendingId);\n // Otherwise we assume it's a promise to be resolved with\n // html and javascript.\n var contentPromise = null;\n body.css('overflow', 'hidden');\n\n // Ensure that the `value` is a jQuery Promise.\n value = $.when(value);\n\n if (value.state() == 'pending') {\n // We're still waiting for the body promise to resolve so\n // let's show a loading icon.\n var height = body.innerHeight();\n if (height < 100) {\n height = 100;\n }\n\n body.animate({height: height + 'px'}, 150);\n\n body.html('');\n contentPromise = Templates.render(TEMPLATES.LOADING, {})\n .then(function(html) {\n var loadingIcon = $(html).hide();\n body.html(loadingIcon);\n loadingIcon.fadeIn(150);\n\n // We only want the loading icon to fade out\n // when the content for the body has finished\n // loading.\n return $.when(loadingIcon.promise(), value);\n })\n .then(function(loadingIcon) {\n // Once the content has finished loading and\n // the loading icon has been shown then we can\n // fade the icon away to reveal the content.\n return loadingIcon.fadeOut(100).promise();\n })\n .then(function() {\n return value;\n });\n } else {\n // The content is already loaded so let's just display\n // it to the user. No need for a loading icon.\n contentPromise = value;\n }\n\n // Now we can actually display the content.\n contentPromise.then(function(html, js) {\n var result = null;\n\n if (this.isVisible()) {\n // If the modal is visible then we should display\n // the content gracefully for the user.\n body.css('opacity', 0);\n var currentHeight = body.innerHeight();\n body.html(html);\n // We need to clear any height values we've set here\n // in order to measure the height of the content being\n // added. This then allows us to animate the height\n // transition.\n body.css('height', '');\n var newHeight = body.innerHeight();\n body.css('height', currentHeight + 'px');\n result = body.animate(\n {height: newHeight + 'px', opacity: 1},\n {duration: 150, queue: false}\n ).promise();\n } else {\n // Since the modal isn't visible we can just immediately\n // set the content. No need to animate it.\n body.html(html);\n }\n\n if (js) {\n if (this.isAttached) {\n // If we're in the DOM then run the JS immediately.\n Templates.runTemplateJS(js);\n } else {\n // Otherwise cache it to be run when we're attached.\n this.bodyJS = js;\n }\n }\n\n return result;\n }.bind(this))\n .then(function(result) {\n FilterEvents.notifyFilterContentUpdated(body);\n this.getRoot().trigger(ModalEvents.bodyRendered, this);\n return result;\n }.bind(this))\n .then(function() {\n this.bodyPromise.resolve(body);\n return;\n }.bind(this))\n .fail(Notification.exception)\n .always(function() {\n // When we're done displaying all of the content we need\n // to clear the custom values we've set here.\n body.css('height', '');\n body.css('overflow', '');\n body.css('opacity', '');\n M.util.js_complete(jsPendingId);\n\n return;\n })\n .fail(Notification.exception);\n }\n };\n\n /**\n * Alternative to setBody() that can be used from non-Jquery modules\n *\n * @param {Promise} promise promise that returns {html, js} object\n * @return {Promise}\n */\n Modal.prototype.setBodyContent = function(promise) {\n // Call the leegacy API for now and pass it a jQuery Promise.\n // This is a non-spec feature of jQuery and cannot be produced with spec promises.\n // We can encourage people to migrate to this approach, and in future we can swap\n // it so that setBody() calls setBodyPromise().\n return promise.then(({html, js}) => this.setBody($.when(html, js)))\n .catch(exception => {\n this.hide();\n throw exception;\n });\n };\n\n /**\n * Set the modal footer element. The footer element is made visible, if it\n * isn't already.\n *\n * This method is overloaded to take either a string\n * value for the body or a jQuery promise that is resolved with HTML and Javascript\n * most commonly from a Templates.render call.\n *\n * @method setFooter\n * @param {(string|object)} value The footer string or jQuery promise\n */\n Modal.prototype.setFooter = function(value) {\n // Make sure the footer is visible.\n this.showFooter();\n this.footerPromise = $.Deferred();\n\n var footer = this.getFooter();\n\n if (typeof value === 'string') {\n // Just set the value if it's a string.\n footer.html(value);\n this.footerPromise.resolve(footer);\n } else {\n // Otherwise we assume it's a promise to be resolved with\n // html and javascript.\n Templates.render(TEMPLATES.LOADING, {})\n .then(function(html) {\n footer.html(html);\n\n return value;\n })\n .then(function(html, js) {\n footer.html(html);\n\n if (js) {\n if (this.isAttached) {\n // If we're in the DOM then run the JS immediately.\n Templates.runTemplateJS(js);\n } else {\n // Otherwise cache it to be run when we're attached.\n this.footerJS = js;\n }\n }\n\n return footer;\n }.bind(this))\n .then(function(footer) {\n this.footerPromise.resolve(footer);\n return;\n }.bind(this))\n .catch(Notification.exception);\n }\n };\n\n /**\n * Check if the footer has any content in it.\n *\n * @method hasFooterContent\n * @return {bool}\n */\n Modal.prototype.hasFooterContent = function() {\n return this.getFooter().children().length ? true : false;\n };\n\n /**\n * Hide the footer element.\n *\n * @method hideFooter\n */\n Modal.prototype.hideFooter = function() {\n this.getFooter().addClass('hidden');\n };\n\n /**\n * Show the footer element.\n *\n * @method showFooter\n */\n Modal.prototype.showFooter = function() {\n this.getFooter().removeClass('hidden');\n };\n\n /**\n * Mark the modal as a large modal.\n *\n * @method setLarge\n */\n Modal.prototype.setLarge = function() {\n if (this.isLarge()) {\n return;\n }\n\n this.getModal().addClass('modal-lg');\n };\n\n /**\n * Check if the modal is a large modal.\n *\n * @method isLarge\n * @return {bool}\n */\n Modal.prototype.isLarge = function() {\n return this.getModal().hasClass('modal-lg');\n };\n\n /**\n * Mark the modal as a small modal.\n *\n * @method setSmall\n */\n Modal.prototype.setSmall = function() {\n if (this.isSmall()) {\n return;\n }\n\n this.getModal().removeClass('modal-lg');\n };\n\n /**\n * Check if the modal is a small modal.\n *\n * @method isSmall\n * @return {bool}\n */\n Modal.prototype.isSmall = function() {\n return !this.getModal().hasClass('modal-lg');\n };\n\n /**\n * Set this modal to be scrollable or not.\n *\n * @method setScrollable\n * @param {bool} value Whether the modal is scrollable or not\n */\n Modal.prototype.setScrollable = function(value) {\n if (!value) {\n this.getModal()[0].classList.remove('modal-dialog-scrollable');\n return;\n }\n\n this.getModal()[0].classList.add('modal-dialog-scrollable');\n };\n\n\n /**\n * Determine the highest z-index value currently on the page.\n *\n * @method calculateZIndex\n * @return {int}\n */\n Modal.prototype.calculateZIndex = function() {\n var items = $(SELECTORS.DIALOG + ', ' + SELECTORS.MENU_BAR + ', ' + SELECTORS.HAS_Z_INDEX);\n var zIndex = parseInt(this.root.css('z-index'));\n\n items.each(function(index, item) {\n item = $(item);\n // Note that webkit browsers won't return the z-index value from the CSS stylesheet\n // if the element doesn't have a position specified. Instead it'll return \"auto\".\n var itemZIndex = item.css('z-index') ? parseInt(item.css('z-index')) : 0;\n\n if (itemZIndex > zIndex) {\n zIndex = itemZIndex;\n }\n });\n\n return zIndex;\n };\n\n /**\n * Check if this modal is visible.\n *\n * @method isVisible\n * @return {bool}\n */\n Modal.prototype.isVisible = function() {\n return this.root.hasClass('show');\n };\n\n /**\n * Check if this modal has focus.\n *\n * @method hasFocus\n * @return {bool}\n */\n Modal.prototype.hasFocus = function() {\n var target = $(document.activeElement);\n return this.root.is(target) || this.root.has(target).length;\n };\n\n /**\n * Check if this modal has CSS transitions applied.\n *\n * @method hasTransitions\n * @return {bool}\n */\n Modal.prototype.hasTransitions = function() {\n return this.getRoot().hasClass('fade');\n };\n\n /**\n * Gets the jQuery wrapped node that the Modal should be attached to.\n *\n * @returns {jQuery}\n */\n Modal.prototype.getAttachmentPoint = function() {\n return $(Fullscreen.getElement() || this.attachmentPoint);\n };\n\n /**\n * Display this modal. The modal will be attached to the DOM if it hasn't\n * already been.\n *\n * @method show\n * @returns {Promise}\n */\n Modal.prototype.show = function() {\n if (this.isVisible()) {\n return $.Deferred().resolve();\n }\n\n var pendingPromise = new Pending('core/modal:show');\n\n if (this.hasFooterContent()) {\n this.showFooter();\n } else {\n this.hideFooter();\n }\n\n this.attachToDOM();\n\n return this.getBackdrop()\n .then(function(backdrop) {\n var currentIndex = this.calculateZIndex();\n var newIndex = currentIndex + 2;\n var newBackdropIndex = newIndex - 1;\n this.root.css('z-index', newIndex);\n backdrop.setZIndex(newBackdropIndex);\n backdrop.show();\n\n this.root.removeClass('hide').addClass('show');\n this.accessibilityShow();\n this.getModal().focus();\n $('body').addClass('modal-open');\n this.root.trigger(ModalEvents.shown, this);\n\n return;\n }.bind(this))\n .then(pendingPromise.resolve);\n };\n\n /**\n * Hide this modal if it does not contain a form.\n *\n * @method hideIfNotForm\n */\n Modal.prototype.hideIfNotForm = function() {\n var formElement = this.modal.find(SELECTORS.FORM);\n if (formElement.length == 0) {\n this.hide();\n }\n };\n\n /**\n * Hide this modal.\n *\n * @method hide\n */\n Modal.prototype.hide = function() {\n this.getBackdrop().done(function(backdrop) {\n FocusLock.untrapFocus();\n\n if (!this.countOtherVisibleModals()) {\n // Hide the backdrop if we're the last open modal.\n backdrop.hide();\n $('body').removeClass('modal-open');\n }\n\n var currentIndex = parseInt(this.root.css('z-index'));\n this.root.css('z-index', '');\n backdrop.setZIndex(currentIndex - 3);\n\n this.accessibilityHide();\n\n if (this.hasTransitions()) {\n // Wait for CSS transitions to complete before hiding the element.\n this.getRoot().one('transitionend webkitTransitionEnd oTransitionEnd', function() {\n this.getRoot().removeClass('show').addClass('hide');\n }.bind(this));\n } else {\n this.getRoot().removeClass('show').addClass('hide');\n }\n\n // Ensure the modal is moved onto the body node if it is still attached to the DOM.\n if ($(document.body).find(this.getRoot()).length) {\n $(document.body).append(this.getRoot());\n }\n\n this.root.trigger(ModalEvents.hidden, this);\n }.bind(this));\n };\n\n /**\n * Remove this modal from the DOM.\n *\n * @method destroy\n */\n Modal.prototype.destroy = function() {\n this.hide();\n this.root.remove();\n this.root.trigger(ModalEvents.destroyed, this);\n this.attachmentPoint.remove();\n };\n\n /**\n * Sets the appropriate aria attributes on this dialogue and the other\n * elements in the DOM to ensure that screen readers are able to navigate\n * the dialogue popup correctly.\n *\n * @method accessibilityShow\n */\n Modal.prototype.accessibilityShow = function() {\n // Make us visible to screen readers.\n Aria.unhide(this.root.get());\n\n // Hide siblings.\n Aria.hideSiblings(this.root.get()[0]);\n };\n\n /**\n * Restores the aria visibility on the DOM elements changed when displaying\n * the dialogue popup and makes the dialogue aria hidden to allow screen\n * readers to navigate the main page correctly when the dialogue is closed.\n *\n * @method accessibilityHide\n */\n Modal.prototype.accessibilityHide = function() {\n // Unhide siblings.\n Aria.unhideSiblings(this.root.get()[0]);\n\n // Hide this modal.\n Aria.hide(this.root.get());\n };\n\n /**\n * Set up all of the event handling for the modal.\n *\n * @method registerEventListeners\n */\n Modal.prototype.registerEventListeners = function() {\n this.getRoot().on('keydown', function(e) {\n if (!this.isVisible()) {\n return;\n }\n\n if (e.keyCode == KeyCodes.escape) {\n if (this.removeOnClose) {\n this.destroy();\n } else {\n this.hide();\n }\n }\n }.bind(this));\n\n // Listen for clicks on the modal container.\n this.getRoot().click(function(e) {\n // If the click wasn't inside the modal element then we should\n // hide the modal.\n if (!$(e.target).closest(SELECTORS.MODAL).length) {\n // The check above fails to detect the click was inside the modal when the DOM tree is already changed.\n // So, we check if we can still find the container element or not. If not, then the DOM tree is changed.\n // It's best not to hide the modal in that case.\n if ($(e.target).closest(SELECTORS.CONTAINER).length) {\n var outsideClickEvent = $.Event(ModalEvents.outsideClick);\n this.getRoot().trigger(outsideClickEvent, this);\n\n if (!outsideClickEvent.isDefaultPrevented()) {\n this.hideIfNotForm();\n }\n }\n }\n }.bind(this));\n\n CustomEvents.define(this.getModal(), [CustomEvents.events.activate]);\n this.getModal().on(CustomEvents.events.activate, SELECTORS.HIDE, function(e, data) {\n this.hide();\n data.originalEvent.preventDefault();\n }.bind(this));\n };\n\n /**\n * Register a listener to close the dialogue when the cancel button is pressed.\n *\n * @method registerCloseOnCancel\n */\n Modal.prototype.registerCloseOnCancel = function() {\n // Handle the clicking of the Cancel button.\n this.getModal().on(CustomEvents.events.activate, this.getActionSelector('cancel'), function(e, data) {\n var cancelEvent = $.Event(ModalEvents.cancel);\n this.getRoot().trigger(cancelEvent, this);\n\n if (!cancelEvent.isDefaultPrevented()) {\n data.originalEvent.preventDefault();\n\n if (this.removeOnClose) {\n this.destroy();\n } else {\n this.hide();\n }\n }\n }.bind(this));\n };\n\n /**\n * Register a listener to close the dialogue when the save button is pressed.\n *\n * @method registerCloseOnSave\n */\n Modal.prototype.registerCloseOnSave = function() {\n // Handle the clicking of the Cancel button.\n this.getModal().on(CustomEvents.events.activate, this.getActionSelector('save'), function(e, data) {\n var saveEvent = $.Event(ModalEvents.save);\n this.getRoot().trigger(saveEvent, this);\n\n if (!saveEvent.isDefaultPrevented()) {\n data.originalEvent.preventDefault();\n\n if (this.removeOnClose) {\n this.destroy();\n } else {\n this.hide();\n }\n }\n }.bind(this));\n };\n\n /**\n * Set or resolve and set the value using the function.\n *\n * @method asyncSet\n * @param {(string|object)} value The string or jQuery promise.\n * @param {function} setFunction The setter\n * @return {Promise}\n */\n Modal.prototype.asyncSet = function(value, setFunction) {\n var p = value;\n if (typeof value !== 'object' || !value.hasOwnProperty('then')) {\n p = $.Deferred();\n p.resolve(value);\n }\n\n p.then(function(content) {\n setFunction(content);\n\n return;\n })\n .fail(Notification.exception);\n\n return p;\n };\n\n /**\n * Set the title text of a button.\n *\n * This method is overloaded to take either a string value for the button title or a jQuery promise that is resolved with\n * text most commonly from a Str.get_string call.\n *\n * @param {DOMString} action The action of the button\n * @param {(String|object)} value The button text, or a promise which will resolve to it\n * @returns {Promise}\n */\n Modal.prototype.setButtonText = function(action, value) {\n const button = this.getFooter().find(this.getActionSelector(action));\n\n if (!button) {\n throw new Error(\"Unable to find the '\" + action + \"' button\");\n }\n\n return this.asyncSet(value, button.text.bind(button));\n };\n\n /**\n * Get the Selector for an action.\n *\n * @param {String} action\n * @returns {DOMString}\n */\n Modal.prototype.getActionSelector = function(action) {\n return \"[data-action='\" + action + \"']\";\n };\n\n /**\n * Set the flag to remove the modal from the DOM on close.\n *\n * @param {Boolean} remove\n */\n Modal.prototype.setRemoveOnClose = function(remove) {\n this.removeOnClose = remove;\n };\n\n return Modal;\n});\n"],"file":"modal.min.js"}
\ No newline at end of file
diff --git a/lib/amd/build/templates.min.js b/lib/amd/build/templates.min.js
index 6beb8a6e542..36b4c671519 100644
--- a/lib/amd/build/templates.min.js
+++ b/lib/amd/build/templates.min.js
@@ -1,2 +1,2 @@
-define ("core/templates",["core/mustache","jquery","core/ajax","core/str","core/notification","core/url","core/config","core/localstorage","core/icon_system","core/event","core/yui","core/log","core/truncate","core/user_date","core/pending"],function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o){var p=0,q={},r={},s={},t={},u=[],v=!1,w=["js"],x=function(a){if(a){if("moodle"!==a&&"core"!==a){return a}}return"core"},y=function(a){if(a in r){return r[a]}if(a in q){r[a]=b.Deferred().resolve(q[a]).promise();return r[a]}if(0>=M.cfg.templaterev){return null}var c=h.get("core_template/"+M.cfg.templaterev+":"+a);if(c){q[a]=c;r[a]=b.Deferred().resolve(c).promise();return r[a]}return null},z=function(){if(!u.length){return}if(v){return}v=!0;var a=u.slice(),e=b.Deferred(),f=[],g=a.map(function(a){var c=x(a.component),i=a.name,j=a.searchKey,k=a.theme,l=a.deferred,m=null,n=y(j);if(n){m=n}else{f.push({methodname:"core_output_load_template_with_dependencies",args:{component:c,template:i,themename:k,lang:b("html").attr("lang").replace(/-/g,"_")}});var o=f.length-1;m=e.promise().then(function(a){g[j]=a[o].then(function(a){var b=null;a.templates.forEach(function(a){a.component=x(a.component);var d=[k,a.component,a.name].join("/");q[d]=a.value;if(0=}}$1<%={{ }}=%>").replace(/(\r\n|\r|\n)/g,"
");return"\""+d+"\""};A.prototype.shortenTextHelper=function(a,b,c){var d=b.match(/(.*?),(.*)/),e=d[1].trim(),f=d[2].trim(),g=c(f,a);return m.truncate(g,{length:e,words:!0,ellipsis:"..."})};A.prototype.userDateHelper=function(a,b,c){var d=b.match(/(.*?),(.*)/),e=c(d[1].trim(),a),f=c(d[2].trim(),a),g=this.requiredDates.length;this.requiredDates.push({timestamp:e,format:f});return"[[_t_"+g+"]]"};A.prototype.addHelperFunction=function(a,b){return function(){return function(c,d){var e=w.reduce(function(a,c){if(b.hasOwnProperty(c)){a[c]=b[c]}return a},{});w.forEach(function(a){b[a]=function(){return""}});var f=a.apply(this,[b,c,d]);for(var g in e){b[g]=e[g]}return f}.bind(this)}.bind(this)};A.prototype.addHelpers=function(a,b){this.currentThemeName=b;this.requiredStrings=[];this.requiredJS=[];a.uniqid=p++;a.str=this.addHelperFunction(this.stringHelper,a);a.pix=this.addHelperFunction(this.pixHelper,a);a.js=this.addHelperFunction(this.jsHelper,a);a.quote=this.addHelperFunction(this.quoteHelper,a);a.shortentext=this.addHelperFunction(this.shortenTextHelper,a);a.userdate=this.addHelperFunction(this.userDateHelper,a);a.globals={config:g};a.currentTheme=b};A.prototype.getJS=function(){var a="";if(0").attr("type","text/javascript").html(a);b("head").append(c)}},C=function(a,c,d,e){var f=b(a);if(f.length){var g=b(c),h=null;if(e){h=new k.NodeList(f.children().get());h.destroy(!0);f.empty();f.append(g)}else{h=new k.NodeList(f.get());h.destroy(!0);f.replaceWith(g)}B(d);j.notifyFilterContentUpdated(g);return g.get()}return[]};A.prototype.scanForPartials=function(b){var c=a.parse(b),d=[],e=function(a,b){var c,d;for(c=0;c"==d[0]||"<"==d[0]){b.push(d[1])}if(4=M.cfg.templaterev){return null}var c=h.get("core_template/"+M.cfg.templaterev+":"+a);if(c){q[a]=c;r[a]=b.Deferred().resolve(c).promise();return r[a]}return null},z=function(){if(!u.length){return}if(v){return}v=!0;var a=u.slice(),e=b.Deferred(),f=[],g=a.map(function(a){var c=x(a.component),i=a.name,j=a.searchKey,k=a.theme,l=a.deferred,m=null,n=y(j);if(n){m=n}else{f.push({methodname:"core_output_load_template_with_dependencies",args:{component:c,template:i,themename:k,lang:b("html").attr("lang").replace(/-/g,"_")}});var o=f.length-1;m=e.promise().then(function(a){g[j]=a[o].then(function(a){var b=null;a.templates.forEach(function(a){a.component=x(a.component);var d=[k,a.component,a.name].join("/");q[d]=a.value;if(0=}}$1<%={{ }}=%>").replace(/(\r\n|\r|\n)/g,"
");return"\""+d+"\""};A.prototype.shortenTextHelper=function(a,b,c){var d=b.match(/(.*?),(.*)/),e=d[1].trim(),f=d[2].trim(),g=c(f,a);return m.truncate(g,{length:e,words:!0,ellipsis:"..."})};A.prototype.userDateHelper=function(a,b,c){var d=b.match(/(.*?),(.*)/),e=c(d[1].trim(),a),f=c(d[2].trim(),a),g=this.requiredDates.length;this.requiredDates.push({timestamp:e,format:f});return"[[_t_"+g+"]]"};A.prototype.addHelperFunction=function(a,b){return function(){return function(c,d){var e=w.reduce(function(a,c){if(b.hasOwnProperty(c)){a[c]=b[c]}return a},{});w.forEach(function(a){b[a]=function(){return""}});var f=a.apply(this,[b,c,d]);for(var g in e){b[g]=e[g]}return f}.bind(this)}.bind(this)};A.prototype.addHelpers=function(a,b){this.currentThemeName=b;this.requiredStrings=[];this.requiredJS=[];a.uniqid=p++;a.str=this.addHelperFunction(this.stringHelper,a);a.pix=this.addHelperFunction(this.pixHelper,a);a.js=this.addHelperFunction(this.jsHelper,a);a.quote=this.addHelperFunction(this.quoteHelper,a);a.shortentext=this.addHelperFunction(this.shortenTextHelper,a);a.userdate=this.addHelperFunction(this.userDateHelper,a);a.globals={config:g};a.currentTheme=b};A.prototype.getJS=function(){var a="";if(0").attr("type","text/javascript").html(a);b("head").append(c)}},C=function(a,c,d,e){var f=b(a);if(f.length){var g=b(c),h=null;if(e){h=new k.NodeList(f.children().get());h.destroy(!0);f.empty();f.append(g)}else{h=new k.NodeList(f.get());h.destroy(!0);f.replaceWith(g)}B(d);j.notifyFilterContentUpdated(g);return g.get()}return[]};A.prototype.scanForPartials=function(b){var c=a.parse(b),d=[],e=function(a,b){var c,d;for(c=0;c"==d[0]||"<"==d[0]){b.push(d[1])}if(4.\n\n/**\n * Template renderer for Moodle. Load and render Moodle templates with Mustache.\n *\n * @module core/templates\n * @package core\n * @class templates\n * @copyright 2015 Damyon Wiese \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 2.9\n */\ndefine([\n 'core/mustache',\n 'jquery',\n 'core/ajax',\n 'core/str',\n 'core/notification',\n 'core/url',\n 'core/config',\n 'core/localstorage',\n 'core/icon_system',\n 'core/event',\n 'core/yui',\n 'core/log',\n 'core/truncate',\n 'core/user_date',\n 'core/pending',\n ],\n function(mustache, $, ajax, str, notification, coreurl, config, storage, IconSystem, event, Y, Log, Truncate, UserDate,\n Pending) {\n\n // Module variables.\n /** @var {Number} uniqInstances Count of times this constructor has been called. */\n var uniqInstances = 0;\n\n /** @var {String[]} templateCache - Cache of already loaded template strings */\n var templateCache = {};\n\n /** @var {Promise[]} templatePromises - Cache of already loaded template promises */\n var templatePromises = {};\n\n /** @var {Promise[]} cachePartialPromises - Cache of already loaded template partial promises */\n var cachePartialPromises = {};\n\n /** @var {Object} iconSystem - Object extending core/iconsystem */\n var iconSystem = {};\n\n /** @var {Object[]} loadTemplateBuffer - List of templates to be loaded */\n var loadTemplateBuffer = [];\n\n /** @var {Bool} isLoadingTemplates - Whether templates are currently being loaded */\n var isLoadingTemplates = false;\n\n /** @var {Array} disallowedNestedHelpers - List of helpers that can't be called within other helpers */\n var disallowedNestedHelpers = ['js'];\n\n /**\n * Normalise the provided component such that '', 'moodle', and 'core' are treated consistently.\n *\n * @param {String} component\n * @returns {String}\n */\n var getNormalisedComponent = function(component) {\n if (component) {\n if (component !== 'moodle' && component !== 'core') {\n return component;\n }\n }\n\n return 'core';\n };\n\n /**\n * Search the various caches for a template promise for the given search key.\n * The search key should be in the format // e.g. boost/core/modal.\n *\n * If the template is found in any of the caches it will populate the other caches with\n * the same data as well.\n *\n * @param {String} searchKey The template search key in the format // e.g. boost/core/modal\n * @return {Object} jQuery promise resolved with the template source\n */\n var getTemplatePromiseFromCache = function(searchKey) {\n // First try the cache of promises.\n if (searchKey in templatePromises) {\n return templatePromises[searchKey];\n }\n\n // Check the module cache.\n if (searchKey in templateCache) {\n // Add this to the promises cache for future.\n templatePromises[searchKey] = $.Deferred().resolve(templateCache[searchKey]).promise();\n return templatePromises[searchKey];\n }\n\n if (M.cfg.templaterev <= 0) {\n // Template caching is disabled. Do not store in persistent storage.\n return null;\n }\n\n // Now try local storage.\n var cached = storage.get('core_template/' + M.cfg.templaterev + ':' + searchKey);\n if (cached) {\n // Add this to the module cache for future.\n templateCache[searchKey] = cached;\n // Add this to the promises cache for future.\n templatePromises[searchKey] = $.Deferred().resolve(cached).promise();\n return templatePromises[searchKey];\n }\n\n return null;\n };\n\n /**\n * Take all of the templates waiting in the buffer and load them from the server\n * or from the cache.\n *\n * All of the templates that need to be loaded from the server will be batched up\n * and sent in a single network request.\n */\n var processLoadTemplateBuffer = function() {\n if (!loadTemplateBuffer.length) {\n return;\n }\n\n if (isLoadingTemplates) {\n return;\n }\n\n isLoadingTemplates = true;\n // Grab any templates waiting in the buffer.\n var templatesToLoad = loadTemplateBuffer.slice();\n // This will be resolved with the list of promises for the server request.\n var serverRequestsDeferred = $.Deferred();\n var requests = [];\n // Get a list of promises for each of the templates we need to load.\n var templatePromises = templatesToLoad.map(function(templateData) {\n var component = getNormalisedComponent(templateData.component);\n var name = templateData.name;\n var searchKey = templateData.searchKey;\n var theme = templateData.theme;\n var templateDeferred = templateData.deferred;\n var promise = null;\n\n // Double check to see if this template happened to have landed in the\n // cache as a dependency of an earlier template.\n var cachedPromise = getTemplatePromiseFromCache(searchKey);\n if (cachedPromise) {\n // We've seen this template so immediately resolve the existing promise.\n promise = cachedPromise;\n } else {\n // We haven't seen this template yet so we need to request it from\n // the server.\n requests.push({\n methodname: 'core_output_load_template_with_dependencies',\n args: {\n component: component,\n template: name,\n themename: theme,\n lang: $('html').attr('lang').replace(/-/g, '_')\n }\n });\n // Remember the index in the requests list for this template so that\n // we can get the appropriate promise back.\n var index = requests.length - 1;\n\n // The server deferred will be resolved with a list of all of the promises\n // that were sent in the order that they were added to the requests array.\n promise = serverRequestsDeferred.promise()\n .then(function(promises) {\n // The promise for this template will be the one that matches the index\n // for it's entry in the requests array.\n //\n // Make sure the promise is added to the promises cache for this template\n // search key so that we don't request it again.\n templatePromises[searchKey] = promises[index].then(function(response) {\n var templateSource = null;\n\n // Process all of the template dependencies for this template and add\n // them to the caches so that we don't request them again later.\n response.templates.forEach(function(data) {\n data.component = getNormalisedComponent(data.component);\n // Generate the search key for this template in the response so that we\n // can add it to the caches.\n var tempSearchKey = [theme, data.component, data.name].join('/');\n // Cache all of the dependent templates because we'll need them to render\n // the requested template.\n templateCache[tempSearchKey] = data.value;\n\n if (M.cfg.templaterev > 0) {\n // The template cache is enabled - set the value there.\n storage.set('core_template/' + M.cfg.templaterev + ':' + tempSearchKey, data.value);\n }\n\n if (data.component == component && data.name == name) {\n // This is the original template that was requested so remember it to return.\n templateSource = data.value;\n }\n });\n\n if (response.strings.length) {\n // If we have strings that the template needs then warm the string cache\n // with them now so that we don't need to re-fetch them.\n str.cache_strings(response.strings.map(function(data) {\n return {\n component: getNormalisedComponent(data.component),\n key: data.name,\n value: data.value\n };\n }));\n }\n\n // Return the original template source that the user requested.\n return templateSource;\n });\n\n return templatePromises[searchKey];\n });\n }\n\n return promise\n .then(function(source) {\n // When we've successfully loaded the template then resolve the deferred\n // in the buffer so that all of the calling code can proceed.\n return templateDeferred.resolve(source);\n })\n .catch(function(error) {\n // If there was an error loading the template then reject the deferred\n // in the buffer so that all of the calling code can proceed.\n templateDeferred.reject(error);\n // Rethrow for anyone else listening.\n throw error;\n });\n });\n\n if (requests.length) {\n // We have requests to send so resolve the deferred with the promises.\n serverRequestsDeferred.resolve(ajax.call(requests, true, false, false, 0, M.cfg.templaterev));\n } else {\n // Nothing to load so we can resolve our deferred.\n serverRequestsDeferred.resolve();\n }\n\n // Once we've finished loading all of the templates then recurse to process\n // any templates that may have been added to the buffer in the time that we\n // were fetching.\n $.when.apply(null, templatePromises)\n .then(function() {\n // Remove the templates we've loaded from the buffer.\n loadTemplateBuffer.splice(0, templatesToLoad.length);\n isLoadingTemplates = false;\n processLoadTemplateBuffer();\n return;\n })\n .catch(function() {\n // Remove the templates we've loaded from the buffer.\n loadTemplateBuffer.splice(0, templatesToLoad.length);\n isLoadingTemplates = false;\n processLoadTemplateBuffer();\n });\n };\n\n /**\n * Constructor\n *\n * Each call to templates.render gets it's own instance of this class.\n */\n var Renderer = function() {\n this.requiredStrings = [];\n this.requiredJS = [];\n this.requiredDates = [];\n this.currentThemeName = '';\n };\n // Class variables and functions.\n\n /** @var {string[]} requiredStrings - Collection of strings found during the rendering of one template */\n Renderer.prototype.requiredStrings = null;\n\n /** @var {object[]} requiredDates - Collection of dates found during the rendering of one template */\n Renderer.prototype.requiredDates = [];\n\n /** @var {string[]} requiredJS - Collection of js blocks found during the rendering of one template */\n Renderer.prototype.requiredJS = null;\n\n /** @var {String} themeName for the current render */\n Renderer.prototype.currentThemeName = '';\n\n /**\n * Load a template.\n *\n * @method getTemplate\n * @private\n * @param {string} templateName - should consist of the component and the name of the template like this:\n * core/menu (lib/templates/menu.mustache) or\n * tool_bananas/yellow (admin/tool/bananas/templates/yellow.mustache)\n * @return {Promise} JQuery promise object resolved when the template has been fetched.\n */\n Renderer.prototype.getTemplate = function(templateName) {\n var currentTheme = this.currentThemeName;\n var searchKey = currentTheme + '/' + templateName;\n\n // If we haven't already seen this template then buffer it.\n var cachedPromise = getTemplatePromiseFromCache(searchKey);\n if (cachedPromise) {\n return cachedPromise;\n }\n\n // Check the buffer to see if this template has already been added.\n var existingBufferRecords = loadTemplateBuffer.filter(function(record) {\n return record.searchKey == searchKey;\n });\n if (existingBufferRecords.length) {\n // This template is already in the buffer so just return the existing\n // promise. No need to add it to the buffer again.\n return existingBufferRecords[0].deferred.promise();\n }\n\n // This is the first time this has been requested so let's add it to the buffer\n // to be loaded.\n var parts = templateName.split('/');\n var component = getNormalisedComponent(parts.shift());\n var name = parts.join('/');\n var deferred = $.Deferred();\n\n // Add this template to the buffer to be loaded.\n loadTemplateBuffer.push({\n component: component,\n name: name,\n theme: currentTheme,\n searchKey: searchKey,\n deferred: deferred\n });\n\n // We know there is at least one thing in the buffer so kick off a processing run.\n processLoadTemplateBuffer();\n return deferred.promise();\n };\n\n /**\n * Prefetch a set of templates without rendering them.\n *\n * @param {Array} templateNames The list of templates to fetch\n * @param {String} currentTheme\n */\n Renderer.prototype.prefetchTemplates = function(templateNames, currentTheme) {\n templateNames.forEach(function(templateName) {\n var searchKey = currentTheme + '/' + templateName;\n\n // If we haven't already seen this template then buffer it.\n if (getTemplatePromiseFromCache(searchKey)) {\n return;\n }\n\n // Check the buffer to see if this template has already been added.\n var existingBufferRecords = loadTemplateBuffer.filter(function(record) {\n return record.searchKey == searchKey;\n });\n\n if (existingBufferRecords.length) {\n // This template is already in the buffer so just return the existing promise.\n // No need to add it to the buffer again.\n return;\n }\n\n // This is the first time this has been requested so let's add it to the buffer to be loaded.\n var parts = templateName.split('/');\n var component = getNormalisedComponent(parts.shift());\n var name = parts.join('/');\n\n // Add this template to the buffer to be loaded.\n loadTemplateBuffer.push({\n component: component,\n name: name,\n theme: currentTheme,\n searchKey: searchKey,\n deferred: $.Deferred(),\n });\n });\n\n processLoadTemplateBuffer();\n };\n\n /**\n * Load a partial from the cache or ajax.\n *\n * @method partialHelper\n * @private\n * @param {string} name The partial name to load.\n * @return {string}\n */\n Renderer.prototype.partialHelper = function(name) {\n\n var searchKey = this.currentThemeName + '/' + name;\n\n if (!(searchKey in templateCache)) {\n notification.exception(new Error('Failed to pre-fetch the template: ' + name));\n }\n\n return templateCache[searchKey];\n };\n\n /**\n * Render a single image icon.\n *\n * @method renderIcon\n * @private\n * @param {string} key The icon key.\n * @param {string} component The component name.\n * @param {string} title The icon title\n * @return {Promise}\n */\n Renderer.prototype.renderIcon = function(key, component, title) {\n // Preload the module to do the icon rendering based on the theme iconsystem.\n var modulename = config.iconsystemmodule;\n component = getNormalisedComponent(component);\n\n // RequireJS does not return a promise.\n var ready = $.Deferred();\n require([modulename], function(System) {\n var system = new System();\n if (!(system instanceof IconSystem)) {\n ready.reject('Invalid icon system specified' + config.iconsystemmodule);\n } else {\n iconSystem = system;\n system.init().then(ready.resolve).catch(notification.exception);\n }\n });\n\n return ready.then(function(iconSystem) {\n return this.getTemplate(iconSystem.getTemplateName());\n }.bind(this)).then(function(template) {\n return iconSystem.renderIcon(\n key,\n component,\n title,\n template\n );\n });\n };\n\n /**\n * Render image icons.\n *\n * @method pixHelper\n * @private\n * @param {object} context The mustache context\n * @param {string} sectionText The text to parse arguments from.\n * @param {function} helper Used to render the alt attribute of the text.\n * @return {string}\n */\n Renderer.prototype.pixHelper = function(context, sectionText, helper) {\n var parts = sectionText.split(',');\n var key = '';\n var component = '';\n var text = '';\n\n if (parts.length > 0) {\n key = helper(parts.shift().trim(), context);\n }\n if (parts.length > 0) {\n component = helper(parts.shift().trim(), context);\n }\n if (parts.length > 0) {\n text = helper(parts.join(',').trim(), context);\n }\n\n var templateName = iconSystem.getTemplateName();\n var searchKey = this.currentThemeName + '/' + templateName;\n var template = templateCache[searchKey];\n\n component = getNormalisedComponent(component);\n\n // The key might have been escaped by the JS Mustache engine which\n // converts forward slashes to HTML entities. Let us undo that here.\n key = key.replace(///gi, '/');\n\n return iconSystem.renderIcon(\n key,\n component,\n text,\n template\n );\n };\n\n /**\n * Render blocks of javascript and save them in an array.\n *\n * @method jsHelper\n * @private\n * @param {object} context The current mustache context.\n * @param {string} sectionText The text to save as a js block.\n * @param {function} helper Used to render the block.\n * @return {string}\n */\n Renderer.prototype.jsHelper = function(context, sectionText, helper) {\n this.requiredJS.push(helper(sectionText, context));\n return '';\n };\n\n /**\n * String helper used to render {{#str}}abd component { a : 'fish'}{{/str}}\n * into a get_string call.\n *\n * @method stringHelper\n * @private\n * @param {object} context The current mustache context.\n * @param {string} sectionText The text to parse the arguments from.\n * @param {function} helper Used to render subsections of the text.\n * @return {string}\n */\n Renderer.prototype.stringHelper = function(context, sectionText, helper) {\n var parts = sectionText.split(',');\n var key = '';\n var component = '';\n var param = '';\n if (parts.length > 0) {\n key = parts.shift().trim();\n }\n if (parts.length > 0) {\n component = parts.shift().trim();\n }\n if (parts.length > 0) {\n param = parts.join(',').trim();\n }\n\n component = getNormalisedComponent(component);\n\n if (param !== '') {\n // Allow variable expansion in the param part only.\n param = helper(param, context);\n }\n // Allow json formatted $a arguments.\n if ((param.indexOf('{') === 0) && (param.indexOf('{{') !== 0)) {\n param = JSON.parse(param);\n }\n\n var index = this.requiredStrings.length;\n this.requiredStrings.push({\n key: key,\n component: component,\n param: param\n });\n\n // The placeholder must not use {{}} as those can be misinterpreted by the engine.\n return '[[_s' + index + ']]';\n };\n\n /**\n * Quote helper used to wrap content in quotes, and escape all quotes present in the content.\n *\n * @method quoteHelper\n * @private\n * @param {object} context The current mustache context.\n * @param {string} sectionText The text to parse the arguments from.\n * @param {function} helper Used to render subsections of the text.\n * @return {string}\n */\n Renderer.prototype.quoteHelper = function(context, sectionText, helper) {\n var content = helper(sectionText.trim(), context);\n\n // Escape the {{ and the \".\n // This involves wrapping {{, and }} in change delimeter tags.\n content = content\n .replace(/\"/g, '\\\\\"')\n .replace(/\\t/g, ' ')\n .replace(/([{}]{2,3})/g, '{{=<% %>=}}$1<%={{ }}=%>')\n .replace(/(\\r\\n|\\r|\\n)/g, '
')\n ;\n return '\"' + content + '\"';\n };\n\n /**\n * Shorten text helper to truncate text and append a trailing ellipsis.\n *\n * @method shortenTextHelper\n * @private\n * @param {object} context The current mustache context.\n * @param {string} sectionText The text to parse the arguments from.\n * @param {function} helper Used to render subsections of the text.\n * @return {string}\n */\n Renderer.prototype.shortenTextHelper = function(context, sectionText, helper) {\n // Non-greedy split on comma to grab section text into the length and\n // text parts.\n var regex = /(.*?),(.*)/;\n var parts = sectionText.match(regex);\n // The length is the part matched in the first set of parethesis.\n var length = parts[1].trim();\n // The length is the part matched in the second set of parethesis.\n var text = parts[2].trim();\n var content = helper(text, context);\n return Truncate.truncate(content, {\n length: length,\n words: true,\n ellipsis: '...'\n });\n };\n\n /**\n * User date helper to render user dates from timestamps.\n *\n * @method userDateHelper\n * @private\n * @param {object} context The current mustache context.\n * @param {string} sectionText The text to parse the arguments from.\n * @param {function} helper Used to render subsections of the text.\n * @return {string}\n */\n Renderer.prototype.userDateHelper = function(context, sectionText, helper) {\n // Non-greedy split on comma to grab the timestamp and format.\n var regex = /(.*?),(.*)/;\n var parts = sectionText.match(regex);\n var timestamp = helper(parts[1].trim(), context);\n var format = helper(parts[2].trim(), context);\n var index = this.requiredDates.length;\n\n this.requiredDates.push({\n timestamp: timestamp,\n format: format\n });\n\n return '[[_t_' + index + ']]';\n };\n\n /**\n * Return a helper function to be added to the context for rendering the a\n * template.\n *\n * This will parse the provided text before giving it to the helper function\n * in order to remove any disallowed nested helpers to prevent one helper\n * from calling another.\n *\n * In particular to prevent the JS helper from being called from within another\n * helper because it can lead to security issues when the JS portion is user\n * provided.\n *\n * @param {function} helperFunction The helper function to add\n * @param {object} context The template context for the helper function\n * @return {Function} To be set in the context\n */\n Renderer.prototype.addHelperFunction = function(helperFunction, context) {\n return function() {\n return function(sectionText, helper) {\n // Override the disallowed helpers in the template context with\n // a function that returns an empty string for use when executing\n // other helpers. This is to prevent these helpers from being\n // executed as part of the rendering of another helper in order to\n // prevent any potential security issues.\n var originalHelpers = disallowedNestedHelpers.reduce(function(carry, name) {\n if (context.hasOwnProperty(name)) {\n carry[name] = context[name];\n }\n\n return carry;\n }, {});\n\n disallowedNestedHelpers.forEach(function(helperName) {\n context[helperName] = function() {\n return '';\n };\n });\n\n // Execute the helper with the modified context that doesn't include\n // the disallowed nested helpers. This prevents the disallowed\n // helpers from being called from within other helpers.\n var result = helperFunction.apply(this, [context, sectionText, helper]);\n\n // Restore the original helper implementation in the context so that\n // any further rendering has access to them again.\n for (var name in originalHelpers) {\n context[name] = originalHelpers[name];\n }\n\n return result;\n }.bind(this);\n }.bind(this);\n };\n\n /**\n * Add some common helper functions to all context objects passed to templates.\n * These helpers match exactly the helpers available in php.\n *\n * @method addHelpers\n * @private\n * @param {Object} context Simple types used as the context for the template.\n * @param {String} themeName We set this multiple times, because there are async calls.\n */\n Renderer.prototype.addHelpers = function(context, themeName) {\n this.currentThemeName = themeName;\n this.requiredStrings = [];\n this.requiredJS = [];\n context.uniqid = (uniqInstances++);\n context.str = this.addHelperFunction(this.stringHelper, context);\n context.pix = this.addHelperFunction(this.pixHelper, context);\n context.js = this.addHelperFunction(this.jsHelper, context);\n context.quote = this.addHelperFunction(this.quoteHelper, context);\n context.shortentext = this.addHelperFunction(this.shortenTextHelper, context);\n context.userdate = this.addHelperFunction(this.userDateHelper, context);\n context.globals = {config: config};\n context.currentTheme = themeName;\n };\n\n /**\n * Get all the JS blocks from the last rendered template.\n *\n * @method getJS\n * @private\n * @return {string}\n */\n Renderer.prototype.getJS = function() {\n var js = '';\n if (this.requiredJS.length > 0) {\n js = this.requiredJS.join(\";\\n\");\n }\n\n return js;\n };\n\n /**\n * Treat strings in content.\n *\n * The purpose of this method is to replace the placeholders found in a string\n * with the their respective translated strings.\n *\n * Previously we were relying on String.replace() but the complexity increased with\n * the numbers of strings to replace. Now we manually walk the string and stop at each\n * placeholder we find, only then we replace it. Most of the time we will\n * replace all the placeholders in a single run, at times we will need a few\n * more runs when placeholders are replaced with strings that contain placeholders\n * themselves.\n *\n * @param {String} content The content in which string placeholders are to be found.\n * @param {Array} strings The strings to replace with.\n * @return {String} The treated content.\n */\n Renderer.prototype.treatStringsInContent = function(content, strings) {\n var pattern = /\\[\\[_s\\d+\\]\\]/,\n treated,\n index,\n strIndex,\n walker,\n char,\n strFinal;\n\n do {\n treated = '';\n index = content.search(pattern);\n while (index > -1) {\n\n // Copy the part prior to the placeholder to the treated string.\n treated += content.substring(0, index);\n content = content.substr(index);\n strIndex = '';\n walker = 4; // 4 is the length of '[[_s'.\n\n // Walk the characters to manually extract the index of the string from the placeholder.\n char = content.substr(walker, 1);\n do {\n strIndex += char;\n walker++;\n char = content.substr(walker, 1);\n } while (char != ']');\n\n // Get the string, add it to the treated result, and remove the placeholder from the content to treat.\n strFinal = strings[parseInt(strIndex, 10)];\n if (typeof strFinal === 'undefined') {\n Log.debug('Could not find string for pattern [[_s' + strIndex + ']].');\n strFinal = '';\n }\n treated += strFinal;\n content = content.substr(6 + strIndex.length); // 6 is the length of the placeholder without the index: '[[_s]]'.\n\n // Find the next placeholder.\n index = content.search(pattern);\n }\n\n // The content becomes the treated part with the rest of the content.\n content = treated + content;\n\n // Check if we need to walk the content again, in case strings contained placeholders.\n index = content.search(pattern);\n\n } while (index > -1);\n\n return content;\n };\n\n /**\n * Treat strings in content.\n *\n * The purpose of this method is to replace the date placeholders found in the\n * content with the their respective translated dates.\n *\n * @param {String} content The content in which string placeholders are to be found.\n * @param {Array} dates The dates to replace with.\n * @return {String} The treated content.\n */\n Renderer.prototype.treatDatesInContent = function(content, dates) {\n dates.forEach(function(date, index) {\n var key = '\\\\[\\\\[_t_' + index + '\\\\]\\\\]';\n var re = new RegExp(key, 'g');\n content = content.replace(re, date);\n });\n\n return content;\n };\n\n /**\n * Render a template and then call the callback with the result.\n *\n * @method doRender\n * @private\n * @param {string} templateSource The mustache template to render.\n * @param {Object} context Simple types used as the context for the template.\n * @param {String} themeName Name of the current theme.\n * @return {Promise} object\n */\n Renderer.prototype.doRender = function(templateSource, context, themeName) {\n this.currentThemeName = themeName;\n var iconTemplate = iconSystem.getTemplateName();\n\n var pendingPromise = new Pending('core/templates:doRender');\n return this.getTemplate(iconTemplate).then(function() {\n this.addHelpers(context, themeName);\n var result = mustache.render(templateSource, context, this.partialHelper.bind(this));\n return $.Deferred().resolve(result.trim(), this.getJS()).promise();\n }.bind(this))\n .then(function(html, js) {\n if (this.requiredStrings.length > 0) {\n return str.get_strings(this.requiredStrings).then(function(strings) {\n\n // Make sure string substitutions are done for the userdate\n // values as well.\n this.requiredDates = this.requiredDates.map(function(date) {\n return {\n timestamp: this.treatStringsInContent(date.timestamp, strings),\n format: this.treatStringsInContent(date.format, strings)\n };\n }.bind(this));\n\n // Why do we not do another call the render here?\n //\n // Because that would expose DOS holes. E.g.\n // I create an assignment called \"{{fish\" which\n // would get inserted in the template in the first pass\n // and cause the template to die on the second pass (unbalanced).\n html = this.treatStringsInContent(html, strings);\n js = this.treatStringsInContent(js, strings);\n return $.Deferred().resolve(html, js).promise();\n }.bind(this));\n }\n\n return $.Deferred().resolve(html, js).promise();\n }.bind(this))\n .then(function(html, js) {\n // This has to happen after the strings replacement because you can\n // use the string helper in content for the user date helper.\n if (this.requiredDates.length > 0) {\n return UserDate.get(this.requiredDates).then(function(dates) {\n html = this.treatDatesInContent(html, dates);\n js = this.treatDatesInContent(js, dates);\n return $.Deferred().resolve(html, js).promise();\n }.bind(this));\n }\n\n return $.Deferred().resolve(html, js).promise();\n }.bind(this))\n .then(function(html, js) {\n pendingPromise.resolve();\n return $.Deferred().resolve(html, js).promise();\n });\n };\n\n /**\n * Execute a block of JS returned from a template.\n * Call this AFTER adding the template HTML into the DOM so the nodes can be found.\n *\n * @method runTemplateJS\n * @param {string} source - A block of javascript.\n */\n var runTemplateJS = function(source) {\n if (source.trim() !== '') {\n var newscript = $('