diff --git a/filter/amd/build/events.min.js b/filter/amd/build/events.min.js index 1e8bb8b1fbd..67d07e4ad23 100644 --- a/filter/amd/build/events.min.js +++ b/filter/amd/build/events.min.js @@ -13,6 +13,6 @@ define("core_filters/events",["exports","core/event_dispatcher","core/normalise" * document.addEventListener(filterEventTypes.filterContentUpdated, e => { * window.console.log(e.detail.nodes); // A list of the HTMLElements whose content was updated * }); - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.notifyFilterContentUpdated=_exports.eventTypes=void 0,_jquery=(obj=_jquery)&&obj.__esModule?obj:{default:obj};const eventTypes={filterContentUpdated:"core_filters/contentUpdated"};_exports.eventTypes=eventTypes;_exports.notifyFilterContentUpdated=nodes=>(nodes=(0,_normalise.getList)(nodes),(0,_event_dispatcher.dispatchEvent)(eventTypes.filterContentUpdated,{nodes:nodes}));let legacyEventsRegistered=!1;legacyEventsRegistered||(Y.use("event","moodle-core-event",(()=>{document.addEventListener(eventTypes.filterContentUpdated,(e=>{(0,_jquery.default)(document).trigger(M.core.event.FILTER_CONTENT_UPDATED,[(0,_jquery.default)(e.detail.nodes)]),Y.fire(M.core.event.FILTER_CONTENT_UPDATED,{nodes:new Y.NodeList(e.detail.nodes)})}))})),legacyEventsRegistered=!0)})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.notifyFilterContentUpdated=_exports.notifyFilterContentRenderingComplete=_exports.eventTypes=void 0,_jquery=(obj=_jquery)&&obj.__esModule?obj:{default:obj};const eventTypes={filterContentUpdated:"core_filters/contentUpdated",filterContentRenderingComplete:"core_filters/contentRenderingComplete"};_exports.eventTypes=eventTypes;_exports.notifyFilterContentUpdated=nodes=>(nodes=(0,_normalise.getList)(nodes),(0,_event_dispatcher.dispatchEvent)(eventTypes.filterContentUpdated,{nodes:nodes}));_exports.notifyFilterContentRenderingComplete=nodes=>(0,_event_dispatcher.dispatchEvent)(eventTypes.filterContentRenderingComplete,{nodes:nodes});let legacyEventsRegistered=!1;legacyEventsRegistered||(Y.use("event","moodle-core-event",(()=>{document.addEventListener(eventTypes.filterContentUpdated,(e=>{(0,_jquery.default)(document).trigger(M.core.event.FILTER_CONTENT_UPDATED,[(0,_jquery.default)(e.detail.nodes)]),Y.fire(M.core.event.FILTER_CONTENT_UPDATED,{nodes:new Y.NodeList(e.detail.nodes)})}))})),legacyEventsRegistered=!0)})); //# sourceMappingURL=events.min.js.map \ No newline at end of file diff --git a/filter/amd/build/events.min.js.map b/filter/amd/build/events.min.js.map index 2e5998d362e..108e0ff59a0 100644 --- a/filter/amd/build/events.min.js.map +++ b/filter/amd/build/events.min.js.map @@ -1 +1 @@ -{"version":3,"file":"events.min.js","sources":["../src/events.js"],"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_filters` 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 * @example Example of listening to a filter event.\n * import {eventTypes as filterEventTypes} from 'core_filters/events';\n *\n * document.addEventListener(filterEventTypes.filterContentUpdated, e => {\n * window.console.log(e.detail.nodes); // A list of the HTMLElements whose content was updated\n * });\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_filters` 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 {object} detail\n * @property {NodeElement[]} detail.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"],"names":["eventTypes","filterContentUpdated","nodes","legacyEventsRegistered","Y","use","document","addEventListener","e","trigger","M","core","event","FILTER_CONTENT_UPDATED","detail","fire","NodeList"],"mappings":";;;;;;;;;;;;;;;0LAwCaA,WAAa,CAYtBC,qBAAsB,kGAWgBC,QAGtCA,OAAQ,sBAAkBA,QAEnB,mCAAcF,WAAWC,qBAAsB,CAACC,MAAAA,aAGvDC,wBAAyB,EACxBA,yBAKDC,EAAEC,IAAI,QAAS,qBAAqB,KAEhCC,SAASC,iBAAiBP,WAAWC,sBAAsBO,wBAEhDF,UAAUG,QAAQC,EAAEC,KAAKC,MAAMC,uBAAwB,EAAC,mBAAOL,EAAEM,OAAOZ,SAG/EE,EAAEW,KAAKL,EAAEC,KAAKC,MAAMC,uBAAwB,CAACX,MAAO,IAAIE,EAAEY,SAASR,EAAEM,OAAOZ,eAIpFC,wBAAyB"} \ No newline at end of file +{"version":3,"file":"events.min.js","sources":["../src/events.js"],"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_filters` 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 * @example Example of listening to a filter event.\n * import {eventTypes as filterEventTypes} from 'core_filters/events';\n *\n * document.addEventListener(filterEventTypes.filterContentUpdated, e => {\n * window.console.log(e.detail.nodes); // A list of the HTMLElements whose content was updated\n * });\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_filters` subsystem.\n *\n * @constant\n * @property {String} filterContentUpdated See {@link event:filterContentUpdated}\n * @property {String} filterContentRenderingComplete See {@link event:filterContentRenderingComplete}\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 {object} detail\n * @property {NodeElement[]} detail.nodes The list of parent nodes which were updated\n */\n filterContentUpdated: 'core_filters/contentUpdated',\n\n /**\n * An event triggered when filter system have done rendering the content using the filter system.\n *\n * @event filterContentRenderingComplete\n * @type {CustomEvent}\n * @property {object} detail\n */\n filterContentRenderingComplete: 'core_filters/contentRenderingComplete',\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\n/**\n * Trigger an event to indicate that the filter has been processed.\n *\n * @method notifyFilterContentRenderingComplete\n * @param {NodeList|Node[]} nodes List of nodes that has been modified by filter\n * @returns {CustomEvent}\n * @fires filterContentRenderingComplete\n */\nexport const notifyFilterContentRenderingComplete = nodes => {\n return dispatchEvent(eventTypes.filterContentRenderingComplete, {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"],"names":["eventTypes","filterContentUpdated","filterContentRenderingComplete","nodes","legacyEventsRegistered","Y","use","document","addEventListener","e","trigger","M","core","event","FILTER_CONTENT_UPDATED","detail","fire","NodeList"],"mappings":";;;;;;;;;;;;;;;wOAyCaA,WAAa,CAYtBC,qBAAsB,8BAStBC,+BAAgC,4GAWMC,QAGtCA,OAAQ,sBAAkBA,QAEnB,mCAAcH,WAAWC,qBAAsB,CAACE,MAAAA,uDAWPA,QACzC,mCAAcH,WAAWE,+BAAgC,CAACC,MAAAA,YAGjEC,wBAAyB,EACxBA,yBAKDC,EAAEC,IAAI,QAAS,qBAAqB,KAEhCC,SAASC,iBAAiBR,WAAWC,sBAAsBQ,wBAEhDF,UAAUG,QAAQC,EAAEC,KAAKC,MAAMC,uBAAwB,EAAC,mBAAOL,EAAEM,OAAOZ,SAG/EE,EAAEW,KAAKL,EAAEC,KAAKC,MAAMC,uBAAwB,CAACX,MAAO,IAAIE,EAAEY,SAASR,EAAEM,OAAOZ,eAIpFC,wBAAyB"} \ No newline at end of file diff --git a/filter/amd/src/events.js b/filter/amd/src/events.js index 5360ad7fcf5..614520ea534 100644 --- a/filter/amd/src/events.js +++ b/filter/amd/src/events.js @@ -37,6 +37,7 @@ import jQuery from 'jquery'; * * @constant * @property {String} filterContentUpdated See {@link event:filterContentUpdated} + * @property {String} filterContentRenderingComplete See {@link event:filterContentRenderingComplete} */ export const eventTypes = { /** @@ -51,6 +52,15 @@ export const eventTypes = { * @property {NodeElement[]} detail.nodes The list of parent nodes which were updated */ filterContentUpdated: 'core_filters/contentUpdated', + + /** + * An event triggered when filter system have done rendering the content using the filter system. + * + * @event filterContentRenderingComplete + * @type {CustomEvent} + * @property {object} detail + */ + filterContentRenderingComplete: 'core_filters/contentRenderingComplete', }; /** @@ -69,6 +79,18 @@ export const notifyFilterContentUpdated = nodes => { return dispatchEvent(eventTypes.filterContentUpdated, {nodes}); }; +/** + * Trigger an event to indicate that the filter has been processed. + * + * @method notifyFilterContentRenderingComplete + * @param {NodeList|Node[]} nodes List of nodes that has been modified by filter + * @returns {CustomEvent} + * @fires filterContentRenderingComplete + */ +export const notifyFilterContentRenderingComplete = nodes => { + return dispatchEvent(eventTypes.filterContentRenderingComplete, {nodes}); +}; + let legacyEventsRegistered = false; if (!legacyEventsRegistered) { // The following event triggers are legacy and will be removed in the future. diff --git a/lib/upgrade.txt b/lib/upgrade.txt index e098f559b6b..0839f57dd39 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -139,6 +139,7 @@ being forced open in all behat tests. * A new parameter $loginrecaptcha has been added to the authenticate_user_login() to check whether the login captcha is needed to verify or not. The default value is false. * A new parameter $compactmode has been added to the recaptcha_get_challenge_html() to define whether the reCaptcha element should be displayed in the compact mode or not. Default value is false. +* A new native event in the `core_filters/events` AMD module eventTypes.filterContentRenderingComplete has been created to determine when the filter is complete the rendering. === 4.2 ===