--- loncom/html/adm/LC_math_editor/dist/LC_math_editor.min.js 2014/09/24 18:14:35 1.1 +++ loncom/html/adm/LC_math_editor/dist/LC_math_editor.min.js 2015/02/24 15:20:41 1.2 @@ -1,43 +1,55 @@ -'use strict';var LCMATH=function(){function k(){this.operators=[]}function e(a,b,c,f){this.type=a;this.op=b;this.value=c;this.children=f}function n(a,b,c,f,e,g){this.id=a;this.arity=b;this.lbp=c;this.rbp=f;this.nud=e;this.led=g}function p(a,b,c){this.msg=a;this.from=b;this.to=c?c:this.from}function r(a,b,c){this.implicit_operators="undefined"==typeof a?!1:a;this.unit_mode="undefined"==typeof b?!1:b;this.constants="undefined"==typeof c?[]:c;this.defs=new k;this.defs.define();this.operators=this.defs.operators; -this.oph={};for(a=0;a=",80,80);this.infix("<", -80,80);this.infix(">",80,80);this.separator(")");this.separator(k.ARG_SEPARATOR);this.operator("(",n.BINARY,200,200,function(a){var b=a.expression(0);a.advance(")");return b},function(a,b){if(b.type!=e.NAME&&b.type!=e.SUBSCRIPT)throw new p("Function name expected before a parenthesis.",a.tokens[a.token_nr-1].from);var c=[b];if(null==a.current_token||null==a.current_token.op||")"!==a.current_token.op.id)for(;;){c.push(a.expression(0));if(null==a.current_token||null==a.current_token.op||a.current_token.op.id!== -k.ARG_SEPARATOR)break;a.advance(k.ARG_SEPARATOR)}a.advance(")");return new e(e.FUNCTION,this,"(",c)});this.separator("]");this.operator("[",n.BINARY,200,70,function(a){var b=[];if(null==a.current_token||null==a.current_token.op||"]"!==a.current_token.op.id)for(;;){b.push(a.expression(0));if(null==a.current_token||null==a.current_token.op||a.current_token.op.id!==k.ARG_SEPARATOR)break;a.advance(k.ARG_SEPARATOR)}a.advance("]");return new e(e.VECTOR,this,null,b)},function(a,b){if(b.type!=e.NAME&&b.type!= -e.SUBSCRIPT)throw new p("Name expected before a square bracket.",a.tokens[a.token_nr-1].from);var c=[b];if(null==a.current_token||null==a.current_token.op||"]"!==a.current_token.op.id)for(;;){c.push(a.expression(0));if(null==a.current_token||null==a.current_token.op||a.current_token.op.id!==k.ARG_SEPARATOR)break;a.advance(k.ARG_SEPARATOR)}a.advance("]");return new e(e.SUBSCRIPT,this,"[",c)})};e.UNKNOWN=0;e.NAME=1;e.NUMBER=2;e.OPERATOR=3;e.FUNCTION=4;e.VECTOR=5;e.SUBSCRIPT=6;e.COLORS="#E01010 #0010FF #009000 #FF00FF #00B0B0 #F09000 #800080 #F080A0 #6090F0 #902000 #70A050 #A07060 #5000FF #E06050 #008080 #808000".split(" "); -e.prototype.toString=function(){var a="(";switch(this.type){case e.UNKNOWN:a+="UNKNOWN";break;case e.NAME:a+="NAME";break;case e.NUMBER:a+="NUMBER";break;case e.OPERATOR:a+="OPERATOR";break;case e.FUNCTION:a+="FUNCTION";break;case e.VECTOR:a+="VECTOR";break;case e.SUBSCRIPT:a+="SUBSCRIPT"}this.op&&(a+=" '"+this.op.id+"'");this.value&&(a+=" '"+this.value+"'");if(this.children){for(var a=a+" [",b=0;bthis.children.length?d.appendChild(this.mo("lim")):(b=document.createElement("munder"),b.appendChild(this.mo("lim")),h=document.createElement("mrow"),h.appendChild(f.toMathML(a)),h.appendChild(this.mo("\u2192")),h.appendChild(l.toMathML(a)),null!=g&&("plus"==g.value?h.appendChild(this.mo("+")):"minus"==g.value&&h.appendChild(this.mo("-"))),b.appendChild(h), -d.appendChild(b)),d.appendChild(c.toMathML(a));else{if("binomial"==b.value){d=document.createElement("mrow");d.appendChild(this.mo("("));l=document.createElement("mtable");for(c=1;c=":"\u2265","<=":"\u2264",inf:"\u221e",minf:"-\u221e",hbar:"\u210f",G:"\ud835\udca2"};n.UNKNOWN=0;n.UNARY=1;n.BINARY=2;n.TERNARY=3;p.prototype.toString=function(){return this.msg+" at "+this.from+" - "+this.to};r.prototype.expression=function(a){var b, -c=this.current_token;if(null==c)throw new p("Expected something at the end",this.tokens[this.tokens.length-1].to+1);this.advance();if(null==c.op)b=new e(c.type,null,c.value,null);else{if(null==c.op.nud)throw new p("Unexpected operator '"+c.op.id+"'",c.from);b=c.op.nud(this)}for(;null!=this.current_token&&null!=this.current_token.op&&a=this.tokens.length?this.current_token=null:(this.current_token=this.tokens[this.token_nr],this.token_nr+=1)};r.prototype.addHiddenOperators=function(){for(var a=this.defs.findOperator("*"),b=this.defs.findOperator("`"),c=!1,f=!1,e=0;ee+2&&this.tokens[e+2].type==m.NAME)){var h,k;d.type==m.NAME?(h=d,k=e+1):(k=e+2,h=this.tokens[k]);for(var q=0;qk+1&&"("==this.tokens[k+1].value)for(k="pow sqrt abs exp factorial diff integrate sum product limit binomial matrix ln log log10 mod signum ceiling floor sin cos tan asin acos atan atan2 sinh cosh tanh asinh acosh atanh".split(" "), -q=0;q=a)b++,a=this.text.charAt(b);else{if("0"<=a&&"9">=a||(a===k.DECIMAL_SIGN_1||a===k.DECIMAL_SIGN_2)&&"0"<=this.text.charAt(b+1)&&"9">=this.text.charAt(b+1)){c="";if(a!==k.DECIMAL_SIGN_1&&a!==k.DECIMAL_SIGN_2)for(b++,c+=a;;){a=this.text.charAt(b);if("0">a||"9"a||"9"a||"9"=a)}var g=+c.replace(k.DECIMAL_SIGN_1,".").replace(k.DECIMAL_SIGN_2,".");if(isFinite(g)){e.push(new m(m.NUMBER,f,b-1,c,null));continue}else throw new p("syntax error in number",f,b);}for(c=0;c=a||"A"<=a&&"Z">=a){c=a;for(b++;;)if(a=this.text.charAt(b),"a"<=a&&"z">=a||"A"<=a&&"Z">=a||"0"<=a&&"9">=a||"_"===a)c+=a,b++;else break;e.push(new m(m.NAME,f,b-1,c,null))}else throw new p("unrecognized operator",f,b);}return e};m.UNKNOWN=0;m.NAME=1;m.NUMBER=2;m.OPERATOR=3;"use strict";var t=!1;return{Definitions:k,ENode:e,Operator:n,ParseException:p,Parser:r,initEditors:function(){if(!t){t=!0; -for(var a=[],b=document.getElementsByClassName("math"),c=0;c=",80,80);this.infix("<",80,80);this.infix(">",80,80);this.separator(")");this.separator(m.ARG_SEPARATOR);this.separator(m.INTERVAL_SEPARATOR);var b=this;this.operator("(",p.BINARY,200,200,function(a){var c=a.expression(0);if(null!=a.current_token&&null!=a.current_token.op&&a.current_token.op.id==m.INTERVAL_SEPARATOR)return b.buildInterval(!1,c,this,a);a.advance(")");return c},function(a,b){if(b.type!=e.NAME&&b.type!=e.SUBSCRIPT)throw new n("Function name expected before a parenthesis.", +a.tokens[a.token_nr-1].from);var g=[b];if(null==a.current_token||null==a.current_token.op||")"!==a.current_token.op.id)for(;;){g.push(a.expression(0));if(null==a.current_token||null==a.current_token.op||a.current_token.op.id!==m.ARG_SEPARATOR)break;a.advance(m.ARG_SEPARATOR)}a.advance(")");return new e(e.FUNCTION,this,"(",g)});this.separator("]");this.operator("[",p.BINARY,200,70,function(a){var c=[];if(null==a.current_token||null==a.current_token.op||"]"!==a.current_token.op.id){var g=a.expression(0); +if(null!=a.current_token&&null!=a.current_token.op&&a.current_token.op.id==m.INTERVAL_SEPARATOR)return b.buildInterval(!0,g,this,a);for(;;){c.push(g);if(null==a.current_token||null==a.current_token.op||a.current_token.op.id!==m.ARG_SEPARATOR)break;a.advance(m.ARG_SEPARATOR);g=a.expression(0)}}a.advance("]");return new e(e.VECTOR,this,null,c)},function(a,b){if(b.type!=e.NAME&&b.type!=e.SUBSCRIPT)throw new n("Name expected before a square bracket.",a.tokens[a.token_nr-1].from);var g=[b];if(null==a.current_token|| +null==a.current_token.op||"]"!==a.current_token.op.id)for(;;){g.push(a.expression(0));if(null==a.current_token||null==a.current_token.op||a.current_token.op.id!==m.ARG_SEPARATOR)break;a.advance(m.ARG_SEPARATOR)}a.advance("]");return new e(e.SUBSCRIPT,this,"[",g)});this.separator("}");this.prefix("{",200,function(a){var b=[];if(null==a.current_token||null==a.current_token.op||"}"!==a.current_token.op.id)for(;;){b.push(a.expression(0));if(null==a.current_token||null==a.current_token.op||a.current_token.op.id!== +m.ARG_SEPARATOR)break;a.advance(m.ARG_SEPARATOR)}a.advance("}");return new e(e.SET,this,null,b)});this.prefix("$",300,function(a){var b=a.expression(300);if(b.type!=e.NAME)throw new n("Variable name expected after a $.",a.tokens[a.token_nr-1].from);b.value="$"+b.value;return b})};"use strict";e.UNKNOWN=0;e.NAME=1;e.NUMBER=2;e.OPERATOR=3;e.FUNCTION=4;e.VECTOR=5;e.INTERVAL=6;e.SET=7;e.SUBSCRIPT=8;e.COLORS="#E01010 #0010FF #009000 #FF00FF #00B0B0 #F09000 #800080 #F080A0 #6090F0 #902000 #70A050 #A07060 #5000FF #E06050 #008080 #808000".split(" "); +e.NOT_AN_INTERVAL=0;e.OPEN_OPEN=1;e.OPEN_CLOSED=2;e.CLOSED_OPEN=3;e.CLOSED_CLOSED=4;e.prototype.toString=function(){var b="(";switch(this.type){case e.UNKNOWN:b+="UNKNOWN";break;case e.NAME:b+="NAME";break;case e.NUMBER:b+="NUMBER";break;case e.OPERATOR:b+="OPERATOR";break;case e.FUNCTION:b+="FUNCTION";break;case e.VECTOR:b+="VECTOR";break;case e.INTERVAL:b+="INTERVAL";break;case e.SET:b+="SET";break;case e.SUBSCRIPT:b+="SUBSCRIPT"}this.op&&(b+=" '"+this.op.id+"'");this.value&&(b+=" '"+this.value+ +"'");if(this.children){for(var b=b+" [",a=0;athis.children.length?d.appendChild(this.mo("lim")):(a=document.createElement("munder"),a.appendChild(this.mo("lim")),h=document.createElement("mrow"),h.appendChild(g._toMathML(b)),h.appendChild(this.mo("\u2192")),h.appendChild(f._toMathML(b)),null!=k&&("plus"==k.value?h.appendChild(this.mo("+")):"minus"==k.value&&h.appendChild(this.mo("-"))),a.appendChild(h),d.appendChild(a)), +d.appendChild(c._toMathML(b));else if("binomial"==a.value){d=document.createElement("mrow");d.appendChild(this.mo("("));g=document.createElement("mtable");for(f=1;f=":"\u2265","<=":"\u2264",inf:"\u221e",minf:"-\u221e",hbar:"\u210f",G:"\ud835\udca2"};"use strict";p.UNKNOWN=0;p.UNARY=1;p.BINARY=2;p.TERNARY=3;"use strict";n.prototype.toString=function(){return this.msg+" at "+this.from+" - "+this.to};"use strict";r.prototype.expression=function(b){var a,c= +this.current_token;if(null==c)throw new n("Expected something at the end",this.tokens[this.tokens.length-1].to+1);this.advance();if(null==c.op)a=new e(c.type,null,c.value,null);else{if(null==c.op.nud)throw new n("Unexpected operator '"+c.op.id+"'",c.from);a=c.op.nud(this)}for(;null!=this.current_token&&null!=this.current_token.op&&b=this.tokens.length?this.current_token=null:(this.current_token=this.tokens[this.token_nr],this.token_nr+=1)};r.prototype.addHiddenOperators=function(){for(var b=this.defs.findOperator("*"),a=this.defs.findOperator("`"),c=!1,g=!1,f=0;ff+2&&this.tokens[f+2].type==l.NAME)){var h,m;d.type==l.NAME?(h=d,m=f+1):(m=f+2,h=this.tokens[m]);for(var s=0;sm+1&&"("==this.tokens[m+1].value)for(m="pow sqrt abs exp factorial diff integrate sum product limit binomial matrix ln log log10 mod signum ceiling floor sin cos tan asin acos atan atan2 sinh cosh tanh asinh acosh atanh".split(" "), +s=0;s=b)a++,b=this.text.charAt(a);else{if("0"<=b&&"9">=b||(b===m.DECIMAL_SIGN_1||b===m.DECIMAL_SIGN_2)&&"0"<=this.text.charAt(a+1)&&"9">=this.text.charAt(a+1)){c="";if(b!==m.DECIMAL_SIGN_1&&b!==m.DECIMAL_SIGN_2)for(a++,c+=b;;){b=this.text.charAt(a);if("0">b||"9"b||"9"b||"9"=b)}var e=+c.replace(m.DECIMAL_SIGN_1,".").replace(m.DECIMAL_SIGN_2,".");if(isFinite(e)){f.push(new l(l.NUMBER,g,a-1,c,null));continue}else throw new n("syntax error in number",g,a);}for(c=0;c=b||"A"<=b&&"Z">=b||"\u03b1"<=b&&"\u03c9">=b||"\u0391"<=b&&"\u03a9">=b||"\u00b5"==b){c=b;for(a++;;)if(b=this.text.charAt(a),"a"<=b&&"z">=b||"A"<=b&&"Z">=b||"\u03b1"<=b&&"\u03c9">=b||"\u0391"<=b&&"\u03a9">=b||"\u00b5"==b||"0"<=b&&"9">=b||"_"===b)c+=b,a++;else break;f.push(new l(l.NAME,g,a-1,c,null))}else throw new n("unrecognized operator",g,a);}return f};"use strict";l.UNKNOWN= +0;l.NAME=1;l.NUMBER=2;l.OPERATOR=3;"use strict";var u=function(b){var a,c,e,f,k;a=b.ta;c=b.output_node;a=a.value;f="";for(k=a;k!=f;)f=k,k=f.replace(/\[[^\[\]]*\]/g,"");if(k.split("[").length==k.split("]").length){for(f="";k!=f;)f=k,k=f.replace(/\([^\(\)]*\)/g,"");if(k.split("(").length==k.split(")").length){for(f="";k!=f;)f=k,k=f.replace(/\{[^\{\}]*\}/g,"");k.split("{").length==k.split("}").length&&-1!=k.indexOf(m.ARG_SEPARATOR)&&(a="["+a+"]")}}if(a!=b.oldtxt){for(b.oldtxt=a;null!=c.firstChild;)c.removeChild(c.firstChild); +c.removeAttribute("title");if(""!=a){b=b.parser;try{if(e=b.parse(a),null!=e){var d=document.createElement("math");d.setAttribute("display","block");d.appendChild(e.toMathML());c.appendChild(d);MathJax.Hub.Queue(["Typeset",MathJax.Hub,c])}}catch(h){e="error: "+h,c.setAttribute("title",e),h instanceof n?(c.appendChild(document.createTextNode(a.substring(0,h.from))),e=document.createElement("span"),e.appendChild(document.createTextNode(a.substring(h.from,h.to+1))),e.className="math-error",c.appendChild(e), +h.tod.bottom+b.offsetHeight?c+a.offsetHeight+"px":c-b.offsetHeight+"px"};c.nextSibling?c.parentNode.insertBefore(f,c.nextSibling):c.parentNode.appendChild(f);k= +function(a){return function(b){a.style.display="none"}};c.addEventListener("blur",k(f),!1);c.addEventListener("focus",function(a,b){return function(c){""!=a.value&&(b.style.display="block",m(a,b))}}(c,f),!1);f.addEventListener("mouseenter",k(f),!1);k=q.length;q[k]={ta:c,output_node:f,oldtxt:"",parser:new r(e,d,h)};e=function(a){return function(b){var c=q[a];u(c);document.activeElement==c.ta&&(""!=c.ta.value?(c.output_node.style.display="block",MathJax.Hub.Queue(function(){m(c.ta,c.output_node)})): +c.output_node.style.display="none")}}(k);""!=c.value&&e();c.addEventListener("change",e,!1);c.addEventListener("keyup",e,!1)}else{var l,n=q[k].parser;if(h||0!=n.constants.length)if(h){if(l=n.constants.length==h.length)for(f=0;f