From 975fe6e67928c9d5c2c28c107a7434000cb19d24 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 24 Aug 2011 20:53:52 -0400 Subject: [PATCH] Move output-jax-specific zoom code to jax, and fix some other minor issues (stil need to check with IE and then repack and recombine) --- unpacked/extensions/MathEvents.js | 9 +- unpacked/extensions/MathZoom.js | 115 ++++-------------------- unpacked/jax/output/HTML-CSS/config.js | 2 +- unpacked/jax/output/HTML-CSS/jax.js | 35 ++++++++ unpacked/jax/output/NativeMML/config.js | 2 +- unpacked/jax/output/NativeMML/jax.js | 27 ++++-- 6 files changed, 84 insertions(+), 106 deletions(-) diff --git a/unpacked/extensions/MathEvents.js b/unpacked/extensions/MathEvents.js index cdca57348..f1693d039 100644 --- a/unpacked/extensions/MathEvents.js +++ b/unpacked/extensions/MathEvents.js @@ -134,9 +134,7 @@ // Remove selections, remove hover fades // if (ME.msieEventBug) {event = window.event} - if (ME.safariContextMenuBug) {setTimeout("window.getSelection().empty()",0)} - if (document.selection) {setTimeout("document.selection.empty()",0)} - HOVER.ClearHoverTimer(); + EVENT.ClearSelection(); HOVER.ClearHoverTimer(); if (jax.hover) { if (jax.hover.remove) {clearTimeout(jax.hover.remove); delete jax.hover.remove} jax.hover.nofade = true; @@ -183,6 +181,11 @@ } return JAX.ContextMenu(event,math,true); } + }, + + ClearSelection: function () { + if (ME.safariContextMenuBug) {setTimeout("window.getSelection().empty()",0)} + if (document.selection) {setTimeout("document.selection.empty()",0)} } }; diff --git a/unpacked/extensions/MathZoom.js b/unpacked/extensions/MathZoom.js index 79cad3734..71c469cbb 100644 --- a/unpacked/extensions/MathZoom.js +++ b/unpacked/extensions/MathZoom.js @@ -26,8 +26,6 @@ var VERSION = "1.1.3"; var CONFIG = HUB.CombineConfig("MathZoom",{ - delay: 400, // mouse must be still this long (milliseconds) - styles: { // // The styles for the MathZoom display box @@ -57,8 +55,9 @@ } }); - var FALSE, HOVER; + var FALSE, HOVER, EVENT; MathJax.Hub.Register.StartupHook("MathEvents Ready",function () { + EVENT = MathJax.Extension.MathEvents.Event; FALSE = MathJax.Extension.MathEvents.Event.False; HOVER = MathJax.Extension.MathEvents.Hover; }); @@ -85,21 +84,21 @@ // Zoom on click // Click: function (event,math) { - if (this.settings.zoom === "Click") {return this.Zoom(math,event)} + if (this.settings.zoom === "Click") {return this.Zoom(event,math)} }, // // Zoom on double click // DblClick: function (event,math) { - if (this.settings.zoom === "Double-Click") {return this.Zoom(math,event)} + if (this.settings.zoom === "Double-Click") {return this.Zoom(event,math)} }, // // Zoom on hover (called by UI.Hover) // Hover: function (event,math) { - if (this.settings.zoom === "Hover") {this.Zoom(math,event); return true} + if (this.settings.zoom === "Hover") {this.Zoom(event,math); return true} return false; }, @@ -107,20 +106,20 @@ // // Handle the actual zooming // - Zoom: function (math,event) { + Zoom: function (event,math) { this.Remove(); HOVER.ClearHoverTimer(); - + EVENT.ClearSelection(); + // // Find the jax and its type // - var parent = math.parentNode; - if (parent.className === "MathJax_MathContainer") {parent = parent.parentNode} - if (parent.parentNode.className === "MathJax_MathContainer") {parent = parent.parentNode.parentNode} - var script = (String(parent.className).match(/^MathJax_(MathML|Display)$/) ? parent : math).nextSibling; - var jax = HUB.getJaxFor(script), root = jax.root; - var JAX = (HTMLCSS && jax.outputJax.isa(HTMLCSS.constructor) ? "HTMLCSS" : - (nMML && jax.outputJax.isa(nMML.constructor) ? "MathML" : null)); - if (!JAX) return; // FIXME: report an error? + /* + * var parent = math.parentNode; + * if (parent.className === "MathJax_MathContainer") {parent = parent.parentNode} + * if (parent.parentNode.className === "MathJax_MathContainer") {parent = parent.parentNode.parentNode} + */ + var JAX = MathJax.OutputJax[math.jaxID]; + var jax = JAX.getJaxFromMath(math), root = jax.root; if (jax.hover) {HOVER.UnHover(jax)} // @@ -140,7 +139,7 @@ visibility:"hidden", fontSize:this.settings.zscale, "max-width":Mw+"px", "max-height":Mh+"px" } - },[["span"]]] + },[["span",{style:{display:"inline-block", "white-space":"nowrap"}}]]] ] ); var zoom = div.lastChild, span = zoom.firstChild, overlay = div.firstChild; @@ -161,7 +160,7 @@ div = tracker; } - var bbox = (this["Zoom"+JAX])(root,span,math,Mw,Mh); + var bbox = JAX.Zoom(root,span,math,Mw,Mh); // // Fix up size and position for browsers with bugs (IE) @@ -176,7 +175,7 @@ } if (this.operaPositionBug) {zoom.style.width = Math.min(Mw,bbox.zW)+"px"} // Opera gets width as 0? if (zoom.offsetWidth <= Mw && zoom.offsetHeight <= Mh) {zoom.style.overflow = "visible"} - this.Position(zoom,bbox,(JAX === "MathML" && parent.nodeName.toLowerCase() === "div")); + this.Position(zoom,bbox,(JAX.id === "MathML" && parent.nodeName.toLowerCase() === "div")); zoom.style.visibility = ""; // @@ -193,79 +192,11 @@ return FALSE(event); }, - // - // Handle the jax-specific output - // - ZoomHTMLCSS: function (root,span,math,Mw,Mh) { - // - // Re-render at larger size - // - span.className = "MathJax"; - HTMLCSS.idPostfix = "-zoom"; - HTMLCSS.getScales(span,span); - root.toHTML(span,span); - var bbox = root.HTMLspanElement().bbox; - HTMLCSS.idPostfix = ""; - if (bbox.width) { - // Handle full-width displayed equations - // FIXME: this is a hack for now - span.style.width = Math.floor(Mw-1.5*HTMLCSS.em)+"px"; span.style.display="inline-block"; - var id = (root.id||"MathJax-Span-"+root.spanID)+"-zoom"; - var child = document.getElementById(id).firstChild; - while (child && child.style.width !== bbox.width) {child = child.nextSibling} - if (child) {child.style.width = "100%"} - } - // - // Get height and width of zoomed math and original math - // - span.style.position = math.style.position = "absolute"; - var zW = span.offsetWidth, zH = span.offsetHeight, - mH = math.offsetHeight, mW = math.offsetWidth; - span.style.position = math.style.position = ""; - if (mW === 0) {mW = math.offseWidth || math.parentNode.offsetWidth}; // IE7 gets mW == 0? - // - return {Y:-this.getTop(root,span,math,this.msieTopBug,this.msieBorderBug,false), - mW:mW, mH:mH, zW:zW, zH:zH}; - }, - ZoomMathML: function (root,span,math) { - root.toNativeMML(span,span); - var top = this.getTop(root,span,math,this.msieTopMMLBug,false,this.ffMMLdisplayBug); - var mW = math.offsetWidth || math.scrollWidth, - mH = math.offsetHeight || math.scrollHeight; - if (this.msieIE8HeightBug) {span.style.position = "absolute"} - var zW = span.offsetWidth, zH = span.offsetHeight; - if (this.msieIE8HeightBug) {span.style.position = ""} - if (this.ffMMLdisplayBug) { - // Force width in FF, since it gets the math element width wrong - span.style.display="inline-block"; - span.style.width = zW+"px"; - } - return {Y:-top, mW:mW, mH:mH, zW:zW, zH:zH} - }, - // // Get top offset from baseline // - getTop: function (root,span,math,topBug,borderBug,mmlBug) { + getTop: function (root,span,math,topBug,borderBug) { span.appendChild(this.topImg); - if (mmlBug && math.getAttribute("display") === "block") { - // FF breaks between the display math and the image, so - // convert display to inline with displaystyle true - math.setAttribute("display","inline"); math.MJinline = true; - var mstyle = root.NativeMMLelement("mstyle"); - while (math.firstChild) {mstyle.appendChild(math.firstChild)} - math.appendChild(mstyle); mstyle.setAttribute("displaystyle","true"); - } - if (math.MJinline) { - // FF breaks between the display math and the image, so - // convert display to inline with displaystyle true - span.insertBefore(this.topImg,span.firstChild); - var zmath = span.childNodes[1], zstyle = root.NativeMMLelement("mstyle"); - zmath.setAttribute("display","inline"); - while (zmath.firstChild) {zstyle.appendChild(zmath.firstChild)} - zmath.appendChild(zstyle); zstyle.setAttribute("displaystyle","true"); - zstyle.setAttribute("displaystyle","true"); - } var top = this.topImg.offsetTop; if (topBug) { // For IE, frame is not at the baseline, so remove extra height @@ -354,11 +285,7 @@ ZOOM.msieSizeBug = browser.versionAtLeast("7.0") && (!document.documentMode || document.documentMode === 7 || document.documentMode === 8); ZOOM.msieIE8Bug = isIE8 && (document.documentMode === 8); - ZOOM.msieIE8HeightBug = (document.documentMode === 8); ZOOM.msieZIndexBug = !isIE8; - ZOOM.msieTopBug = (!browser.versionAtLeast("8.0") || document.documentMode === 7); - ZOOM.msieTopMMLBug = ZOOM.msieTopBug || (!isIE8 || document.documentMode >= 9); - ZOOM.msieBorderBug = quirks && browser.versionAtLeast("8.0"); ZOOM.msieInlineBlockAlignBug = (!isIE8 || quirks); if (document.documentMode >= 9) {delete CONFIG.styles["#MathJax_Zoom"].filter} }, @@ -366,10 +293,6 @@ Opera: function (browser) { ZOOM.operaPositionBug = true; ZOOM.operaRefreshBug = true; - }, - - Firefox: function (browser) { - ZOOM.ffMMLdisplayBug = true; } }); diff --git a/unpacked/jax/output/HTML-CSS/config.js b/unpacked/jax/output/HTML-CSS/config.js index 02ff640fe..8a39f1282 100644 --- a/unpacked/jax/output/HTML-CSS/config.js +++ b/unpacked/jax/output/HTML-CSS/config.js @@ -24,7 +24,7 @@ MathJax.OutputJax["HTML-CSS"] = MathJax.OutputJax({ id: "HTML-CSS", - version: "1.1.12", + version: "1.1.13", directory: MathJax.OutputJax.directory + "/HTML-CSS", extensionDir: MathJax.OutputJax.extensionDir + "/HTML-CSS", autoloadDir: MathJax.OutputJax.directory + "/HTML-CSS/autoload", diff --git a/unpacked/jax/output/HTML-CSS/jax.js b/unpacked/jax/output/HTML-CSS/jax.js index f219e08e3..ae74e8c24 100644 --- a/unpacked/jax/output/HTML-CSS/jax.js +++ b/unpacked/jax/output/HTML-CSS/jax.js @@ -438,6 +438,39 @@ if (bbox.width) {BBOX.width = bbox.width} return BBOX; }, + + Zoom: function (root,span,math,Mw,Mh) { + // + // Re-render at larger size + // + span.className = "MathJax"; + this.idPostfix = "-zoom"; + this.getScales(span,span); + root.toHTML(span,span); + var bbox = root.HTMLspanElement().bbox; + this.idPostfix = ""; + if (bbox.width) { + // Handle full-width displayed equations + // FIXME: this is a hack for now + span.style.width = Math.floor(Mw-1.5*HTMLCSS.em)+"px"; span.style.display="inline-block"; + var id = (root.id||"MathJax-Span-"+root.spanID)+"-zoom"; + var child = document.getElementById(id).firstChild; + while (child && child.style.width !== bbox.width) {child = child.nextSibling} + if (child) {child.style.width = "100%"} + } + // + // Get height and width of zoomed math and original math + // + span.style.position = math.style.position = "absolute"; + var zW = span.offsetWidth, zH = span.offsetHeight, + mH = math.offsetHeight, mW = math.offsetWidth; + if (mW === 0) {mW = math.parentNode.offsetWidth}; // IE7 gets mW == 0? + span.style.position = math.style.position = ""; + // + var ZOOM = MathJax.Extension.MathZoom; + return {Y:-ZOOM.getTop(root,span,math,ZOOM.msieTopBug,ZOOM.msieBorderBug), + mW:mW, mH:mH, zW:zW, zH:zH}; + }, initImg: function (span) {}, initHTML: function (math,span) {}, @@ -2172,6 +2205,8 @@ msieClipRectBug: !isIE8, msieNegativeSpaceBug: quirks, msieCloneNodeBug: (isIE8 && browser.version === "8.0"), + msieTopBug: (!browser.versionAtLeast("8.0") || document.documentMode === 7), + msieBorderBug: (quirks && browser.versionAtLeast("8.0")), negativeSkipBug: true, msieIE6: !isIE7, msieItalicWidthBug: true, diff --git a/unpacked/jax/output/NativeMML/config.js b/unpacked/jax/output/NativeMML/config.js index a6bd51f6e..2ea642493 100644 --- a/unpacked/jax/output/NativeMML/config.js +++ b/unpacked/jax/output/NativeMML/config.js @@ -24,7 +24,7 @@ MathJax.OutputJax.NativeMML = MathJax.OutputJax({ id: "NativeMML", - version: "1.1.8", + version: "1.1.9", directory: MathJax.OutputJax.directory + "/NativeMML", extensionDir: MathJax.OutputJax.extensionDir + "/NativeMML", diff --git a/unpacked/jax/output/NativeMML/jax.js b/unpacked/jax/output/NativeMML/jax.js index 1be043a5f..f8909a067 100644 --- a/unpacked/jax/output/NativeMML/jax.js +++ b/unpacked/jax/output/NativeMML/jax.js @@ -25,7 +25,9 @@ (function (nMML,HUB,AJAX,HTML) { var MML, isMSIE = HUB.Browser.isMSIE; - var EVENT, TOUCH, HOVER; // filled in later + var EVENT, TOUCH, HOVER, ZOOM; // filled in later + + HUB.Register.StartupHook("MathZoom Ready",function () {ZOOM = MathJax.Extension.MathZoom}); nMML.Augment({ // @@ -188,7 +190,7 @@ var event = window.event; var type = nMML.MSIEevents[event.type]; if (nMML[type] && nMML[type](event,this) === false) {return false} - if (MathJax.Extension.MathZoom && MathJax.Extension.MathZoom.HandleEvent(event,type,this) === false) {return false} + if (ZOOM && ZOOM.HandleEvent(event,type,this) === false) {return false} if (event.srcElement.className === "MathJax_MathPlayer_Overlay" && this.msieMath.fireEvent) {this.msieMath.fireEvent("on"+event.type,event)} return EVENT.False(event); @@ -211,6 +213,16 @@ return {w:w, h:h, d:d, x:x} }, + Zoom: function (root,span,math) { + root.toNativeMML(span,span); + var top = ZOOM.getTop(root,span.parentNode,math,this.msieTopBug,false); + if (this.msieIE8HeightBug) {span.style.position = "absolute"} + var mW = math.offsetWidth || math.scrollWidth, + mH = math.offsetHeight || math.scrollHeight; + var zW = span.offsetWidth, zH = span.offsetHeight; + if (this.msieIE8HeightBug) {span.style.position = ""} + return {Y:-top, mW:mW, mH:mH, zW:zW, zH:zH} + }, NAMEDSPACE: { negativeveryverythinmathspace: "-.0556em", @@ -481,9 +493,14 @@ HUB.Browser.Select({ MSIE: function (browser) { var quirks = (document.compatMode === "BackCompat"); - var isIE8 = browser.versionAtLeast("8.0") && document.documentMode > 7; - nMML.msieInlineBlockAlignBug = (!isIE8 || quirks); - nMML.msieTopBug = (!browser.versionAtLeast("8.0") || document.documentMode === 7); + var mode = (document.documentMode || 0); + var isIE8 = browser.versionAtLeast("8.0"); + nMML.Augment({ + msieInlineBlockAlignBug: (!isIE8 || mode < 8 || quirks), + msieTopBug: (!isIE8 || mode === 7), + msieIE8HeightBug: (mode === 8), + msieTopBug: (!isIE8 || mode !== 8) + }); }, Opera: function (browser) { nMML.operaPositionBug = true;