Difference between revisions of "MediaWiki:Common.js"
From CUGC Wiki
(Debugging $content.) |
(Get element from $content.) |
||
Line 3: | Line 3: | ||
mw.hook('wikipage.content').add(function ($content) { | mw.hook('wikipage.content').add(function ($content) { | ||
console.log($content); | console.log($content); | ||
− | console.log( | + | console.log($content[0]); |
+ | var element = $content[0]; | ||
var observer = new MutationObserver(function(mutations) { | var observer = new MutationObserver(function(mutations) { | ||
− | if (document.contains( | + | if (document.contains(element)) { |
console.log("It's in the DOM!"); | console.log("It's in the DOM!"); | ||
− | + | MathJax.Hub.Queue(["Typeset", MathJax.Hub, element]).execute(); | |
− | MathJax.Hub.Queue(["Typeset", MathJax.Hub, | ||
observer.disconnect(); | observer.disconnect(); | ||
} else { | } else { |
Revision as of 16:45, 12 March 2019
/* Any JavaScript here will be loaded for all users on every page load. */ mw.hook('wikipage.content').add(function ($content) { console.log($content); console.log($content[0]); var element = $content[0]; var observer = new MutationObserver(function(mutations) { if (document.contains(element)) { console.log("It's in the DOM!"); MathJax.Hub.Queue(["Typeset", MathJax.Hub, element]).execute(); observer.disconnect(); } else { console.log("Still waiting"); } }); observer.observe(document, {attributes: false, childList: true, characterData: false, subtree: true}); });