2011-12-06 01:17:35 +00:00
|
|
|
/**
|
|
|
|
* From https://en.wikipedia.org/wiki/User:Nageh/mathJax.js
|
|
|
|
*/
|
2013-04-27 14:04:21 +00:00
|
|
|
/*global mathJax:true, MathJax */
|
2013-02-07 04:14:02 +00:00
|
|
|
( function ( mw, $ ) {
|
|
|
|
if ( typeof mathJax === 'undefined' ) {
|
|
|
|
mathJax = {};
|
|
|
|
}
|
2011-12-06 01:17:35 +00:00
|
|
|
|
2013-02-07 04:14:02 +00:00
|
|
|
mathJax.version = '0.2';
|
2011-12-06 01:17:35 +00:00
|
|
|
|
2013-02-07 04:14:02 +00:00
|
|
|
mathJax.loaded = false;
|
2011-12-06 01:17:35 +00:00
|
|
|
|
2013-04-27 13:28:46 +00:00
|
|
|
mathJax.config = $.extend( true, {
|
|
|
|
root: mw.config.get('wgExtensionAssetsPath') + '/Math/modules/MathJax',
|
|
|
|
config: ['TeX-AMS-texvc_HTML.js'],
|
|
|
|
'v1.0-compatible': false,
|
|
|
|
styles: {
|
|
|
|
'.mtext': {
|
|
|
|
'font-family': 'sans-serif ! important',
|
|
|
|
'font-size': '80%'
|
2013-02-07 04:20:14 +00:00
|
|
|
}
|
2013-04-27 13:28:46 +00:00
|
|
|
},
|
|
|
|
displayAlign: 'left',
|
|
|
|
menuSettings: {
|
|
|
|
zoom: 'Click'
|
|
|
|
},
|
|
|
|
'HTML-CSS': {
|
|
|
|
imageFont: null,
|
|
|
|
availableFonts: ['TeX']
|
|
|
|
}
|
|
|
|
}, mathJax.config );
|
|
|
|
|
|
|
|
mathJax.Config = function () {
|
|
|
|
MathJax.Hub.Config( mathJax.config );
|
|
|
|
MathJax.OutputJax.fontDir = mw.config.get('wgExtensionAssetsPath') + '/Math/modules/MathJax/fonts';
|
2013-02-07 04:14:02 +00:00
|
|
|
};
|
2011-12-06 01:17:35 +00:00
|
|
|
|
2013-04-27 13:53:10 +00:00
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
|
|
|
|
if ( !$.isFunction( callback ) ) {
|
|
|
|
callback = $.noop;
|
|
|
|
}
|
|
|
|
|
|
|
|
function render () {
|
|
|
|
MathJax.Hub.Queue( ['Typeset', MathJax.Hub, elem, callback] );
|
|
|
|
}
|
|
|
|
|
|
|
|
mw.loader.using( 'ext.math.mathjax', function () {
|
|
|
|
if ( MathJax.isReady ) {
|
|
|
|
render();
|
|
|
|
} else {
|
|
|
|
MathJax.Hub.Startup.signal.MessageHook( 'End', render );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2013-02-07 04:20:14 +00:00
|
|
|
mathJax.Load = function () {
|
2013-02-07 04:14:02 +00:00
|
|
|
var config, script;
|
|
|
|
if (this.loaded) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-12-06 01:17:35 +00:00
|
|
|
|
2013-02-07 04:14:02 +00:00
|
|
|
// create configuration element
|
|
|
|
config = 'mathJax.Config();';
|
|
|
|
script = document.createElement( 'script' );
|
|
|
|
script.setAttribute( 'type', 'text/x-mathjax-config' );
|
|
|
|
if ( window.opera ) {
|
|
|
|
script.innerHTML = config;
|
|
|
|
} else {
|
|
|
|
script.text = config;
|
|
|
|
}
|
|
|
|
document.getElementsByTagName('head')[0].appendChild( script );
|
2011-12-06 01:17:35 +00:00
|
|
|
|
2013-02-07 04:14:02 +00:00
|
|
|
// create startup element
|
2013-02-07 04:20:14 +00:00
|
|
|
mw.loader.load('ext.math.mathjax');
|
2011-12-06 01:17:35 +00:00
|
|
|
|
2013-02-07 04:14:02 +00:00
|
|
|
this.loaded = true;
|
2011-12-06 01:17:35 +00:00
|
|
|
|
2013-02-07 04:14:02 +00:00
|
|
|
return false;
|
|
|
|
};
|
2011-12-06 01:17:35 +00:00
|
|
|
|
2013-02-07 04:20:14 +00:00
|
|
|
$( document ).ready( function () {
|
2013-04-27 14:04:21 +00:00
|
|
|
mathJax.Load();
|
2013-02-07 04:14:02 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
}( mediaWiki, jQuery ) );
|