Skip to content

Commit

Permalink
Simplify mathml test and remove async stuff. Fixes Modernizr#682
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanseddon committed Jul 12, 2013
1 parent 780a1c0 commit f67041a
Showing 1 changed file with 8 additions and 36 deletions.
44 changes: 8 additions & 36 deletions feature-detects/mathml.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,19 @@
Detects support for MathML, for mathematic equations in web pages.
*/
define(['Modernizr', 'createElement', 'addTest'], function( Modernizr, createElement, addTest ) {
define(['Modernizr', 'testStyles'], function( Modernizr, testStyles ) {
// Based on work by Davide (@dpvc) and David (@davidcarlisle)
// in https://github.com/mathjax/MathJax/issues/182

Modernizr.addAsyncTest('mathml', function() {
var waitTime = 300;
setTimeout(runMathMLTest, waitTime);
// Hack to make sure that the body exists
// TODO:: find a more reasonable method of
// doing this.
function runMathMLTest() {
if (!document.body && !document.getElementsByTagName('body')[0]) {
setTimeout(runMathMLTest, waitTime);
return;
}
addTest(function () {
var hasMathML = false;
if ( document.createElementNS ) {
var ns = "http://www.w3.org/1998/Math/MathML";
var div = createElement("div");
Modernizr.addTest('mathml', function() {
var ret;

div.style.position = "absolute";
Modernizr.testStyles("#modernizr{position:absolute}", function(node){
node.innerHTML = "<math><mfrac><mi>xx</mi><mi>yy</mi></mfrac></math>";

var mfrac = div.appendChild(document.createElementNS(ns,"math"))
.appendChild(document.createElementNS(ns,"mfrac"));
ret = node.offsetHeight > node.offsetWidth;
});

mfrac.appendChild(document.createElementNS(ns,"mi"))
.appendChild(document.createTextNode("xx"));

mfrac.appendChild(document.createElementNS(ns,"mi"))
.appendChild(document.createTextNode("yy"));

document.body.appendChild(div);

hasMathML = div.offsetHeight > div.offsetWidth;

// Clean up the element
document.body.removeChild(div);
}
return hasMathML;
});
}
return ret;
});
});

0 comments on commit f67041a

Please sign in to comment.