Merge branch 'MDL-85155-main' of https://github.com/HuongNV13/moodle
This commit is contained in:
+1
-1
@@ -1,3 +1,3 @@
|
||||
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;_exports.configure=params=>{window.MathJax&&(window.MathJax.config.locale=params.lang),document.addEventListener(_events.eventTypes.filterContentUpdated,contentUpdated)};const typesetNode=node=>{node instanceof HTMLElement&&window.MathJax&&window.MathJax.typesetPromise([node]).then((()=>{(0,_events.notifyFilterContentRenderingComplete)([node])})).catch((e=>{window.console.log(e)}))};_exports.typeset=()=>{const elements=document.getElementsByClassName("filter_mathjaxloader_equation");for(const element of elements)void 0!==window.MathJax&&typesetNode(element)};const contentUpdated=event=>{if(void 0===window.MathJax)return;let listOfElementContainMathJax=[],hasMathJax=!1;event.detail.nodes.forEach((node=>{if(!(node instanceof HTMLElement))return;const mathjaxElements=node.querySelectorAll(".filter_mathjaxloader_equation");mathjaxElements.length>0&&(hasMathJax=!0),listOfElementContainMathJax.push(mathjaxElements)})),hasMathJax&&listOfElementContainMathJax.forEach((mathjaxElements=>{mathjaxElements.forEach((node=>typesetNode(node)))}))};_exports.contentUpdated=contentUpdated}));
|
||||
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;_exports.configure=params=>{loadMathJax(params.mathjaxurl,(()=>{window.MathJax&&(window.MathJax.config.locale=params.lang),document.addEventListener(_events.eventTypes.filterContentUpdated,contentUpdated)}))};const typesetNode=node=>{node instanceof HTMLElement&&window.MathJax&&window.MathJax.typesetPromise([node]).then((()=>{(0,_events.notifyFilterContentRenderingComplete)([node])})).catch((e=>{window.console.log(e)}))};_exports.typeset=()=>{const elements=document.getElementsByClassName("filter_mathjaxloader_equation");for(const element of elements)void 0!==window.MathJax&&typesetNode(element)};const contentUpdated=event=>{if(void 0===window.MathJax)return;let listOfElementContainMathJax=[],hasMathJax=!1;event.detail.nodes.forEach((node=>{if(!(node instanceof HTMLElement))return;const mathjaxElements=node.querySelectorAll(".filter_mathjaxloader_equation");mathjaxElements.length>0&&(hasMathJax=!0),listOfElementContainMathJax.push(mathjaxElements)})),hasMathJax&&listOfElementContainMathJax.forEach((mathjaxElements=>{mathjaxElements.forEach((node=>typesetNode(node)))}))};_exports.contentUpdated=contentUpdated;const loadMathJax=(url,callback)=>{const script=document.createElement("script");script.type="text/javascript",script.onload=()=>{callback()},script.src=url,document.getElementsByTagName("head")[0].appendChild(script)}}));
|
||||
|
||||
//# sourceMappingURL=loader.min.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -29,18 +29,20 @@ import {
|
||||
* 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.
|
||||
*
|
||||
* @param {Object} params List of configuration params containing mathjaxconfig (text) and lang
|
||||
* @param {Object} params List of configuration params containing mathjaxurl, mathjaxconfig (text) and lang
|
||||
*/
|
||||
export const configure = (params) => {
|
||||
if (window.MathJax) {
|
||||
// Let's still set the locale even if the localization is not yet ported to version 3.2.2
|
||||
// https://docs.mathjax.org/en/v3.2-latest/upgrading/v2.html#not-yet-ported-to-version-3.
|
||||
window.MathJax.config.locale = params.lang;
|
||||
}
|
||||
loadMathJax(params.mathjaxurl, () => {
|
||||
if (window.MathJax) {
|
||||
// Let's still set the locale even if the localization is not yet ported to version 3.2.2
|
||||
// https://docs.mathjax.org/en/v3.2-latest/upgrading/v2.html#not-yet-ported-to-version-3.
|
||||
window.MathJax.config.locale = 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);
|
||||
// Listen for events triggered when new text is added to a page that needs
|
||||
// processing by a filter.
|
||||
document.addEventListener(eventTypes.filterContentUpdated, contentUpdated);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -112,3 +114,19 @@ export const contentUpdated = (event) => {
|
||||
mathjaxElements.forEach((node) => typesetNode(node));
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Load the MathJax script.
|
||||
*
|
||||
* @param {String} url The URL of the MathJax script to load.
|
||||
* @param {function} callback The function to call when the script has loaded.
|
||||
*/
|
||||
const loadMathJax = (url, callback) => {
|
||||
const script = document.createElement('script');
|
||||
script.type = 'text/javascript';
|
||||
script.onload = () => {
|
||||
callback();
|
||||
};
|
||||
script.src = url;
|
||||
document.getElementsByTagName('head')[0].appendChild(script);
|
||||
};
|
||||
|
||||
@@ -78,7 +78,6 @@ class text_filter extends \core_filters\text_filter {
|
||||
$url = get_config('filter_mathjaxloader', 'httpsurl');
|
||||
$lang = $this->map_language_code(current_language());
|
||||
$url = new url($url);
|
||||
$page->requires->js($url);
|
||||
|
||||
// Let's still get this config even if the value is null due to the setting being set as default.
|
||||
// For the config we can set based on the needs when we need from:
|
||||
@@ -86,7 +85,11 @@ class text_filter extends \core_filters\text_filter {
|
||||
$config = get_config('filter_mathjaxloader', 'mathjaxconfig');
|
||||
$wwwroot = new url('/');
|
||||
$config = str_replace('{wwwroot}', $wwwroot->out(true), $config);
|
||||
$params = ['mathjaxconfig' => $config, 'lang' => $lang];
|
||||
$params = [
|
||||
'mathjaxurl' => $url->out(false),
|
||||
'mathjaxconfig' => $config,
|
||||
'lang' => $lang,
|
||||
];
|
||||
|
||||
// Let's still send the config and lang to the loader.
|
||||
$page->requires->js_call_amd('filter_mathjaxloader/loader', 'configure', [$params]);
|
||||
|
||||
Reference in New Issue
Block a user