From 13df3c9b0cd13a096c4e917012bef4fefef3f4e7 Mon Sep 17 00:00:00 2001 From: Derk-Jan Hartman Date: Sat, 5 Apr 2014 19:11:25 +0200 Subject: [PATCH] MathJax: Listen for wikipage.content hook This brings us one step closer to solving the JS rendering bug. The remaining issue is how to know that the enabler script needs to be loaded. Bug: 36060 Change-Id: I9cbd032afaf90a735c92f055c2bf82766e9acbe0 --- modules/ext.math.mathjax.enabler.js | 55 ++++++++++++----------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/modules/ext.math.mathjax.enabler.js b/modules/ext.math.mathjax.enabler.js index eb9a51e..9a45a01 100644 --- a/modules/ext.math.mathjax.enabler.js +++ b/modules/ext.math.mathjax.enabler.js @@ -201,48 +201,37 @@ * Renders all Math TeX inside the given elements. * @param {function} callback to be executed after text elements have rendered [optional] */ - $.fn.renderTex = function ( callback ) { - var elem = this.find( '.tex' ).parent().toArray(); + $.fn.renderTex = function () { + mathJax.LoadAndRender( this ); + return this; + }; + mw.log.deprecate( $.fn, 'renderTex', $.fn.renderTex, + 'Use the mw.hook wikipage.content instead' ); - if ( !$.isFunction( callback ) ) { - callback = $.noop; + mathJax.LoadAndRender = function ( $content ) { + // create the global MathJax variable to hook into MathJax startup + if( typeof MathJax === 'undefined' ) { + window.MathJax = { + delayStartupUntil: 'configured', + skipStartupTypeset: true, + AuthorInit: mathJax.Init + }; } function render() { - MathJax.Hub.Queue( ['Typeset', MathJax.Hub, elem, callback] ); + var elem = $content.toArray(); + MathJax.Hub.Queue( ['Typeset', MathJax.Hub, elem] ); } - mw.loader.using( 'ext.math.mathjax.mathjax', function () { - if ( MathJax.isReady ) { - render(); - } else { + if ( MathJax.isReady ) { + render(); + } else { + mw.loader.using( 'ext.math.mathjax.mathjax', function () { MathJax.Hub.Startup.signal.MessageHook( 'End', render ); - } - } ); - return this; - }; - - mathJax.Load = function () { - if ( this.loaded ) { - return true; + } ); } - - // create the global MathJax variable to hook into MathJax startup - window.MathJax = { - delayStartupUntil: 'configured', - AuthorInit: mathJax.Init - }; - - // load MathJax.js - mw.loader.load('ext.math.mathjax.mathjax'); - - this.loaded = true; - - return false; }; - $( document ).ready( function () { - mathJax.Load(); - } ); + mw.hook( 'wikipage.content' ).add( mathJax.LoadAndRender ); }( mediaWiki, jQuery ) );