[LON-CAPA-cvs] cvs: loncom /html/adm/LC_math_editor/dist LC_math_editor.min.js /html/adm/LC_math_editor/src ui.js
damieng
damieng at source.lon-capa.org
Thu Jan 5 08:55:35 EST 2017
damieng Thu Jan 5 13:55:35 2017 EDT
Modified files:
/loncom/html/adm/LC_math_editor/dist LC_math_editor.min.js
/loncom/html/adm/LC_math_editor/src ui.js
Log:
fixed a bug in math editor positioning for equations longer than the input field
Index: loncom/html/adm/LC_math_editor/dist/LC_math_editor.min.js
diff -u loncom/html/adm/LC_math_editor/dist/LC_math_editor.min.js:1.5 loncom/html/adm/LC_math_editor/dist/LC_math_editor.min.js:1.6
--- loncom/html/adm/LC_math_editor/dist/LC_math_editor.min.js:1.5 Thu Aug 13 18:30:36 2015
+++ loncom/html/adm/LC_math_editor/dist/LC_math_editor.min.js Thu Jan 5 13:55:26 2017
@@ -48,8 +48,8 @@
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.style.border="solid 1px red",e.style.minWidth=
"1px",c.appendChild(e),h.to<a.length-1&&c.appendChild(document.createTextNode(a.substring(h.to+1)))):(a=document.createTextNode(e),c.appendChild(a))}}}},q=[];return{Definitions:l,ENode:e,Operator:p,ParseException:n,Parser:r,initEditors:function(){MathJax.Hub.Config({messageStyle:"none"});for(var b=document.getElementsByClassName("math"),a=0;a<q.length;a++){for(var c=q[a].ta,e=!1,f=0;f<b.length;f++)if(b[f]==c){e=!0;break}e||(f=q[a].output_node,f.parentNode&&f.parentNode.removeChild(f),q.splice(a,1),
a--)}for(a=0;a<b.length;a++)if(c=b[a],"TEXTAREA"==c.nodeName||"INPUT"==c.nodeName){e=-1;for(f=0;f<q.length;f++)if(q[f].ta==c){e=f;break}var m="true"===c.getAttribute("data-implicit_operators"),d="true"===c.getAttribute("data-unit_mode"),h=c.getAttribute("data-constants");h&&(h=h.split(/[\s,]+/));if(-1==e){f=document.createElement("span");f.style.display="none";f.style.position="absolute";f.style.backgroundColor="rgba(255,255,224,0.9)";f.style.color="black";f.style.border="1px solid #A0A0A0";f.style.padding=
-"5px";f.style.zIndex="1";var l=function(a,b){var c,d=a.getBoundingClientRect();c=a;for(var e=0,f=0;c&&!isNaN(c.offsetLeft)&&!isNaN(c.offsetTop);)if(e+=c.offsetLeft-c.scrollLeft,f+=c.offsetTop-c.scrollTop,c=c.offsetParent){var g=window.getComputedStyle(c);if("absolute"==g.position||"relative"==g.position)break}c=f;b.style.left=e+"px";b.style.top=window.innerHeight>d.bottom+b.offsetHeight?c+a.offsetHeight+"px":c-b.offsetHeight+"px"};c.nextSibling?c.parentNode.insertBefore(f,c.nextSibling):c.parentNode.appendChild(f);
-c.addEventListener("blur",function(a){return function(b){a.style.display="none"}}(f),!1);c.addEventListener("focus",function(a,b){return function(c){""!=a.value&&(b.style.display="block",l(a,b))}}(c,f),!1);f.addEventListener("mouseenter",function(a){return function(b){a.hasAttribute("title")||(a.style.display="none")}}(f),!1);e=q.length;q[e]={ta:c,output_node:f,oldtxt:"",parser:new r(m,d,h)};f=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(){l(c.ta,c.output_node)})):c.output_node.style.display="none")}}(e);""!=c.value&&f();c.addEventListener("change",f,!1);c.addEventListener("keyup",f,!1)}else{var k,n=q[e].parser;if(h||0!=n.constants.length)if(h){if(k=n.constants.length==h.length)for(f=0;f<h.length;f++)if(n.constants[f]!=h[f]){k=!1;break}}else k=!1;else k=!0;n.implicit_operators==m&&n.unit_mode==d&&k||(q[e].parser=new r(m,d,h),""!=c.value&&(q[e].oldtxt="",u(q[e])))}}},updateMathSpanAndDiv:function(){for(var b=
-document.getElementsByClassName("math"),a=[],c=0,e=a.length=b.length;c<e;c++)a[c]=b[c];for(c=0;c<a.length;c++)if(b=a[c],("SPAN"==b.nodeName||"DIV"==b.nodeName)&&null!=b.firstChild&&3==b.firstChild.nodeType){var e="SPAN"==b.nodeName,f=b.firstChild.nodeValue,m="true"===b.getAttribute("data-implicit_operators"),d="true"===b.getAttribute("data-unit_mode"),h=b.getAttribute("data-constants");h&&(h=h.split(/[\s,]+/));m=new r(m,d,h);try{var l=m.parse(f);if(null!=l){var k=document.createElement("math");k.setAttribute("display",
-e?"inline":"block");k.appendChild(l.toMathML(["#000000"]));b.classList.remove("math");b.removeChild(b.firstChild);b.appendChild(k);MathJax.Hub.Queue(["Typeset",MathJax.Hub,b])}}catch(n){b.firstChild.nodeValue="[syntax error in math:"+n+"]",b.classList.remove("math")}}}}}();
+"5px";f.style.zIndex="1";var l=function(a,b){var c,d=a.getBoundingClientRect();c=a;for(var e=0,f=0;c&&!isNaN(c.offsetLeft)&&!isNaN(c.offsetTop);)if(e+=c.offsetLeft-("INPUT"==c.nodeName?0:c.scrollLeft),f+=c.offsetTop-c.scrollTop,c=c.offsetParent){var g=window.getComputedStyle(c);if("absolute"==g.position||"relative"==g.position)break}c=f;b.style.left=e+"px";b.style.top=window.innerHeight>d.bottom+b.offsetHeight?c+a.offsetHeight+"px":c-b.offsetHeight+"px"};c.nextSibling?c.parentNode.insertBefore(f,
+c.nextSibling):c.parentNode.appendChild(f);c.addEventListener("blur",function(a){return function(b){a.style.display="none"}}(f),!1);c.addEventListener("focus",function(a,b){return function(c){""!=a.value&&(b.style.display="block",l(a,b))}}(c,f),!1);f.addEventListener("mouseenter",function(a){return function(b){a.hasAttribute("title")||(a.style.display="none")}}(f),!1);e=q.length;q[e]={ta:c,output_node:f,oldtxt:"",parser:new r(m,d,h)};f=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(){l(c.ta,c.output_node)})):c.output_node.style.display="none")}}(e);""!=c.value&&f();c.addEventListener("change",f,!1);c.addEventListener("keyup",f,!1)}else{var k,n=q[e].parser;if(h||0!=n.constants.length)if(h){if(k=n.constants.length==h.length)for(f=0;f<h.length;f++)if(n.constants[f]!=h[f]){k=!1;break}}else k=!1;else k=!0;n.implicit_operators==m&&n.unit_mode==d&&k||(q[e].parser=new r(m,d,h),""!=c.value&&(q[e].oldtxt=
+"",u(q[e])))}}},updateMathSpanAndDiv:function(){for(var b=document.getElementsByClassName("math"),a=[],c=0,e=a.length=b.length;c<e;c++)a[c]=b[c];for(c=0;c<a.length;c++)if(b=a[c],("SPAN"==b.nodeName||"DIV"==b.nodeName)&&null!=b.firstChild&&3==b.firstChild.nodeType){var e="SPAN"==b.nodeName,f=b.firstChild.nodeValue,m="true"===b.getAttribute("data-implicit_operators"),d="true"===b.getAttribute("data-unit_mode"),h=b.getAttribute("data-constants");h&&(h=h.split(/[\s,]+/));m=new r(m,d,h);try{var l=m.parse(f);
+if(null!=l){var k=document.createElement("math");k.setAttribute("display",e?"inline":"block");k.appendChild(l.toMathML(["#000000"]));b.classList.remove("math");b.removeChild(b.firstChild);b.appendChild(k);MathJax.Hub.Queue(["Typeset",MathJax.Hub,b])}}catch(n){b.firstChild.nodeValue="[syntax error in math:"+n+"]",b.classList.remove("math")}}}}}();
Index: loncom/html/adm/LC_math_editor/src/ui.js
diff -u loncom/html/adm/LC_math_editor/src/ui.js:1.3 loncom/html/adm/LC_math_editor/src/ui.js:1.4
--- loncom/html/adm/LC_math_editor/src/ui.js:1.3 Wed Feb 25 20:54:06 2015
+++ loncom/html/adm/LC_math_editor/src/ui.js Thu Jan 5 13:55:35 2017
@@ -156,7 +156,12 @@
var x = 0;
var y = 0;
while (el && !isNaN(el.offsetLeft) && !isNaN(el.offsetTop)) {
- x += el.offsetLeft - el.scrollLeft;
+ var scrollLeft;
+ if (el.nodeName == 'INPUT')
+ scrollLeft = 0;
+ else
+ scrollLeft = el.scrollLeft;
+ x += el.offsetLeft - scrollLeft;
y += el.offsetTop - el.scrollTop;
el = el.offsetParent;
if (el) {
More information about the LON-CAPA-cvs
mailing list