r112857 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112856‎ | r112857 | r112858 >
Date:00:26, 2 March 2012
Author:brion
Status:ok
Tags:1.19, mathjax 
Comment:
* (bug 34828) Fix MathJax initializer to operate on images as well as text form

Warning: this piggybacks on 'alt' text and can be broken if a manual alt text was specified on a <math> bit. Needs to be more nativey.
Also cleaned up the conditional setup code since we're already only called when a <math> is present.
Modified paths:
  • /trunk/extensions/Math/modules/MathJax-custom/extensions/TeX/texvc.js (modified) (history)
  • /trunk/extensions/Math/modules/ext.math.mathjax.enabler.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Math/modules/MathJax-custom/extensions/TeX/texvc.js
@@ -23,27 +23,23 @@
2424 this.previewClass = MathJax.Hub.config.preRemoveClass;
2525 this.configured = true;
2626 }
27 - var span, i;
28 - if ((!element || element == document.body) && mathJax.span) { // dirty hack
29 - span = mathJax.span;
30 - i = mathJax.spanIndex;
31 - }
32 - else {
33 - if (typeof(element) === "string") {element = document.getElementById(element)}
34 - if (!element) {element = this.config.element || document.body}
35 - span = element.getElementsByTagName("span");
36 - i = span.length-1;
37 - }
38 - for (; i >= 0; i--)
39 - if (span[i].className === "tex") this.ConvertMath(span[i])
 27+ var that = this;
 28+ $('span.tex, img.tex', element || document).each(function(i, span) {
 29+ that.ConvertMath(span);
 30+ });
4031 },
4132
4233 ConvertMath: function (node) {
4334 var parent = node.parentNode,
4435 mode = parent.tagName === "DD" && parent.firstChild === parent.lastChild ? "; mode=display" : "",
 36+ tex;
 37+ if (node.nodeName == 'IMG') {
 38+ tex = node.alt;
 39+ } else {
4540 tex = node.innerHTML.substring(node.innerHTML[0]=='$',node.innerHTML.length-(node.innerHTML[node.innerHTML.length-1]=='$'));
 41+ tex = tex.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&nbsp;/g," ");
 42+ }
4643
47 - tex = tex.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&nbsp;/g," ");
4844 tex = tex.replace(/\\iiint([^!]*)!\\!\\!\\!\\!.*\\subset\\!\\supset/g,"\\iiint$1mkern-2.5em\\subset\\!\\supset").replace(/\\iint([^!]*)!\\!\\!\\!\\!\\!\\!\\!\\!\\!\\!(.*)\\subset\\!\\supset/g,"\\iint$1mkern-1.65em$2\\subset\\!\\!\\supset").replace(/\\int\\!\\!\\!(\\!)+\\int\\!\\!\\!(\\!)+\\int([^!]*)!\\!\\!\\!\\!.*\\bigcirc(\\,)*/g,"\\iiint$3mkern-2.5em\\subset\\!\\supset").replace(/\\int\\!\\!\\!(\\!)+\\int([^!]*)!\\!\\!\\!\\!\\!\\!\\!\\!(.*)\\bigcirc(\\,)*/g,"\\iint$2mkern-1.65em$3\\subset\\!\\!\\supset");
4945 if (mode === "") {
5046 tex = tex.replace(/ *\\scriptstyle(\W)/g,"\\textstyle$1").replace(/ *\\scriptscriptstyle(\W)/g,"\\scriptstyle$1");
Index: trunk/extensions/Math/modules/ext.math.mathjax.enabler.js
@@ -44,26 +44,18 @@
4545 if (this.loaded)
4646 return true;
4747
48 - var span = element.getElementsByTagName("span"), i;
49 - for (i = span.length-1; i >= 0; i--) {
50 - if (span[i].className === "tex") {
51 -// this.span = span;
52 -// this.spanIndex = i;
 48+ // create configuration element
 49+ var config = 'mathJax.Config();';
 50+ var script = document.createElement( 'script' );
 51+ script.setAttribute( 'type', 'text/x-mathjax-config' );
 52+ if ( window.opera ) script.innerHTML = config; else script.text = config;
 53+ document.getElementsByTagName('head')[0].appendChild( script );
5354
54 - // create configuration element
55 - var config = 'mathJax.Config();';
56 - var script = document.createElement( 'script' );
57 - script.setAttribute( 'type', 'text/x-mathjax-config' );
58 - if ( window.opera ) script.innerHTML = config; else script.text = config;
59 - document.getElementsByTagName('head')[0].appendChild( script );
 55+ // create startup element
 56+ mediaWiki.loader.load('ext.math.mathjax');
6057
61 - // create startup element
62 - mediaWiki.loader.load('ext.math.mathjax');
 58+ this.loaded = true;
6359
64 - this.loaded = true;
65 - break;
66 - }
67 - }
6860 return false;
6961 }
7062

Status & tagging log