mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-25 16:05:50 +00:00
296bc66540
This way the cookie is never set and MathJax simply always follows the MediaWiki language. Follow up of Ibf43a3e44ea2bfdbd9fddc01c71c72ba097ff1b7 Bug: 35038 Change-Id: Ie7530d3a904fb39945ba8b8d261852c2b8cb666b
93 lines
2.2 KiB
JavaScript
93 lines
2.2 KiB
JavaScript
/**
|
|
* From https://en.wikipedia.org/wiki/User:Nageh/mathJax.js
|
|
*/
|
|
/*global mathJax:true, MathJax */
|
|
( function ( mw, $ ) {
|
|
if ( typeof mathJax === 'undefined' ) {
|
|
mathJax = {};
|
|
}
|
|
|
|
mathJax.version = '0.2';
|
|
|
|
mathJax.loaded = false;
|
|
|
|
mathJax.config = $.extend( true, {
|
|
root: mw.config.get('wgExtensionAssetsPath') + '/Math/modules/MathJax',
|
|
config: ['TeX-AMS-texvc_HTML.js'],
|
|
'v1.0-compatible': false,
|
|
displayAlign: 'left',
|
|
menuSettings: {
|
|
zoom: 'Click'
|
|
},
|
|
'HTML-CSS': {
|
|
imageFont: null,
|
|
availableFonts: ['TeX'],
|
|
mtextFontInherit: true
|
|
},
|
|
MathMenu: {
|
|
showLocale: false
|
|
}
|
|
}, mathJax.config );
|
|
|
|
mathJax.Config = function () {
|
|
MathJax.Hub.Config( mathJax.config );
|
|
MathJax.OutputJax.fontDir = mw.config.get('wgExtensionAssetsPath') + '/Math/modules/MathJax/fonts';
|
|
MathJax.Localization.locale = mw.config.get('wgUserLanguage');
|
|
};
|
|
|
|
/**
|
|
* 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;
|
|
};
|
|
|
|
mathJax.Load = function () {
|
|
var config, script;
|
|
if (this.loaded) {
|
|
return true;
|
|
}
|
|
|
|
// 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 );
|
|
|
|
// create startup element
|
|
mw.loader.load('ext.math.mathjax');
|
|
|
|
this.loaded = true;
|
|
|
|
return false;
|
|
};
|
|
|
|
$( document ).ready( function () {
|
|
mathJax.Load();
|
|
} );
|
|
|
|
}( mediaWiki, jQuery ) );
|