1234567891011121314151617181920212223242526 |
- /* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
- /* vim: set ts=2 et sw=2 tw=80: */
- /*************************************************************
- *
- * MathJax/extensions/MathEvents.js
- *
- * Implements the event handlers needed by the output jax to perform
- * menu, hover, and other events.
- *
- * ---------------------------------------------------------------------
- *
- * Copyright (c) 2011-2013 The MathJax Consortium
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */(function(l,u,m,p,w,r,x){var t=MathJax.Extension,g=t.MathEvents={version:"2.2"},n=l.config.menuSettings,d={hover:500,frame:{x:3.5,y:5,bwidth:1,bcolor:"#A6D",hwidth:"15px",hcolor:"#83A"},button:{x:-4,y:-3,wx:-2,src:m.fileURL(r.imageDir+"/MenuArrow-15.png")},fadeinInc:.2,fadeoutInc:.05,fadeDelay:50,fadeoutStart:400,fadeoutDelay:15E3,styles:{".MathJax_Hover_Frame":{"border-radius":".25em","-webkit-border-radius":".25em","-moz-border-radius":".25em","-khtml-border-radius":".25em","box-shadow":"0px 0px 15px #83A","-webkit-box-shadow":"0px 0px 15px #83A","-moz-box-shadow":"0px 0px 15px #83A","-khtml-box-shadow":"0px 0px 15px #83A",border:"1px solid #A6D ! important",display:"inline-block",position:"absolute"},".MathJax_Hover_Arrow":{position:"absolute",width:"15px",height:"11px",cursor:"pointer"}}},e=g.Event={LEFTBUTTON:0,RIGHTBUTTON:2,MENUKEY:"altKey",Mousedown:function(a){return e.Handler(a,"Mousedown",this)},Mouseup:function(a){return e.Handler(a,"Mouseup",this)},Mousemove:function(a){return e.Handler(a,"Mousemove",this)},Mouseover:function(a){return e.Handler(a,"Mouseover",this)},Mouseout:function(a){return e.Handler(a,"Mouseout",this)},Click:function(a){return e.Handler(a,"Click",this)},DblClick:function(a){return e.Handler(a,"DblClick",this)},Menu:function(a){return e.Handler(a,"ContextMenu",this)},Handler:function(a,c,b){if(m.loadingMathMenu)return e.False(a);var q=r[b.jaxID];a||(a=window.event);a.isContextMenu="ContextMenu"===c;if(q[c])return q[c](a,b);if(t.MathZoom)return t.MathZoom.HandleEvent(a,c,b)},False:function(a){a||(a=window.event);a&&(a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0,a.returnValue=!1);return!1},ContextMenu:function(a,c,b){var q=r[c.jaxID],f=q.getJaxFromMath(c);if((null!=q.config.showMathMenu?q:l).config.showMathMenu&&("MathJax"===n.context||b)){g.msieEventBug&&(a=window.event||a);e.ClearSelection();k.ClearHoverTimer();f.hover&&(f.hover.remove&&(clearTimeout(f.hover.remove),delete f.hover.remove),f.hover.nofade=!0);var d=MathJax.Menu;if(d){if(d.loadingDomain)return e.False(a);q=w.loadDomain("MathMenu");if(!q)return d.jax=f,c=d.menu.Find("Show Math As").menu,c.items[0].name=f.sourceMenuTitle,c.items[0].format=f.sourceMenuFormat||"MathML",c.items[1].name=x[f.inputJax].sourceMenuTitle,d.menu.Find("Math Settings","MathPlayer").hidden=!("NativeMML"===f.outputJax&&l.Browser.hasMathPlayer),d.menu.Post(a);d.loadingDomain=!0;f=function(){delete d.loadingDomain}}else{if(m.loadingMathMenu)return e.False(a);m.loadingMathMenu=!0;q=m.Require("[MathJax]/extensions/MathMenu.js");f=function(){delete m.loadingMathMenu;MathJax.Menu||(MathJax.Menu={})}}p.Queue(q,f,["ContextMenu",e,{pageX:a.pageX,pageY:a.pageY,clientX:a.clientX,clientY:a.clientY},c,b]);return e.False(a)}},AltContextMenu:function(a,c){var b=r[c.jaxID],d=(null!=b.config.showMathMenu?b:l).config.showMathMenu;if(d){d=(null!=b.config.showMathMenuMSIE?b:l).config.showMathMenuMSIE;if("MathJax"===n.context&&!n.mpContext&&d){if(!g.noContextMenuBug||a.button!==e.RIGHTBUTTON)return}else if(!a[e.MENUKEY]||a.button!==e.LEFTBUTTON)return;return b.ContextMenu(a,c,!0)}},ClearSelection:function(){g.safariContextMenuBug&&setTimeout("window.getSelection().empty()",0);document.selection&&setTimeout("document.selection.empty()",0)},getBBox:function(a){a.appendChild(g.topImg);var c=g.topImg.offsetTop,b=a.offsetHeight-c,d=a.offsetWidth;a.removeChild(g.topImg);return{w:d,h:c,d:b}}},k=g.Hover={Mouseover:function(a,c){if(n.discoverable||"Hover"===n.zoom){var b=a.fromElement||a.relatedTarget,d=a.toElement||a.target;if(b&&d&&(b.isMathJax!=d.isMathJax||l.getJaxFor(b)!==l.getJaxFor(d)))return b=this.getJaxFromMath(c),b.hover?k.ReHover(b):k.HoverTimer(b,c),e.False(a)}},Mouseout:function(a,c){if(n.discoverable||"Hover"===n.zoom){var b=a.fromElement||a.relatedTarget,d=a.toElement||a.target;if(b&&d&&(b.isMathJax!=d.isMathJax||l.getJaxFor(b)!==l.getJaxFor(d)))return b=this.getJaxFromMath(c),b.hover?k.UnHover(b):k.ClearHoverTimer(),e.False(a)}},Mousemove:function(a,c){if(n.discoverable||"Hover"===n.zoom){var b=this.getJaxFromMath(c);if(!b.hover&&(k.lastX!=a.clientX||k.lastY!=a.clientY))return k.lastX=a.clientX,k.lastY=a.clientY,k.HoverTimer(b,c),e.False(a)}},HoverTimer:function(a,c){this.ClearHoverTimer();this.hoverTimer=setTimeout(p(["Hover",this,a,c]),d.hover)},ClearHoverTimer:function(){this.hoverTimer&&(clearTimeout(this.hoverTimer),delete this.hoverTimer)},Hover:function(a,c){if(!t.MathZoom||!t.MathZoom.Hover({},c)){var b=r[a.outputJax],e=b.getHoverSpan(a,c),f=b.getHoverBBox(a,e,c),h=(null!=b.config.showMathMenu?b:l).config.showMathMenu,k=d.frame.x,n=d.frame.y,m=d.frame.bwidth;g.msieBorderWidthBug&&(m=0);a.hover={opacity:0,id:a.inputID+"-Hover"};var p=u.Element("span",{id:a.hover.id,isMathJax:!0,style:{display:"inline-block",width:0,height:0,position:"relative"}},[["span",{className:"MathJax_Hover_Frame",isMathJax:!0,style:{display:"inline-block",position:"absolute",top:this.Px(-f.h-n-m-(f.y||0)),left:this.Px(-k-m+(f.x||0)),width:this.Px(f.w+2*k),height:this.Px(f.h+f.d+2*n),opacity:0,filter:"alpha(opacity\x3d0)"}}]]),b=u.Element("span",{isMathJax:!0,id:a.hover.id+"Menu",style:{display:"inline-block","z-index":1,width:0,height:0,position:"relative"}},[["img",{className:"MathJax_Hover_Arrow",isMathJax:!0,math:c,src:d.button.src,onclick:this.HoverMenu,jax:b.id,style:{left:this.Px(f.w+k+m+(f.x||0)+d.button.x),top:this.Px(-f.h-n-m-(f.y||0)-d.button.y),opacity:0,filter:"alpha(opacity\x3d0)"}}]]);f.width&&(p.style.width=b.style.width=f.width,p.style.marginRight=b.style.marginRight="-"+f.width,p.firstChild.style.width=f.width,b.firstChild.style.left="",b.firstChild.style.right=this.Px(d.button.wx));e.parentNode.insertBefore(p,e);h&&e.parentNode.insertBefore(b,e);e.style&&(e.style.position="relative");this.ReHover(a)}},ReHover:function(a){a.hover.remove&&clearTimeout(a.hover.remove);a.hover.remove=setTimeout(p(["UnHover",this,a]),d.fadeoutDelay);this.HoverFadeTimer(a,d.fadeinInc)},UnHover:function(a){a.hover.nofade||this.HoverFadeTimer(a,-d.fadeoutInc,d.fadeoutStart)},HoverFade:function(a){delete a.hover.timer;a.hover.opacity=Math.max(0,Math.min(1,a.hover.opacity+a.hover.inc));a.hover.opacity=Math.floor(1E3*a.hover.opacity)/1E3;var c=document.getElementById(a.hover.id),b=document.getElementById(a.hover.id+"Menu");c.firstChild.style.opacity=a.hover.opacity;c.firstChild.style.filter="alpha(opacity\x3d"+Math.floor(100*a.hover.opacity)+")";b&&(b.firstChild.style.opacity=a.hover.opacity,b.firstChild.style.filter=c.style.filter);1!==a.hover.opacity&&(0<a.hover.opacity?this.HoverFadeTimer(a,a.hover.inc):(c.parentNode.removeChild(c),b&&b.parentNode.removeChild(b),a.hover.remove&&clearTimeout(a.hover.remove),delete a.hover))},HoverFadeTimer:function(a,c,b){a.hover.inc=c;a.hover.timer||(a.hover.timer=setTimeout(p(["HoverFade",this,a]),b||d.fadeDelay))},HoverMenu:function(a){a||(a=window.event);return r[this.jax].ContextMenu(a,this.math,!0)},ClearHover:function(a){a.hover.remove&&clearTimeout(a.hover.remove);a.hover.timer&&clearTimeout(a.hover.timer);k.ClearHoverTimer();delete a.hover},Px:function(a){return.006>Math.abs(a)?"0px":a.toFixed(2).replace(/\.?0+$/,"")+"px"},getImages:function(){(new Image).src=d.button.src}},h=g.Touch={last:0,delay:500,start:function(a){var c=(new Date).getTime(),b=c-h.last<h.delay&&h.up;h.last=c;h.up=!1;b&&(h.timeout=setTimeout(h.menu,h.delay,a,this),a.preventDefault())},end:function(a){var c=(new Date).getTime();h.up=c-h.last<h.delay;if(h.timeout)return clearTimeout(h.timeout),delete h.timeout,h.last=0,h.up=!1,a.preventDefault(),e.Handler(a.touches[0]||a.touch,"DblClick",this)},menu:function(a,c){delete h.timeout;h.last=0;h.up=!1;return e.Handler(a.touches[0]||a.touch,"ContextMenu",c)}};if(l.Browser.isMobile){var v=d.styles[".MathJax_Hover_Arrow"];v.width="25px";v.height="18px";d.button.x=-6}l.Browser.Select({MSIE:function(a){var c=document.documentMode||0,b=a.versionAtLeast("8.0");g.msieBorderWidthBug="BackCompat"===document.compatMode;g.msieEventBug=a.isIE9;g.msieAlignBug=!b||8>c;9>c&&(e.LEFTBUTTON=1)},Safari:function(a){g.safariContextMenuBug=!0},Opera:function(a){g.operaPositionBug=!0},Konqueror:function(a){g.noContextMenuBug=!0}});g.topImg=g.msieAlignBug?u.Element("img",{style:{width:0,height:0,position:"relative"},src:"about:blank"}):u.Element("span",{style:{width:0,height:0,display:"inline-block"}});g.operaPositionBug&&(g.topImg.style.border="1px solid");g.config=d=l.CombineConfig("MathEvents",d);p.Queue(l.Register.StartupHook("End Config",{}),[function(){var a=d.styles[".MathJax_Hover_Frame"];a.border=d.frame.bwidth+"px solid "+d.frame.bcolor+" ! important";a["box-shadow"]=a["-webkit-box-shadow"]=a["-moz-box-shadow"]=a["-khtml-box-shadow"]="0px 0px "+d.frame.hwidth+" "+d.frame.hcolor}],["getImages",k],["Styles",m,d.styles],["Post",l.Startup.signal,"MathEvents Ready"],["loadComplete",m,"[MathJax]/extensions/MathEvents.js"])})(MathJax.Hub,MathJax.HTML,MathJax.Ajax,MathJax.Callback,MathJax.Localization,MathJax.OutputJax,MathJax.InputJax);
|