Difference between revisions of "MediaWiki:Common.js"

From CUGC Wiki
(Don't use $content as there are errors in MathJax using it (TypeError: c.nodeName is undefined).)
(Remove debugging statements.)
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
/* Any JavaScript here will be loaded for all users on every page load. */
 
/* Any JavaScript here will be loaded for all users on every page load. */
  
// MathJax typesetting in edit previews
+
function waitForMathJax($content) {
function mathJaxTypeset($content) {
+
   if (typeof MathJax === 'undefined') {
   function waitForMathJax() {
+
    setTimeout(function () { waitForMathJax($content); }, 1000);
    if (typeof MathJax === 'undefined') {
+
  } else {
      setTimeout(waitForMathJax, 1000);
+
    MathJax.Hub.Queue(["Typeset", MathJax.Hub, $content[0]]).execute();
      console.log('Waiting for MathJax.');
 
    } else {
 
      console.log($content);
 
      // delay as wikipage.content is fired before $content is added to the page
 
      setTimeout(MathJax.Hub.Queue(["Typeset", MathJax.Hub, "wikiPreview"]).execute, 1000);
 
      console.log('Found MathJax; typeset done.');
 
    }
 
 
   }
 
   }
  waitForMathJax();
 
 
}
 
}
mw.hook('wikipage.content').add(mathJaxTypeset);
+
 
 +
mw.hook('wikipage.content').add(waitForMathJax);

Latest revision as of 17:55, 12 March 2019

/* Any JavaScript here will be loaded for all users on every page load. */

function waitForMathJax($content) {
  if (typeof MathJax === 'undefined') {
    setTimeout(function () { waitForMathJax($content); }, 1000);
  } else {
    MathJax.Hub.Queue(["Typeset", MathJax.Hub, $content[0]]).execute();
  }
}

mw.hook('wikipage.content').add(waitForMathJax);