Convert MathJax enabler script to tabs

Per our coding conventions:
https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript

Change-Id: I679246089ec485678088ff08f3a46d8b74a262c5
This commit is contained in:
Derk-Jan Hartman 2014-04-07 10:59:24 +02:00
parent c5b0b15d8f
commit 28efa34ffd
1 changed files with 213 additions and 211 deletions

View File

@ -3,6 +3,8 @@
*/ */
/*global mathJax:true, MathJax:true */ /*global mathJax:true, MathJax:true */
( function ( mw, $ ) { ( function ( mw, $ ) {
'use strict';
if ( typeof mathJax === 'undefined' ) { if ( typeof mathJax === 'undefined' ) {
mathJax = {}; mathJax = {};
} }
@ -11,11 +13,11 @@
mathJax.loaded = false; mathJax.loaded = false;
mathJax.locale = mw.config.get('wgUserLanguage'); mathJax.locale = mw.config.get( 'wgUserLanguage' );
// See http://docs.mathjax.org/en/latest/options/index.html // See http://docs.mathjax.org/en/latest/options/index.html
mathJax.config = $.extend( true, { mathJax.config = $.extend( true, {
root: mw.config.get('wgExtensionAssetsPath') + '/Math/modules/MathJax/unpacked', root: mw.config.get( 'wgExtensionAssetsPath' ) + '/Math/modules/MathJax/unpacked',
'v1.0-compatible': false, 'v1.0-compatible': false,
menuSettings: { menuSettings: {
zoom: 'Click' zoom: 'Click'
@ -34,7 +36,7 @@
* @param {string} relative path to a MathJax file * @param {string} relative path to a MathJax file
* @return {string} MediaWiki module containing the file * @return {string} MediaWiki module containing the file
*/ */
mathJax.getModuleNameFromFile = function (file) { mathJax.getModuleNameFromFile = function ( file ) {
var regexp, module; var regexp, module;
// These modules are loaded at startup and thus don't need to be specified: // These modules are loaded at startup and thus don't need to be specified:
@ -46,7 +48,7 @@
module = 'ext.math.mathjax.'; module = 'ext.math.mathjax.';
regexp = file.match(/(.*)\/jax\.js/); regexp = file.match( /(.*)\/jax\.js/ );
if ( regexp ) { if ( regexp ) {
// These are jax.js files of input, element or output modules: // These are jax.js files of input, element or output modules:
// - ext.math.mathjax.jax.input.MathML // - ext.math.mathjax.jax.input.MathML
@ -55,32 +57,32 @@
// - ext.math.mathjax.jax.output.NativeMML // - ext.math.mathjax.jax.output.NativeMML
// - ext.math.mathjax.jax.output.HTML-CSS // - ext.math.mathjax.jax.output.HTML-CSS
// - ext.math.mathjax.jax.output.SVG // - ext.math.mathjax.jax.output.SVG
return module + regexp[1].replace(/\//g,'.'); return module + regexp[1].replace( /\//g, '.' );
} }
if ( file.match(/jax\/element\/mml\/optable/) ) { if ( file.match( /jax\/element\/mml\/optable/ ) ) {
return module + 'jax.element.mml.optable'; return module + 'jax.element.mml.optable';
} }
regexp = file.match(/jax\/output\/(HTML-CSS|SVG)/); regexp = file.match( /jax\/output\/(HTML-CSS|SVG)/ );
if ( regexp ) { if ( regexp ) {
module += 'jax.output.' + regexp[1] + '.'; module += 'jax.output.' + regexp[1] + '.';
if ( file.match(/autoload/) ) { if ( file.match( /autoload/ ) ) {
return module + 'autoload'; return module + 'autoload';
} }
if ( file.match(/fonts\/TeX\/fontdata/) ) { if ( file.match( /fonts\/TeX\/fontdata/ ) ) {
return module + 'fonts.TeX.fontdata'; return module + 'fonts.TeX.fontdata';
} }
if ( file.match(/fonts\/TeX\/.*\/.*\/Main\.js/) ) { if ( file.match( /fonts\/TeX\/.*\/.*\/Main\.js/ ) ) {
return module + 'fonts.TeX.MainJS'; return module + 'fonts.TeX.MainJS';
} }
if ( file.match(/fonts\/TeX\/Main/) ) { if ( file.match( /fonts\/TeX\/Main/ ) ) {
return module + 'fonts.TeX.Main'; return module + 'fonts.TeX.Main';
} }
if ( file.match(/fonts\/TeX\/AMS/) ) { if ( file.match( /fonts\/TeX\/AMS/ ) ) {
return module + 'fonts.TeX.AMS'; return module + 'fonts.TeX.AMS';
} }
if ( file.match(/fonts\/TeX/) ) { if ( file.match( /fonts\/TeX/ ) ) {
return module + 'fonts.TeX.Extra'; return module + 'fonts.TeX.Extra';
} }
} }
@ -97,7 +99,7 @@
mathJax.Init = function () { mathJax.Init = function () {
// Configure MathJax // Configure MathJax
MathJax.Hub.Config( mathJax.config ); MathJax.Hub.Config( mathJax.config );
MathJax.OutputJax.fontDir = mw.config.get('wgExtensionAssetsPath') + '/Math/modules/MathJax/fonts'; MathJax.OutputJax.fontDir = mw.config.get( 'wgExtensionAssetsPath' ) + '/Math/modules/MathJax/fonts';
// Redefine MathJax.Hub.Startup.Jax // Redefine MathJax.Hub.Startup.Jax
MathJax.Hub.Startup.Jax = function () { MathJax.Hub.Startup.Jax = function () {
@ -106,14 +108,14 @@
config = MathJax.Hub.config; config = MathJax.Hub.config;
jax = MathJax.Hub.outputJax; jax = MathJax.Hub.outputJax;
for ( i = 0, k = 0; i < config.jax.length; i++ ) { for ( i = 0, k = 0; i < config.jax.length; i++ ) {
name = config.jax[i].substr(7); name = config.jax[i].substr( 7 );
if ( config.jax[i].substr(0,7) === 'output/' && jax.order[name] === null ) { if ( config.jax[i].substr( 0,7 ) === 'output/' && jax.order[name] === null ) {
jax.order[name] = k; jax.order[name] = k;
k++; k++;
} }
} }
queue = MathJax.Callback.Queue(); queue = MathJax.Callback.Queue();
callback = MathJax.Callback({}); callback = MathJax.Callback( {} );
return queue.Push( return queue.Push(
['Post', MathJax.Hub.Startup.signal, 'Begin Jax'], ['Post', MathJax.Hub.Startup.signal, 'Begin Jax'],
['using', mw.loader, 'ext.math.mathjax.jax.config', callback], ['using', mw.loader, 'ext.math.mathjax.jax.config', callback],
@ -126,7 +128,7 @@
MathJax.Hub.Startup.Extensions = function () { MathJax.Hub.Startup.Extensions = function () {
var queue, callback; var queue, callback;
queue = MathJax.Callback.Queue(); queue = MathJax.Callback.Queue();
callback = MathJax.Callback({}); callback = MathJax.Callback( {} );
return queue.Push( return queue.Push(
['Post', MathJax.Hub.Startup.signal, 'Begin Extensions'], ['Post', MathJax.Hub.Startup.signal, 'Begin Extensions'],
['using', mw.loader, 'ext.math.mathjax.extensions', callback], ['using', mw.loader, 'ext.math.mathjax.extensions', callback],
@ -137,25 +139,25 @@
// Redefine MathJax.Ajax.Load // Redefine MathJax.Ajax.Load
MathJax.Ajax.MathJaxLoad = MathJax.Ajax.Load; MathJax.Ajax.MathJaxLoad = MathJax.Ajax.Load;
MathJax.Ajax.Load = function (file, callback) { MathJax.Ajax.Load = function ( file, callback ) {
var type, i, module; var type, i, module;
callback = MathJax.Callback(callback); callback = MathJax.Callback( callback );
if ( file instanceof Object ) { if ( file instanceof Object ) {
for ( i in file ) { for ( i in file ) {
if ( file.hasOwnProperty(i) ) { if ( file.hasOwnProperty( i ) ) {
type = i.toUpperCase(); type = i.toUpperCase();
file = file[i]; file = file[i];
} }
} }
} else { } else {
type = file.split(/\./).pop().toUpperCase(); type = file.split( /\./ ).pop().toUpperCase();
} }
file = MathJax.Ajax.fileURL(file); file = MathJax.Ajax.fileURL( file );
if ( MathJax.Ajax.loading[file] ) { if ( MathJax.Ajax.loading[file] ) {
MathJax.Ajax.addHook(file, callback); MathJax.Ajax.addHook( file, callback );
} else { } else {
if ( MathJax.Ajax.loader[type] ) { if ( MathJax.Ajax.loader[type] ) {
module = mathJax.getModuleNameFromFile(file.substring(MathJax.Hub.config.root.length + 1)); module = mathJax.getModuleNameFromFile( file.substring( MathJax.Hub.config.root.length + 1 ) );
if ( module ) { if ( module ) {
// Use MediaWiki's resource loader. // Use MediaWiki's resource loader.
MathJax.Ajax.loading[file] = { MathJax.Ajax.loading[file] = {
@ -167,14 +169,14 @@
// Add this to the structure above after it is created to prevent // Add this to the structure above after it is created to prevent
// recursion when loading the initial localization file (before // recursion when loading the initial localization file (before
// loading message is available) // loading message is available)
MathJax.Ajax.loading[file].message = MathJax.Message.File(file); MathJax.Ajax.loading[file].message = MathJax.Message.File( file );
mw.loader.load(module); mw.loader.load( module );
} else { } else {
// Fallback to MathJax's own loader. // Fallback to MathJax's own loader.
callback = MathJax.Ajax.MathJaxLoad(file, callback); callback = MathJax.Ajax.MathJaxLoad( file, callback );
} }
} else { } else {
throw new Error('Can\'t load files of type ' + type); throw new Error( 'Can\'t load files of type ' + type );
} }
} }
return callback; return callback;
@ -183,11 +185,11 @@
// Register the final action after MathJax processing: hide // Register the final action after MathJax processing: hide
// SVG/PNG preview if thas was not done before and show MathJax's output. // SVG/PNG preview if thas was not done before and show MathJax's output.
MathJax.Hub.Startup.signal.MessageHook( 'End', function () { MathJax.Hub.Startup.signal.MessageHook( 'End', function () {
mw.loader.load('ext.math.mathml'); mw.loader.load( 'ext.math.mathml' );
}); } );
// Set MathJax's locale and load the localization data. // Set MathJax's locale and load the localization data.
MathJax.Localization.resetLocale(mathJax.locale); MathJax.Localization.resetLocale( mathJax.locale );
mathJax.locale = MathJax.Localization.locale; mathJax.locale = MathJax.Localization.locale;
MathJax.Hub.config.menuSettings.locale = mathJax.locale; MathJax.Hub.config.menuSettings.locale = mathJax.locale;
mw.loader.using( 'ext.math.mathjax.localization', function () { mw.loader.using( 'ext.math.mathjax.localization', function () {
@ -206,7 +208,7 @@
callback = $.noop; callback = $.noop;
} }
function render () { function render() {
MathJax.Hub.Queue( ['Typeset', MathJax.Hub, elem, callback] ); MathJax.Hub.Queue( ['Typeset', MathJax.Hub, elem, callback] );
} }