From 80c9de3d0040eeaeae5769ae596c011a2a822f5e Mon Sep 17 00:00:00 2001 From: hieuvu Date: Fri, 18 Aug 2023 10:00:03 +0700 Subject: [PATCH] MDL-79039 mathjax: Re-write yui javascript to AMD module --- filter/mathjaxloader/amd/build/loader.min.js | 11 ++ .../mathjaxloader/amd/build/loader.min.js.map | 1 + filter/mathjaxloader/amd/src/loader.js | 123 ++++++++++++++++ filter/mathjaxloader/filter.php | 11 +- ...oodle-filter_mathjaxloader-loader-debug.js | 137 ------------------ .../moodle-filter_mathjaxloader-loader-min.js | 1 - .../moodle-filter_mathjaxloader-loader.js | 137 ------------------ .../mathjaxloader/yui/src/loader/build.json | 10 -- .../mathjaxloader/yui/src/loader/js/loader.js | 132 ----------------- .../yui/src/loader/meta/loader.json | 7 - filter/upgrade.txt | 2 + 11 files changed, 140 insertions(+), 432 deletions(-) create mode 100644 filter/mathjaxloader/amd/build/loader.min.js create mode 100644 filter/mathjaxloader/amd/build/loader.min.js.map create mode 100644 filter/mathjaxloader/amd/src/loader.js delete mode 100644 filter/mathjaxloader/yui/build/moodle-filter_mathjaxloader-loader/moodle-filter_mathjaxloader-loader-debug.js delete mode 100644 filter/mathjaxloader/yui/build/moodle-filter_mathjaxloader-loader/moodle-filter_mathjaxloader-loader-min.js delete mode 100644 filter/mathjaxloader/yui/build/moodle-filter_mathjaxloader-loader/moodle-filter_mathjaxloader-loader.js delete mode 100644 filter/mathjaxloader/yui/src/loader/build.json delete mode 100644 filter/mathjaxloader/yui/src/loader/js/loader.js delete mode 100644 filter/mathjaxloader/yui/src/loader/meta/loader.json diff --git a/filter/mathjaxloader/amd/build/loader.min.js b/filter/mathjaxloader/amd/build/loader.min.js new file mode 100644 index 00000000000..fc7e9648903 --- /dev/null +++ b/filter/mathjaxloader/amd/build/loader.min.js @@ -0,0 +1,11 @@ +define("filter_mathjaxloader/loader",["exports","core_filters/events"],(function(_exports,_events){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.typeset=_exports.contentUpdated=_exports.configure=void 0; +/** + * Mathjax JS Loader. + * + * @module filter_mathjaxloader + * @copyright 2014 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +let lang="",configured=!1;_exports.configure=params=>{let script=document.createElement("script");script.type="text/x-mathjax-config",script[window.opera?"innerHTML":"text"]=params.mathjaxconfig,document.getElementsByTagName("head")[0].appendChild(script),lang=params.lang,document.addEventListener(_events.eventTypes.filterContentUpdated,contentUpdated)};const setLocale=()=>{configured||void 0!==window.MathJax&&(window.MathJax.Hub.Queue((function(){window.MathJax.Localization.setLocale(lang)})),window.MathJax.Hub.Configured(),configured=!0)};_exports.typeset=()=>{if(!configured){setLocale();const elements=document.getElementsByClassName("filter_mathjaxloader_equation");for(let i=0;i{if(void 0===window.MathJax)return;const processdelay=window.MathJax.Hub.processSectionDelay;window.MathJax.Hub.processSectionDelay=0,window.MathJax.Hub.Config({positionToHash:!1}),setLocale(),event.detail.nodes.forEach((node=>{node.querySelectorAll(".filter_mathjaxloader_equation").forEach((node=>{window.MathJax.Hub.Queue(["Typeset",window.MathJax.Hub,node])}))})),window.MathJax.Hub.processSectionDelay=processdelay};_exports.contentUpdated=contentUpdated})); + +//# sourceMappingURL=loader.min.js.map \ No newline at end of file diff --git a/filter/mathjaxloader/amd/build/loader.min.js.map b/filter/mathjaxloader/amd/build/loader.min.js.map new file mode 100644 index 00000000000..33709adae67 --- /dev/null +++ b/filter/mathjaxloader/amd/build/loader.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"loader.min.js","sources":["../src/loader.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 * Mathjax JS Loader.\n *\n * @module filter_mathjaxloader\n * @copyright 2014 Damyon Wiese \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport {eventTypes} from 'core_filters/events';\n\n/**\n * The users current language - this can't be set until MathJax is loaded - so we need to store it.\n * @property {string} lang\n * @default ''\n * @private\n */\nlet lang = '';\n\n/**\n * Used to prevent configuring MathJax twice.\n * @property {boolean} configured\n * @default false\n * @private\n */\nlet configured = false;\n\n/**\n * Called by the filter when it is active on any page.\n * This does not load MathJAX yet - it addes the configuration to the head incase it gets loaded later.\n * It also subscribes to the filter-content-updated event so MathJax can respond to content loaded by Ajax.\n *\n * @method configure\n * @param {Object} params List of configuration params containing mathjaxconfig (text) and lang\n */\nexport const configure = (params) => {\n // Add a js configuration object to the head.\n // See \"http://docs.mathjax.org/en/latest/dynamic.html#ajax-mathjax\"\n let script = document.createElement(\"script\");\n script.type = \"text/x-mathjax-config\";\n script[(window.opera ? \"innerHTML\" : \"text\")] = params.mathjaxconfig;\n document.getElementsByTagName(\"head\")[0].appendChild(script);\n\n // Save the lang config until MathJax is actually loaded.\n lang = params.lang;\n\n // Listen for events triggered when new text is added to a page that needs\n // processing by a filter.\n document.addEventListener(eventTypes.filterContentUpdated, contentUpdated);\n};\n\n/**\n * Set the correct language for the MathJax menus. Only do this once.\n *\n * @method setLocale\n * @private\n */\nconst setLocale = () => {\n if (!configured) {\n if (typeof window.MathJax !== \"undefined\") {\n window.MathJax.Hub.Queue(function() {\n window.MathJax.Localization.setLocale(lang);\n });\n window.MathJax.Hub.Configured();\n configured = true;\n }\n }\n};\n\n/**\n * Called by the filter when an equation is found while rendering the page.\n *\n * @method typeset\n */\nexport const typeset = () => {\n if (!configured) {\n setLocale();\n const elements = document.getElementsByClassName('filter_mathjaxloader_equation');\n for (let i = 0; i < elements.length; i++) {\n if (typeof window.MathJax !== \"undefined\") {\n window.MathJax.Hub.Queue([\"Typeset\", window.MathJax.Hub, elements[i]]);\n }\n }\n }\n};\n\n/**\n * Handle content updated events - typeset the new content.\n *\n * @method contentUpdated\n * @param {CustomEvent} event - Custom event with \"nodes\" indicating the root of the updated nodes.\n */\nexport const contentUpdated = (event) => {\n if (typeof window.MathJax === \"undefined\") {\n return;\n }\n const processdelay = window.MathJax.Hub.processSectionDelay;\n // Set the process section delay to 0 when updating the formula.\n window.MathJax.Hub.processSectionDelay = 0;\n // When content is updated never position to hash, it may cause unexpected document scrolling.\n window.MathJax.Hub.Config({positionToHash: false});\n setLocale();\n // The list of HTMLElements in an Array.\n event.detail.nodes.forEach((node) => {\n const mathjaxElements = node.querySelectorAll('.filter_mathjaxloader_equation');\n mathjaxElements.forEach((node) => {\n window.MathJax.Hub.Queue([\"Typeset\", window.MathJax.Hub, node]);\n });\n });\n window.MathJax.Hub.processSectionDelay = processdelay;\n};\n"],"names":["lang","configured","params","script","document","createElement","type","window","opera","mathjaxconfig","getElementsByTagName","appendChild","addEventListener","eventTypes","filterContentUpdated","contentUpdated","setLocale","MathJax","Hub","Queue","Localization","Configured","elements","getElementsByClassName","i","length","event","processdelay","processSectionDelay","Config","positionToHash","detail","nodes","forEach","node","querySelectorAll"],"mappings":";;;;;;;;IA6BIA,KAAO,GAQPC,YAAa,qBAUSC,aAGlBC,OAASC,SAASC,cAAc,UACpCF,OAAOG,KAAO,wBACdH,OAAQI,OAAOC,MAAQ,YAAc,QAAWN,OAAOO,cACvDL,SAASM,qBAAqB,QAAQ,GAAGC,YAAYR,QAGrDH,KAAOE,OAAOF,KAIdI,SAASQ,iBAAiBC,mBAAWC,qBAAsBC,uBASzDC,UAAY,KACTf,iBAC6B,IAAnBM,OAAOU,UACdV,OAAOU,QAAQC,IAAIC,OAAM,WACrBZ,OAAOU,QAAQG,aAAaJ,UAAUhB,SAE1CO,OAAOU,QAAQC,IAAIG,aACnBpB,YAAa,qBAUF,SACdA,WAAY,CACbe,kBACMM,SAAWlB,SAASmB,uBAAuB,qCAC5C,IAAIC,EAAI,EAAGA,EAAIF,SAASG,OAAQD,SACH,IAAnBjB,OAAOU,SACdV,OAAOU,QAAQC,IAAIC,MAAM,CAAC,UAAWZ,OAAOU,QAAQC,IAAKI,SAASE,aAYrET,eAAkBW,gBACG,IAAnBnB,OAAOU,qBAGZU,aAAepB,OAAOU,QAAQC,IAAIU,oBAExCrB,OAAOU,QAAQC,IAAIU,oBAAsB,EAEzCrB,OAAOU,QAAQC,IAAIW,OAAO,CAACC,gBAAgB,IAC3Cd,YAEAU,MAAMK,OAAOC,MAAMC,SAASC,OACAA,KAAKC,iBAAiB,kCAC9BF,SAASC,OACrB3B,OAAOU,QAAQC,IAAIC,MAAM,CAAC,UAAWZ,OAAOU,QAAQC,IAAKgB,aAGjE3B,OAAOU,QAAQC,IAAIU,oBAAsBD"} \ No newline at end of file diff --git a/filter/mathjaxloader/amd/src/loader.js b/filter/mathjaxloader/amd/src/loader.js new file mode 100644 index 00000000000..a3af14f3e93 --- /dev/null +++ b/filter/mathjaxloader/amd/src/loader.js @@ -0,0 +1,123 @@ +// 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 . + +/** + * Mathjax JS Loader. + * + * @module filter_mathjaxloader + * @copyright 2014 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +import {eventTypes} from 'core_filters/events'; + +/** + * The users current language - this can't be set until MathJax is loaded - so we need to store it. + * @property {string} lang + * @default '' + * @private + */ +let lang = ''; + +/** + * Used to prevent configuring MathJax twice. + * @property {boolean} configured + * @default false + * @private + */ +let configured = false; + +/** + * Called by the filter when it is active on any page. + * This does not load MathJAX yet - it addes the configuration to the head incase it gets loaded later. + * It also subscribes to the filter-content-updated event so MathJax can respond to content loaded by Ajax. + * + * @method configure + * @param {Object} params List of configuration params containing mathjaxconfig (text) and lang + */ +export const configure = (params) => { + // Add a js configuration object to the head. + // See "http://docs.mathjax.org/en/latest/dynamic.html#ajax-mathjax" + let script = document.createElement("script"); + script.type = "text/x-mathjax-config"; + script[(window.opera ? "innerHTML" : "text")] = params.mathjaxconfig; + document.getElementsByTagName("head")[0].appendChild(script); + + // Save the lang config until MathJax is actually loaded. + lang = params.lang; + + // Listen for events triggered when new text is added to a page that needs + // processing by a filter. + document.addEventListener(eventTypes.filterContentUpdated, contentUpdated); +}; + +/** + * Set the correct language for the MathJax menus. Only do this once. + * + * @method setLocale + * @private + */ +const setLocale = () => { + if (!configured) { + if (typeof window.MathJax !== "undefined") { + window.MathJax.Hub.Queue(function() { + window.MathJax.Localization.setLocale(lang); + }); + window.MathJax.Hub.Configured(); + configured = true; + } + } +}; + +/** + * Called by the filter when an equation is found while rendering the page. + * + * @method typeset + */ +export const typeset = () => { + if (!configured) { + setLocale(); + const elements = document.getElementsByClassName('filter_mathjaxloader_equation'); + for (let i = 0; i < elements.length; i++) { + if (typeof window.MathJax !== "undefined") { + window.MathJax.Hub.Queue(["Typeset", window.MathJax.Hub, elements[i]]); + } + } + } +}; + +/** + * Handle content updated events - typeset the new content. + * + * @method contentUpdated + * @param {CustomEvent} event - Custom event with "nodes" indicating the root of the updated nodes. + */ +export const contentUpdated = (event) => { + if (typeof window.MathJax === "undefined") { + return; + } + const processdelay = window.MathJax.Hub.processSectionDelay; + // Set the process section delay to 0 when updating the formula. + window.MathJax.Hub.processSectionDelay = 0; + // When content is updated never position to hash, it may cause unexpected document scrolling. + window.MathJax.Hub.Config({positionToHash: false}); + setLocale(); + // The list of HTMLElements in an Array. + event.detail.nodes.forEach((node) => { + const mathjaxElements = node.querySelectorAll('.filter_mathjaxloader_equation'); + mathjaxElements.forEach((node) => { + window.MathJax.Hub.Queue(["Typeset", window.MathJax.Hub, node]); + }); + }); + window.MathJax.Hub.processSectionDelay = processdelay; +}; diff --git a/filter/mathjaxloader/filter.php b/filter/mathjaxloader/filter.php index 9fab93b9e79..2704fd6df7d 100644 --- a/filter/mathjaxloader/filter.php +++ b/filter/mathjaxloader/filter.php @@ -85,12 +85,7 @@ class filter_mathjaxloader extends moodle_text_filter { $lang = $this->map_language_code(current_language()); $url = new moodle_url($url, array('delayStartupUntil' => 'configured')); - $moduleconfig = array( - 'name' => 'mathjax', - 'fullpath' => $url - ); - - $page->requires->js_module($moduleconfig); + $page->requires->js($url); $config = get_config('filter_mathjaxloader', 'mathjaxconfig'); $wwwroot = new moodle_url('/'); @@ -99,7 +94,7 @@ class filter_mathjaxloader extends moodle_text_filter { $params = array('mathjaxconfig' => $config, 'lang' => $lang); - $page->requires->yui_module('moodle-filter_mathjaxloader-loader', 'M.filter_mathjaxloader.configure', array($params)); + $page->requires->js_call_amd('filter_mathjaxloader/loader', 'configure', [$params]); } } @@ -156,7 +151,7 @@ class filter_mathjaxloader extends moodle_text_filter { } if ($hasdisplayorinline || $hasextra) { - $PAGE->requires->yui_module('moodle-filter_mathjaxloader-loader', 'M.filter_mathjaxloader.typeset'); + $PAGE->requires->js_call_amd('filter_mathjaxloader/loader', 'typeset'); return '' . $text . ''; } return $text; diff --git a/filter/mathjaxloader/yui/build/moodle-filter_mathjaxloader-loader/moodle-filter_mathjaxloader-loader-debug.js b/filter/mathjaxloader/yui/build/moodle-filter_mathjaxloader-loader/moodle-filter_mathjaxloader-loader-debug.js deleted file mode 100644 index c2441d291e7..00000000000 --- a/filter/mathjaxloader/yui/build/moodle-filter_mathjaxloader-loader/moodle-filter_mathjaxloader-loader-debug.js +++ /dev/null @@ -1,137 +0,0 @@ -YUI.add('moodle-filter_mathjaxloader-loader', function (Y, NAME) { - -// 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 . - -/** - * Mathjax JS Loader. - * - * @package filter_mathjaxloader - * @copyright 2014 Damyon Wiese - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -M.filter_mathjaxloader = M.filter_mathjaxloader || { - - /** - * The users current language - this can't be set until MathJax is loaded - so we need to store it. - * @property _lang - * @type String - * @default '' - * @private - */ - _lang: '', - - /** - * Boolean used to prevent configuring MathJax twice. - * @property _configured - * @type Boolean - * @default '' - * @private - */ - _configured: false, - - /** - * Called by the filter when it is active on any page. - * This does not load MathJAX yet - it addes the configuration to the head incase it gets loaded later. - * It also subscribes to the filter-content-updated event so MathJax can respond to content loaded by Ajax. - * - * @method typeset - * @param {Object} params List of configuration params containing mathjaxconfig (text) and lang - */ - configure: function(params) { - - // Add a js configuration object to the head. - // See "http://docs.mathjax.org/en/latest/dynamic.html#ajax-mathjax" - var script = document.createElement("script"); - script.type = "text/x-mathjax-config"; - script[(window.opera ? "innerHTML" : "text")] = params.mathjaxconfig; - document.getElementsByTagName("head")[0].appendChild(script); - - // Save the lang config until MathJax is actually loaded. - this._lang = params.lang; - - // Listen for events triggered when new text is added to a page that needs - // processing by a filter. - Y.on(M.core.event.FILTER_CONTENT_UPDATED, this.contentUpdated, this); - }, - - /** - * Set the correct language for the MathJax menus. Only do this once. - * - * @method setLocale - * @private - */ - _setLocale: function() { - if (!this._configured) { - var lang = this._lang; - if (typeof window.MathJax !== "undefined") { - window.MathJax.Hub.Queue(function() { - window.MathJax.Localization.setLocale(lang); - }); - window.MathJax.Hub.Configured(); - this._configured = true; - } - } - }, - - /** - * Called by the filter when an equation is found while rendering the page. - * - * @method typeset - */ - typeset: function() { - if (!this._configured) { - var self = this; - Y.use('mathjax', function() { - self._setLocale(); - Y.all('.filter_mathjaxloader_equation').each(function(node) { - if (typeof window.MathJax !== "undefined") { - window.MathJax.Hub.Queue(["Typeset", window.MathJax.Hub, node.getDOMNode()]); - } - }); - }); - } - }, - - /** - * Handle content updated events - typeset the new content. - * @method contentUpdated - * @param Y.Event - Custom event with "nodes" indicating the root of the updated nodes. - */ - contentUpdated: function(event) { - var self = this; - Y.use('mathjax', function() { - if (typeof window.MathJax === "undefined") { - return; - } - var processdelay = window.MathJax.Hub.processSectionDelay; - // Set the process section delay to 0 when updating the formula. - window.MathJax.Hub.processSectionDelay = 0; - // When content is updated never position to hash, it may cause unexpected document scrolling. - window.MathJax.Hub.Config({positionToHash: false}); - self._setLocale(); - event.nodes.each(function(node) { - node.all('.filter_mathjaxloader_equation').each(function(node) { - window.MathJax.Hub.Queue(["Typeset", window.MathJax.Hub, node.getDOMNode()]); - }); - }); - // Set the delay back to normal after processing. - window.MathJax.Hub.processSectionDelay = processdelay; - }); - } -}; - - -}, '@VERSION@', {"requires": ["moodle-core-event"]}); diff --git a/filter/mathjaxloader/yui/build/moodle-filter_mathjaxloader-loader/moodle-filter_mathjaxloader-loader-min.js b/filter/mathjaxloader/yui/build/moodle-filter_mathjaxloader-loader/moodle-filter_mathjaxloader-loader-min.js deleted file mode 100644 index cc5543015ca..00000000000 --- a/filter/mathjaxloader/yui/build/moodle-filter_mathjaxloader-loader/moodle-filter_mathjaxloader-loader-min.js +++ /dev/null @@ -1 +0,0 @@ -YUI.add("moodle-filter_mathjaxloader-loader",function(n,e){M.filter_mathjaxloader=M.filter_mathjaxloader||{_lang:"",_configured:!1,configure:function(e){var t=document.createElement("script");t.type="text/x-mathjax-config",t[window.opera?"innerHTML":"text"]=e.mathjaxconfig,document.getElementsByTagName("head")[0].appendChild(t),this._lang=e.lang,n.on(M.core.event.FILTER_CONTENT_UPDATED,this.contentUpdated,this)},_setLocale:function(){var e;this._configured||(e=this._lang,"undefined"!=typeof window.MathJax&&(window.MathJax.Hub.Queue(function(){window.MathJax.Localization.setLocale(e)}),window.MathJax.Hub.Configured(),this._configured=!0))},typeset:function(){var e;this._configured||(e=this,n.use("mathjax",function(){e._setLocale(),n.all(".filter_mathjaxloader_equation").each(function(e){"undefined"!=typeof window.MathJax&&window.MathJax.Hub.Queue(["Typeset",window.MathJax.Hub,e.getDOMNode()])})}))},contentUpdated:function(t){var a=this;n.use("mathjax",function(){var e;"undefined"!=typeof window.MathJax&&(e=window.MathJax.Hub.processSectionDelay,window.MathJax.Hub.processSectionDelay=0,window.MathJax.Hub.Config({positionToHash:!1}),a._setLocale(),t.nodes.each(function(e){e.all(".filter_mathjaxloader_equation").each(function(e){window.MathJax.Hub.Queue(["Typeset",window.MathJax.Hub,e.getDOMNode()])})}),window.MathJax.Hub.processSectionDelay=e)})}}},"@VERSION@",{requires:["moodle-core-event"]}); \ No newline at end of file diff --git a/filter/mathjaxloader/yui/build/moodle-filter_mathjaxloader-loader/moodle-filter_mathjaxloader-loader.js b/filter/mathjaxloader/yui/build/moodle-filter_mathjaxloader-loader/moodle-filter_mathjaxloader-loader.js deleted file mode 100644 index c2441d291e7..00000000000 --- a/filter/mathjaxloader/yui/build/moodle-filter_mathjaxloader-loader/moodle-filter_mathjaxloader-loader.js +++ /dev/null @@ -1,137 +0,0 @@ -YUI.add('moodle-filter_mathjaxloader-loader', function (Y, NAME) { - -// 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 . - -/** - * Mathjax JS Loader. - * - * @package filter_mathjaxloader - * @copyright 2014 Damyon Wiese - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -M.filter_mathjaxloader = M.filter_mathjaxloader || { - - /** - * The users current language - this can't be set until MathJax is loaded - so we need to store it. - * @property _lang - * @type String - * @default '' - * @private - */ - _lang: '', - - /** - * Boolean used to prevent configuring MathJax twice. - * @property _configured - * @type Boolean - * @default '' - * @private - */ - _configured: false, - - /** - * Called by the filter when it is active on any page. - * This does not load MathJAX yet - it addes the configuration to the head incase it gets loaded later. - * It also subscribes to the filter-content-updated event so MathJax can respond to content loaded by Ajax. - * - * @method typeset - * @param {Object} params List of configuration params containing mathjaxconfig (text) and lang - */ - configure: function(params) { - - // Add a js configuration object to the head. - // See "http://docs.mathjax.org/en/latest/dynamic.html#ajax-mathjax" - var script = document.createElement("script"); - script.type = "text/x-mathjax-config"; - script[(window.opera ? "innerHTML" : "text")] = params.mathjaxconfig; - document.getElementsByTagName("head")[0].appendChild(script); - - // Save the lang config until MathJax is actually loaded. - this._lang = params.lang; - - // Listen for events triggered when new text is added to a page that needs - // processing by a filter. - Y.on(M.core.event.FILTER_CONTENT_UPDATED, this.contentUpdated, this); - }, - - /** - * Set the correct language for the MathJax menus. Only do this once. - * - * @method setLocale - * @private - */ - _setLocale: function() { - if (!this._configured) { - var lang = this._lang; - if (typeof window.MathJax !== "undefined") { - window.MathJax.Hub.Queue(function() { - window.MathJax.Localization.setLocale(lang); - }); - window.MathJax.Hub.Configured(); - this._configured = true; - } - } - }, - - /** - * Called by the filter when an equation is found while rendering the page. - * - * @method typeset - */ - typeset: function() { - if (!this._configured) { - var self = this; - Y.use('mathjax', function() { - self._setLocale(); - Y.all('.filter_mathjaxloader_equation').each(function(node) { - if (typeof window.MathJax !== "undefined") { - window.MathJax.Hub.Queue(["Typeset", window.MathJax.Hub, node.getDOMNode()]); - } - }); - }); - } - }, - - /** - * Handle content updated events - typeset the new content. - * @method contentUpdated - * @param Y.Event - Custom event with "nodes" indicating the root of the updated nodes. - */ - contentUpdated: function(event) { - var self = this; - Y.use('mathjax', function() { - if (typeof window.MathJax === "undefined") { - return; - } - var processdelay = window.MathJax.Hub.processSectionDelay; - // Set the process section delay to 0 when updating the formula. - window.MathJax.Hub.processSectionDelay = 0; - // When content is updated never position to hash, it may cause unexpected document scrolling. - window.MathJax.Hub.Config({positionToHash: false}); - self._setLocale(); - event.nodes.each(function(node) { - node.all('.filter_mathjaxloader_equation').each(function(node) { - window.MathJax.Hub.Queue(["Typeset", window.MathJax.Hub, node.getDOMNode()]); - }); - }); - // Set the delay back to normal after processing. - window.MathJax.Hub.processSectionDelay = processdelay; - }); - } -}; - - -}, '@VERSION@', {"requires": ["moodle-core-event"]}); diff --git a/filter/mathjaxloader/yui/src/loader/build.json b/filter/mathjaxloader/yui/src/loader/build.json deleted file mode 100644 index b262702bd16..00000000000 --- a/filter/mathjaxloader/yui/src/loader/build.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "moodle-filter_mathjaxloader-loader", - "builds": { - "moodle-filter_mathjaxloader-loader": { - "jsfiles": [ - "loader.js" - ] - } - } -} diff --git a/filter/mathjaxloader/yui/src/loader/js/loader.js b/filter/mathjaxloader/yui/src/loader/js/loader.js deleted file mode 100644 index 1258a5c066e..00000000000 --- a/filter/mathjaxloader/yui/src/loader/js/loader.js +++ /dev/null @@ -1,132 +0,0 @@ -// 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 . - -/** - * Mathjax JS Loader. - * - * @package filter_mathjaxloader - * @copyright 2014 Damyon Wiese - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -M.filter_mathjaxloader = M.filter_mathjaxloader || { - - /** - * The users current language - this can't be set until MathJax is loaded - so we need to store it. - * @property _lang - * @type String - * @default '' - * @private - */ - _lang: '', - - /** - * Boolean used to prevent configuring MathJax twice. - * @property _configured - * @type Boolean - * @default '' - * @private - */ - _configured: false, - - /** - * Called by the filter when it is active on any page. - * This does not load MathJAX yet - it addes the configuration to the head incase it gets loaded later. - * It also subscribes to the filter-content-updated event so MathJax can respond to content loaded by Ajax. - * - * @method typeset - * @param {Object} params List of configuration params containing mathjaxconfig (text) and lang - */ - configure: function(params) { - - // Add a js configuration object to the head. - // See "http://docs.mathjax.org/en/latest/dynamic.html#ajax-mathjax" - var script = document.createElement("script"); - script.type = "text/x-mathjax-config"; - script[(window.opera ? "innerHTML" : "text")] = params.mathjaxconfig; - document.getElementsByTagName("head")[0].appendChild(script); - - // Save the lang config until MathJax is actually loaded. - this._lang = params.lang; - - // Listen for events triggered when new text is added to a page that needs - // processing by a filter. - Y.on(M.core.event.FILTER_CONTENT_UPDATED, this.contentUpdated, this); - }, - - /** - * Set the correct language for the MathJax menus. Only do this once. - * - * @method setLocale - * @private - */ - _setLocale: function() { - if (!this._configured) { - var lang = this._lang; - if (typeof window.MathJax !== "undefined") { - window.MathJax.Hub.Queue(function() { - window.MathJax.Localization.setLocale(lang); - }); - window.MathJax.Hub.Configured(); - this._configured = true; - } - } - }, - - /** - * Called by the filter when an equation is found while rendering the page. - * - * @method typeset - */ - typeset: function() { - if (!this._configured) { - var self = this; - Y.use('mathjax', function() { - self._setLocale(); - Y.all('.filter_mathjaxloader_equation').each(function(node) { - if (typeof window.MathJax !== "undefined") { - window.MathJax.Hub.Queue(["Typeset", window.MathJax.Hub, node.getDOMNode()]); - } - }); - }); - } - }, - - /** - * Handle content updated events - typeset the new content. - * @method contentUpdated - * @param Y.Event - Custom event with "nodes" indicating the root of the updated nodes. - */ - contentUpdated: function(event) { - var self = this; - Y.use('mathjax', function() { - if (typeof window.MathJax === "undefined") { - return; - } - var processdelay = window.MathJax.Hub.processSectionDelay; - // Set the process section delay to 0 when updating the formula. - window.MathJax.Hub.processSectionDelay = 0; - // When content is updated never position to hash, it may cause unexpected document scrolling. - window.MathJax.Hub.Config({positionToHash: false}); - self._setLocale(); - event.nodes.each(function(node) { - node.all('.filter_mathjaxloader_equation').each(function(node) { - window.MathJax.Hub.Queue(["Typeset", window.MathJax.Hub, node.getDOMNode()]); - }); - }); - // Set the delay back to normal after processing. - window.MathJax.Hub.processSectionDelay = processdelay; - }); - } -}; diff --git a/filter/mathjaxloader/yui/src/loader/meta/loader.json b/filter/mathjaxloader/yui/src/loader/meta/loader.json deleted file mode 100644 index eaca4224906..00000000000 --- a/filter/mathjaxloader/yui/src/loader/meta/loader.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "moodle-filter_mathjaxloader-loader": { - "requires": [ - "moodle-core-event" - ] - } -} diff --git a/filter/upgrade.txt b/filter/upgrade.txt index bd186cec7e1..a4f52adfb92 100644 --- a/filter/upgrade.txt +++ b/filter/upgrade.txt @@ -7,6 +7,8 @@ information provided here is intended especially for developers. It is recommended that add-on filter developers use early formatting stages to prevent security issues caused by modification of already sanitised text. +* The moodle-filter_mathjaxloader-loader yui module has been deprecated. We create amd filter_mathjaxloader/loader to replace it. + === 4.0 === * The Word censorship (filter_censor) filter has been completely removed from core. It has been moved to the plugins database