instiki/public/MathJax/extensions/MathZoom.js
2011-06-01 14:35:18 -05:00

17 lines
9 KiB
JavaScript

/*
* /MathJax/extensions/MathZoom.js
*
* Copyright (c) 2010 Design Science, Inc.
*
* Part of the MathJax library.
* See http://www.mathjax.org for details.
*
* Licensed under the Apache License, Version 2.0;
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*/
(function(a,c,e,b,h){var i="1.1";var g=a.CombineConfig("MathZoom",{delay:400,styles:{"#MathJax_Zoom":{position:"absolute","background-color":"#F0F0F0",overflow:"auto",display:"block","z-index":301,padding:".5em",border:"1px solid black",margin:0,"font-family":"serif","font-size":"85%","font-weight":"normal","font-style":"normal","text-align":"left","text-indent":0,"text-transform":"none","line-height":"normal","letter-spacing":"normal","word-spacing":"normal","word-wrap":"normal","white-space":"nowrap","float":"none","box-shadow":"5px 5px 15px #AAAAAA","-webkit-box-shadow":"5px 5px 15px #AAAAAA","-moz-box-shadow":"5px 5px 15px #AAAAAA","-khtml-box-shadow":"5px 5px 15px #AAAAAA",filter:"progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')"},"#MathJax_ZoomOverlay":{position:"absolute",left:0,top:0,"z-index":300,display:"inline-block",width:"100%",height:"100%",border:0,padding:0,margin:0,"background-color":"white",opacity:0,filter:"alpha(opacity=0)"}}});var d=function(j){if(!j){j=window.event}if(j){if(j.preventDefault){j.preventDefault()}if(j.stopPropagation){j.stopPropagation()}j.cancelBubble=true;j.returnValue=false}return false};var f=MathJax.Extension.MathZoom={version:i,settings:a.config.menuSettings,HandleEvent:function(l,j,k){if(!l){l=window.event}if(f.settings.CTRL&&!l.ctrlKey){return true}if(f.settings.ALT&&!l.altKey){return true}if(f.settings.CMD&&!l.metaKey){return true}if(f.settings.Shift&&!l.shiftKey){return true}return f[j](l,k)},Click:function(k,j){if(this.settings.zoom==="Click"){return this.Zoom(j,k)}},DblClick:function(k,j){if(this.settings.zoom==="Double-Click"){return this.Zoom(j,k)}},Mouseover:function(k,j){if(this.settings.zoom==="Hover"){f.oldMouseOver=j.onmouseover;j.onmouseover=null;j.onmousemove=this.Mousemove;j.onmouseout=this.Mouseout;return f.Timer(k,j)}},Mouseout:function(j){this.onmouseover=f.oldMouseOver;delete f.oldMouseOver;this.onmousemove=this.onmouseout=null;f.ClearTimer();return d(j)},Mousemove:function(j){return f.Timer(j||window.event,this)},Timer:function(k,j){this.ClearTimer();this.timer=setTimeout(MathJax.Callback(["Zoom",this,j,{}]),g.delay);return d(k)},ClearTimer:function(){if(this.timer){clearTimeout(this.timer);delete this.timer}},Zoom:function(s,l){this.ClearTimer();this.Remove();var v=s.parentNode;if(v.className==="MathJax_MathContainer"){v=v.parentNode}if(v.parentNode.className==="MathJax_MathContainer"){v=v.parentNode.parentNode}var q=(String(v.className).match(/^MathJax_(MathML|Display)$/)?v:s).nextSibling;var m=a.getJaxFor(q),r=m.root;var o=(b&&m.outputJax.isa(b.constructor)?"HTMLCSS":(h&&m.outputJax.isa(h.constructor)?"MathML":null));if(!o){return}var j=Math.floor(0.85*document.body.clientWidth),p=Math.floor(0.85*document.body.clientHeight);var k=c.Element("span",{style:{position:"relative",display:"inline-block",height:0,width:0},id:"MathJax_ZoomFrame"},[["span",{id:"MathJax_ZoomOverlay",onmousedown:this.Remove}],["span",{id:"MathJax_Zoom",onclick:this.Remove,style:{visibility:"hidden",fontSize:this.settings.zscale,"max-width":j+"px","max-height":p+"px"}},[["span"]]]]);var x=k.lastChild,u=x.firstChild,n=k.firstChild;s.parentNode.insertBefore(k,s);if(this.msieZIndexBug){var t=c.Element("img",{src:"about:blank",id:"MathJax_ZoomTracker",style:{width:0,height:0,position:"relative"}});document.body.appendChild(k);k.style.position="absolute";k.style.zIndex=g.styles["#MathJax_ZoomOverlay"]["z-index"];k=t}var w=(this["Zoom"+o])(r,u,s);if(this.msiePositionBug){if(this.msieIE8Bug){u.style.position="absolute";x.style.height=u.offsetHeight;u.style.position="";if(x.offsetHeight<=p&&x.offsetWidth<=j){x.style.overflow="visible"}}if(this.msieWidthBug){x.style.width=Math.min(j,w.w)}else{if(w.w>j){x.style.width=j}}if(x.offsetHeight>p){x.style.Height=p+"px"}if(s.nextSibling){s.parentNode.insertBefore(k,s.nextSibling)}else{v.appendChild(k)}}else{if(this.operaPositionBug){x.style.width=Math.min(j,u.offsetWidth)+"px"}}this.Position(x,w,(o==="MathML"&&v.nodeName.toLowerCase()==="div"));x.style.visibility="";if(this.settings.zoom==="Hover"){n.onmouseover=this.Remove}if(window.addEventListener){addEventListener("resize",this.Resize,false)}else{if(window.attachEvent){attachEvent("onresize",this.Resize)}else{this.onresize=window.onresize;window.onresize=this.Resize}}return d(l)},ZoomHTMLCSS:function(o,q,p){q.className="MathJax";b.idPostfix="-zoom";b.getScales(q,q);o.toHTML(q,q);var r=o.HTMLspanElement().bbox;b.idPostfix="";if(r.width&&r.width!=="100%"){var j=Math.floor(0.85*document.body.clientWidth);q.style.width=j+"px";q.style.display="inline-block";var k=(o.id||"MathJax-Span-"+o.spanID)+"-zoom";var l=document.getElementById(k).firstChild;while(l&&l.style.width!==r.width){l=l.nextSibling}if(l){l.style.width="100%"}}q.appendChild(this.topImg);var n=this.topImg.offsetTop;q.removeChild(this.topImg);var m=(this.msieWidthBug?b.getW(p)*b.em:p.offsetWidth);return{w:r.w*b.em,Y:-n,W:m}},ZoomMathML:function(k,l,m){k.toNativeMML(l,l);var n;l.appendChild(this.topImg);n=this.topImg.offsetTop;l.removeChild(this.topImg);var j=(this.ffMMLwidthBug?m.parentNode:m).offsetWidth;return{w:l.offsetWidth,Y:-n,W:j}},Position:function(p,n,r){var k=this.Resize(),m=k.x,l=k.y,j=n.W;if(this.msiePositionBug){j=-j}if(r&&this.ffMMLcenterBug){j=0}var q=-Math.floor((p.offsetWidth-j)/2),o=n.Y;p.style.left=Math.max(q,20-m)+"px";p.style.top=Math.max(o,20-l)+"px"},Resize:function(l){if(f.onresize){f.onresize(l)}var j=0,o=0,n=document.getElementById("MathJax_ZoomFrame"),k=document.getElementById("MathJax_ZoomOverlay");var m=(f.msieZIndexBug?document.getElementById("MathJax_ZoomTracker"):n);if(f.operaPositionBug){n.style.border="1px solid"}if(m.offsetParent){do{j+=m.offsetLeft;o+=m.offsetTop}while(m=m.offsetParent)}if(f.operaPositionBug){n.style.border=""}if(f.msieZIndexBug){n.style.left=j+"px";n.style.top=o+"px"}k.style.left=(-j)+"px";k.style.top=(-o)+"px";if(f.msiePositionBug){setTimeout(f.SetWH,0)}else{f.SetWH()}return{x:j,y:o}},SetWH:function(){var j=document.getElementById("MathJax_ZoomOverlay");j.style.width=j.style.height="1px";j.style.width=document.body.scrollWidth+"px";j.style.height=document.body.scrollHeight+"px"},Remove:function(k){var l=document.getElementById("MathJax_ZoomFrame");if(l){l.parentNode.removeChild(l);l=document.getElementById("MathJax_ZoomTracker");if(l){l.parentNode.removeChild(l)}if(f.operaRefreshBug){var j=c.addElement(document.body,"div",{style:{position:"fixed",left:0,top:0,width:"100%",height:"100%",backgroundColor:"white",opacity:0},id:"MathJax_OperaDiv"});document.body.removeChild(j)}if(window.removeEventListener){removeEventListener("resize",f.Resize,false)}else{if(window.detachEvent){detachEvent("onresize",f.Resize)}else{window.onresize=f.onresize;delete f.onresize}}}return d(k)}};a.Register.StartupHook("HTML-CSS Jax Ready",function(){b=MathJax.OutputJax["HTML-CSS"];b.Augment({HandleEvent:f.HandleEvent})});a.Register.StartupHook("NativeMML Jax Ready",function(){h=MathJax.OutputJax.NativeMML;h.Augment({HandleEvent:f.HandleEvent,MSIEmouseup:function(l,k,j){if(this.trapUp){delete this.trapUp;return true}if(this.MSIEzoomKeys(l)){return true}return false},MSIEclick:function(l,k,j){if(this.trapClick){delete this.trapClick;return true}if(!this.MSIEzoomKeys(l)){return false}if(!this.settings.zoom.match(/Click/)){return false}return(f.Click(l,k)===false)},MSIEdblclick:function(l,k,j){if(!this.MSIEzoomKeys(l)){return false}return(f.DblClick(l,k)===false)},MSIEmouseover:function(l,k,j){if(this.settings.zoom!=="Hover"){return false}f.Timer(l,k);return true},MSIEmouseout:function(l,k,j){if(this.settings.zoom!=="Hover"){return false}f.ClearTimer();return true},MSIEmousemove:function(l,k,j){if(this.settings.zoom!=="Hover"){return false}f.Timer(l,k);return true},MSIEzoomKeys:function(j){if(this.settings.CTRL&&!j.ctrlKey){return false}if(this.settings.CMD&&!j.metaKey){return false}if(this.settings.ALT&&!j.altKey){return false}if(this.settings.Shift&&!j.shiftKey){return false}return true}})});a.Browser.Select({MSIE:function(j){var k=(document.compatMode==="BackCompat");var l=j.versionAtLeast("8.0")&&document.documentMode>7;f.msiePositionBug=true;f.msieWidthBug=!k;f.msieIE8Bug=l;f.msieZIndexBug=!l;f.msieInlineBlockAlignBug=(!l||k);if(document.documentMode>=9){delete g.styles["#MathJax_Zoom"].filter}},Opera:function(j){f.operaPositionBug=true;f.operaRefreshBug=true},Firefox:function(j){f.ffMMLwidthBug=true;f.ffMMLcenterBug=true}});f.topImg=(f.msieInlineBlockAlignBug?c.Element("img",{style:{width:0,height:0},src:"about:blank"}):c.Element("span",{style:{width:0,height:0,display:"inline-block"}}));if(f.operaPositionBug){f.topImg.style.border="1px solid"}MathJax.Callback.Queue(["Styles",e,g.styles],["Post",a.Startup.signal,"MathZoom Ready"],["loadComplete",e,"[MathJax]/extensions/MathZoom.js"])})(MathJax.Hub,MathJax.HTML,MathJax.Ajax,MathJax.OutputJax["HTML-CSS"],MathJax.OutputJax.NativeMML);