jQMath - MathML中的基本数学求和等效线

时间:2013-05-14 20:22:06

标签: jquery math mathml jqmath

我知道jqMath不支持普通的低数学,所以我创建了一个小的工作,使用css和jQuery,它在表格单元格的底部添加了一个边框。这在Chrome,IE和Safari中运行良好,使用fmath(假数学)来表示MathML表,但在使用本机MathML标记的Firefox中,它不受支持。事实上,我似乎无法使用jQuery为元素添加一个类,即使我发现它们很好。所以说,是否有一个设置允许我强制Firefox(或其他浏览器)使用假数学表,直到浏览器更好地支持它?或者,有什么方法我不知道哪个允许我将总和行添加到原生MathML源?

一些思考的代码:

<div class=”row math”>
<div class=”col2”>
<p><strong>First Equation</strong></p>
$\\table
x + y,=,9;
\cl "red"{6}+ y,=,9;
6 + y,=,9;
\cl "math-sum red redunderline" {-6},\cl "math-sum redunderline" {&nbsp;}, \cl "math-sum red redunderline" {-6};
y,=,\cl "red" {3};$ <br/>
<p> The solution to this system is <br />
  x = 6, y = 3.</p>
</div>
<div class=”col2”> $\table
x - y,=,3;
\cl "red" {6}- y,=,3;
6 + y,=,9;
\cl "redunderline math-sum red"{-6},,\cl "redunderline math-sum red"{-6};
-y,=,\cl "red" {-3};
y,=,\cl "red" {3};$ <br>
<p> The solution to this system is <br />
  x = 6, y = 3.</p>
</div>
</div>

用于处理下划线的CSS

<style type=”text/css”>
/* jqMath is using important tags which requires important to override contents inside a css file*/
.math .math-sum.red,
.redunderline { 
    border-bottom: #a20000 1px solid !important; 
}
</style>

jQuery移动下划线:

// Add red underline to jqMath fake table markup
if($('td.fm-mtd:has(.red.math-sum)').selector === 'td.fm-mtd:has(.red.math-sum)') {
    $('td.fm-mtd:has(.red.math-sum)').addClass('redunderline');
}
if($('td.fm-mtd:has(.red.math-sum-row)').selector === 'td.fm-mtd:has(.red.math-sum-row)') {
    $('td.fm-mtd:has(.red.math-sum-row)').parent().addClass('redunderline');
}

if($('td.fm-mtd.mrow:has(.red.math-sum-row)').selector === 'td.fm-mtd.mrow:has(.red.math-sum-row)') {
    $('td.fm-mtd:has(.red.math-sum-row)').parent().addClass('redunderline');
}


// Add red underline for real math table markup
if($('mtd:has(.red.math-sum))').selector === 'mtd:has(.red.math-sum)') {
    $('mtd:has(.red.math-sum)').addClass('redunderline');
    //addClassML($('mtd:has(.red.math-sum)'),'redunderline');
}

// This SHOULD work, but doesn't add the class in FF
//$('.red.math-sum').parent().parent().addClass('redunderline'); 
if($('mtd:has(.red.math-sum-row))') != " ") {
    addClassML($('mtd:has(.red.math-sum-row)').parent(),'redunderline');
}
if($('mtd:has(.red.math-sum))') != " ") {
    addClassML($('mtd:has(.red.math-sum)').parent(),'redunderline');
}


/* This is NOT the prefered way to add a class - Firefox was ignoring addClass jQuery
function when in math markup */

function addClassML(element,newClassString){
if(typeof element === 'object' && newClassString === 'string' && newClassString.length > 0) {
    var i,n=0;
    newClass=newClassString.split(",");
    for(i=0;i<newClass.length;i++){
        var currentClass = $(element).attr("class");
        if(typeof(currentClass) == 'string' && currentClass > 0) {
           if(currentClass.indexOf(" "+newClass[i]+" ")==-1){
                   $(element).attr("class",currentClass+=" "+newClass[i]);
                   n++;
           }
        } else {
            $(element).attr("class",newClass[i]);
        }
    }
    return n;
} else {
    return -1;
}
} 

1 个答案:

答案 0 :(得分:0)

我在使用jQuery向XML元素添加类时遇到了麻烦,例如Firefox MathML元素。请参阅jqmath-0.4.0.js中的M.addClass,了解我在jqMath中所做的事情 - 基本上我在XML元素上调用element.setAttribute('class', ...),这相当于您的addClassML。 (或者或许更高版本的jQuery的.addClass()可能有一天会自己做这个?)

正如您所说,jqMath或Firefox MathML不支持MathML的基础数学(http://www.w3.org/TR/MathML3/chapter3.html#presm.elementary)。但它只处理数字和操作,而不是变量,无论如何都不会严格涵盖你的例子。