MDL-79301 mathjax: contentUpdated must trigger for mathjax element only.

This commit is contained in:
hieuvu
2023-09-11 10:25:21 +07:00
parent 00f0613f99
commit 457cfa50e1
3 changed files with 20 additions and 8 deletions
+1 -1
View File
@@ -6,6 +6,6 @@ define("filter_mathjaxloader/loader",["exports","core_filters/events"],(function
* @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=>{const 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)},typesetNode=node=>{node instanceof HTMLElement&&(window.MathJax.Hub.Queue(["Typeset",window.MathJax.Hub,node]),window.MathJax.Hub.Queue([node=>{(0,_events.notifyFilterContentRenderingComplete)([node])},node]))};_exports.typeset=()=>{if(!configured){setLocale();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;const processDelay=window.MathJax.Hub.processSectionDelay;window.MathJax.Hub.processSectionDelay=0,window.MathJax.Hub.Config({positionToHash:!1}),setLocale(),event.detail.nodes.forEach((node=>{if(!(node instanceof HTMLElement))return;node.querySelectorAll(".filter_mathjaxloader_equation").forEach((node=>typesetNode(node)))})),window.MathJax.Hub.processSectionDelay=processDelay};_exports.contentUpdated=contentUpdated}));
let lang="",configured=!1;_exports.configure=params=>{const 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)},typesetNode=node=>{node instanceof HTMLElement&&(window.MathJax.Hub.Queue(["Typeset",window.MathJax.Hub,node]),window.MathJax.Hub.Queue([node=>{(0,_events.notifyFilterContentRenderingComplete)([node])},node]))};_exports.typeset=()=>{if(!configured){setLocale();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;if(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)return;const processDelay=window.MathJax.Hub.processSectionDelay;window.MathJax.Hub.processSectionDelay=0,window.MathJax.Hub.Config({positionToHash:!1}),setLocale(),listOfElementContainMathJax.forEach((mathjaxElements=>{mathjaxElements.forEach((node=>typesetNode(node)))})),window.MathJax.Hub.processSectionDelay=processDelay};_exports.contentUpdated=contentUpdated}));
//# sourceMappingURL=loader.min.js.map
File diff suppressed because one or more lines are too long
+18 -6
View File
@@ -132,12 +132,9 @@ 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();
let listOfElementContainMathJax = [];
let hasMathJax = false;
// The list of HTMLElements in an Array.
event.detail.nodes.forEach((node) => {
if (!(node instanceof HTMLElement)) {
@@ -145,6 +142,21 @@ export const contentUpdated = (event) => {
return;
}
const mathjaxElements = node.querySelectorAll('.filter_mathjaxloader_equation');
if (mathjaxElements.length > 0) {
hasMathJax = true;
}
listOfElementContainMathJax.push(mathjaxElements);
});
if (!hasMathJax) {
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();
listOfElementContainMathJax.forEach((mathjaxElements) => {
mathjaxElements.forEach((node) => typesetNode(node));
});
window.MathJax.Hub.processSectionDelay = processDelay;