make mathjax host a config option, revamp script loading, fragment examples #531
This commit is contained in:
@ -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 );
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
Reference in New Issue
Block a user