From 23c8dcc8d39cdab437ef2070ce0c6c94166e4612 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Sat, 8 Sep 2012 14:27:03 -0400 Subject: [PATCH] Delay sizing and positioning of Show Source window to give WebKit time to get the dimensions worked out. Also make sure we don't use negative width or height (which I think was the problem with Chrome). Resolves issues #245 and #221. --- unpacked/extensions/MathMenu.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/unpacked/extensions/MathMenu.js b/unpacked/extensions/MathMenu.js index 6a34a7e07..515d8fd7b 100644 --- a/unpacked/extensions/MathMenu.js +++ b/unpacked/extensions/MathMenu.js @@ -24,7 +24,7 @@ */ (function (HUB,HTML,AJAX,CALLBACK,OUTPUT) { - var VERSION = "2.0.5"; + var VERSION = "2.0.6"; var SIGNAL = MathJax.Callback.Signal("menu") // signal for menu events @@ -50,7 +50,9 @@ windowSettings: { // for source window status: "no", toolbar: "no", locationbar: "no", menubar: "no", directories: "no", personalbar: "no", resizable: "yes", scrollbars: "yes", - width: 100, height: 50 + width: 400, height: 300, + left: Math.round((screen.width - 400)/2), + top: Math.round((screen.height - 300)/3) }, styles: { @@ -700,7 +702,7 @@ return MENU.ShowSource.w; }; MENU.ShowSource.Text = function (text,event) { - var w = MENU.ShowSource.Window(event); + var w = MENU.ShowSource.Window(event); delete MENU.ShowSource.w; text = text.replace(/^\s*/,"").replace(/\s*$/,""); text = text.replace(/&/g,"&").replace(//g,">"); if (MENU.isMobile) { @@ -717,17 +719,18 @@ w.document.write(""); w.document.close(); var table = w.document.body.firstChild; - var H = (w.outerHeight-w.innerHeight)||30, W = (w.outerWidth-w.innerWidth)||30; - W = Math.min(Math.floor(.5*screen.width),table.offsetWidth+W+25); - H = Math.min(Math.floor(.5*screen.height),table.offsetHeight+H+25); - w.resizeTo(W,H); - if (event && event.screenX != null) { - var x = Math.max(0,Math.min(event.screenX-Math.floor(W/2), screen.width-W-20)), - y = Math.max(0,Math.min(event.screenY-Math.floor(H/2), screen.height-H-20)); - w.moveTo(x,y); - } + setTimeout(function () { + var H = (w.outerHeight-w.innerHeight)||30, W = (w.outerWidth-w.innerWidth)||30, x, y; + W = Math.max(100,Math.min(Math.floor(.5*screen.width),table.offsetWidth+W+25)); + H = Math.max(40,Math.min(Math.floor(.5*screen.height),table.offsetHeight+H+25)); + w.resizeTo(W,H); + if (event && event.screenX != null) { + x = Math.max(0,Math.min(event.screenX-Math.floor(W/2), screen.width-W-20)); + y = Math.max(0,Math.min(event.screenY-Math.floor(H/2), screen.height-H-20)); + w.moveTo(x,y); + } + },50); } - delete MENU.ShowSource.w; }; /*