https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112857

Revision: 112857
Author:   brion
Date:     2012-03-02 00:26:56 +0000 (Fri, 02 Mar 2012)
Log Message:
-----------
* (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
    trunk/extensions/Math/modules/ext.math.mathjax.enabler.js

Modified: trunk/extensions/Math/modules/MathJax-custom/extensions/TeX/texvc.js
===================================================================
--- trunk/extensions/Math/modules/MathJax-custom/extensions/TeX/texvc.js        
2012-03-02 00:18:09 UTC (rev 112856)
+++ trunk/extensions/Math/modules/MathJax-custom/extensions/TeX/texvc.js        
2012-03-02 00:26:56 UTC (rev 112857)
@@ -23,27 +23,23 @@
       this.previewClass = MathJax.Hub.config.preRemoveClass;
       this.configured = true;
     }
-    var span, i;
-    if ((!element || element == document.body) && mathJax.span) {  // dirty 
hack
-      span = mathJax.span;
-      i = mathJax.spanIndex;
-    }
-    else {
-      if (typeof(element) === "string") {element = 
document.getElementById(element)}
-      if (!element) {element = this.config.element || document.body}
-      span = element.getElementsByTagName("span");
-      i = span.length-1;
-    }
-    for (; i >= 0; i--)
-      if (span[i].className === "tex") this.ConvertMath(span[i])
+    var that = this;
+    $('span.tex, img.tex', element || document).each(function(i, span) {
+               that.ConvertMath(span);
+       });
   },
 
   ConvertMath: function (node) {
     var parent = node.parentNode,
         mode = parent.tagName === "DD" && parent.firstChild === 
parent.lastChild ? "; mode=display" : "",
+               tex;
+       if (node.nodeName == 'IMG') {
+               tex = node.alt;
+       } else {
         tex = 
node.innerHTML.substring(node.innerHTML[0]=='$',node.innerHTML.length-(node.innerHTML[node.innerHTML.length-1]=='$'));
+           tex = 
tex.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&nbsp;/g,"
 ");
+       }
 
-    tex = 
tex.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&nbsp;/g,"
 ");
     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");
     if (mode === "") {
       tex = tex.replace(/ *\\scriptstyle(\W)/g,"\\textstyle$1").replace(/ 
*\\scriptscriptstyle(\W)/g,"\\scriptstyle$1");

Modified: trunk/extensions/Math/modules/ext.math.mathjax.enabler.js
===================================================================
--- trunk/extensions/Math/modules/ext.math.mathjax.enabler.js   2012-03-02 
00:18:09 UTC (rev 112856)
+++ trunk/extensions/Math/modules/ext.math.mathjax.enabler.js   2012-03-02 
00:26:56 UTC (rev 112857)
@@ -44,26 +44,18 @@
   if (this.loaded)
     return true;
 
-  var span = element.getElementsByTagName("span"), i;
-  for (i = span.length-1; i >= 0; i--) {
-    if (span[i].className === "tex") {
-//      this.span = span;
-//      this.spanIndex = i;
+  // create configuration element
+  var config = 'mathJax.Config();';
+  var 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 configuration element
-      var config = 'mathJax.Config();';
-      var 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
+  mediaWiki.loader.load('ext.math.mathjax');
 
-      // create startup element
-         mediaWiki.loader.load('ext.math.mathjax');
+  this.loaded = true;
 
-      this.loaded = true;
-      break;
-    }
-  }
   return false;
 }
 


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to