aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorHakim El Hattab <hakim.elhattab@gmail.com>2013-08-12 23:15:19 -0400
committerHakim El Hattab <hakim.elhattab@gmail.com>2013-08-12 23:15:19 -0400
commit3e23b8b690222d914b2d6839eabd18f6c08f0eed (patch)
tree7e5a685658e2b6a62f25c314289de69be73da3b4 /plugin
parent39019040579208b87f620567eb722d70e310bc8f (diff)
downloadfosdem-2018-presentation-3e23b8b690222d914b2d6839eabd18f6c08f0eed.tar
fosdem-2018-presentation-3e23b8b690222d914b2d6839eabd18f6c08f0eed.tar.gz
make mathjax host a config option, revamp script loading, fragment examples #531
Diffstat (limited to 'plugin')
-rwxr-xr-xplugin/math/math.js54
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 );
+
}
})();