mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-79039 mathjax: Re-write yui javascript to AMD module
This commit is contained in:
parent
e998f14061
commit
80c9de3d00
11
filter/mathjaxloader/amd/build/loader.min.js
vendored
Normal file
11
filter/mathjaxloader/amd/build/loader.min.js
vendored
Normal file
@ -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 <damyon@moodle.com>
|
||||
* @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<elements.length;i++)void 0!==window.MathJax&&window.MathJax.Hub.Queue(["Typeset",window.MathJax.Hub,elements[i]])}};const contentUpdated=event=>{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
|
1
filter/mathjaxloader/amd/build/loader.min.js.map
Normal file
1
filter/mathjaxloader/amd/build/loader.min.js.map
Normal file
File diff suppressed because one or more lines are too long
123
filter/mathjaxloader/amd/src/loader.js
Normal file
123
filter/mathjaxloader/amd/src/loader.js
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Mathjax JS Loader.
|
||||
*
|
||||
* @module filter_mathjaxloader
|
||||
* @copyright 2014 Damyon Wiese <damyon@moodle.com>
|
||||
* @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;
|
||||
};
|
@ -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 '<span class="filter_mathjaxloader_equation">' . $text . '</span>';
|
||||
}
|
||||
return $text;
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Mathjax JS Loader.
|
||||
*
|
||||
* @package filter_mathjaxloader
|
||||
* @copyright 2014 Damyon Wiese <damyon@moodle.com>
|
||||
* @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"]});
|
@ -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"]});
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Mathjax JS Loader.
|
||||
*
|
||||
* @package filter_mathjaxloader
|
||||
* @copyright 2014 Damyon Wiese <damyon@moodle.com>
|
||||
* @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"]});
|
@ -1,10 +0,0 @@
|
||||
{
|
||||
"name": "moodle-filter_mathjaxloader-loader",
|
||||
"builds": {
|
||||
"moodle-filter_mathjaxloader-loader": {
|
||||
"jsfiles": [
|
||||
"loader.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
132
filter/mathjaxloader/yui/src/loader/js/loader.js
vendored
132
filter/mathjaxloader/yui/src/loader/js/loader.js
vendored
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Mathjax JS Loader.
|
||||
*
|
||||
* @package filter_mathjaxloader
|
||||
* @copyright 2014 Damyon Wiese <damyon@moodle.com>
|
||||
* @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;
|
||||
});
|
||||
}
|
||||
};
|
@ -1,7 +0,0 @@
|
||||
{
|
||||
"moodle-filter_mathjaxloader-loader": {
|
||||
"requires": [
|
||||
"moodle-core-event"
|
||||
]
|
||||
}
|
||||
}
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user