diff options
Diffstat (limited to 'plugin')
-rwxr-xr-x | plugin/math/math.js | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/plugin/math/math.js b/plugin/math/math.js index b6bd82f..78856a5 100755 --- a/plugin/math/math.js +++ b/plugin/math/math.js @@ -9,27 +9,10 @@ var RevealMath = window.RevealMath || (function(){ var loaded = false; var config = Reveal.getConfig().math || {}; + config.host = config.host || 'http://cdn.mathjax.org/mathjax/latest/MathJax.js'; config.mode = config.mode || 'TeX-AMS_HTML-full'; - var head = document.querySelector( 'head' ); - var script = document.createElement( 'script' ); - script.type = 'text/javascript'; - script.src = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=' + config.mode; - - // Detect when the script has loaded - script.onload = onScriptLoad; - - // IE - script.onreadystatechange = function() { - if ( this.readyState === 'loaded' ) { - onScriptLoad.call(); - } - } - - // Normal browsers - head.appendChild( script ); - - function onScriptLoad() { + loadScript( config.host + '?config=' + config.mode, function() { // Conditioned just in case both onload and readystate fire if( loaded === false ) { @@ -48,11 +31,42 @@ var RevealMath = window.RevealMath || (function(){ // This will only typeset equations that have not yet been // processed, as well as equations that have change since // last being processed. - MathJax.Hub.Update( event.currentSlide ); + MathJax.Hub.Update( event.currentSlide, function() { + Reveal.layout(); + } ); } ); } + } ); + + function loadScript( url, callback ) { + + var head = document.querySelector( 'head' ); + var script = document.createElement( 'script' ); + script.type = 'text/javascript'; + script.src = url; + + // Wrapper for callback to make sure it only fires once + var finish = function() { + if( typeof callback === 'function' ) { + callback.call(); + callback = null; + } + } + + script.onload = finish; + + // IE + script.onreadystatechange = function() { + if ( this.readyState === 'loaded' ) { + finish.call(); + } + } + + // Normal browsers + head.appendChild( script ); + } })(); |