Skip to content

Commit 23c8dcc

Browse files
committed
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.
1 parent 0ed5d46 commit 23c8dcc

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

unpacked/extensions/MathMenu.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525

2626
(function (HUB,HTML,AJAX,CALLBACK,OUTPUT) {
27-
var VERSION = "2.0.5";
27+
var VERSION = "2.0.6";
2828

2929
var SIGNAL = MathJax.Callback.Signal("menu") // signal for menu events
3030

@@ -50,7 +50,9 @@
5050
windowSettings: { // for source window
5151
status: "no", toolbar: "no", locationbar: "no", menubar: "no",
5252
directories: "no", personalbar: "no", resizable: "yes", scrollbars: "yes",
53-
width: 100, height: 50
53+
width: 400, height: 300,
54+
left: Math.round((screen.width - 400)/2),
55+
top: Math.round((screen.height - 300)/3)
5456
},
5557

5658
styles: {
@@ -700,7 +702,7 @@
700702
return MENU.ShowSource.w;
701703
};
702704
MENU.ShowSource.Text = function (text,event) {
703-
var w = MENU.ShowSource.Window(event);
705+
var w = MENU.ShowSource.Window(event); delete MENU.ShowSource.w;
704706
text = text.replace(/^\s*/,"").replace(/\s*$/,"");
705707
text = text.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
706708
if (MENU.isMobile) {
@@ -717,17 +719,18 @@
717719
w.document.write("</body></html>");
718720
w.document.close();
719721
var table = w.document.body.firstChild;
720-
var H = (w.outerHeight-w.innerHeight)||30, W = (w.outerWidth-w.innerWidth)||30;
721-
W = Math.min(Math.floor(.5*screen.width),table.offsetWidth+W+25);
722-
H = Math.min(Math.floor(.5*screen.height),table.offsetHeight+H+25);
723-
w.resizeTo(W,H);
724-
if (event && event.screenX != null) {
725-
var x = Math.max(0,Math.min(event.screenX-Math.floor(W/2), screen.width-W-20)),
726-
y = Math.max(0,Math.min(event.screenY-Math.floor(H/2), screen.height-H-20));
727-
w.moveTo(x,y);
728-
}
722+
setTimeout(function () {
723+
var H = (w.outerHeight-w.innerHeight)||30, W = (w.outerWidth-w.innerWidth)||30, x, y;
724+
W = Math.max(100,Math.min(Math.floor(.5*screen.width),table.offsetWidth+W+25));
725+
H = Math.max(40,Math.min(Math.floor(.5*screen.height),table.offsetHeight+H+25));
726+
w.resizeTo(W,H);
727+
if (event && event.screenX != null) {
728+
x = Math.max(0,Math.min(event.screenX-Math.floor(W/2), screen.width-W-20));
729+
y = Math.max(0,Math.min(event.screenY-Math.floor(H/2), screen.height-H-20));
730+
w.moveTo(x,y);
731+
}
732+
},50);
729733
}
730-
delete MENU.ShowSource.w;
731734
};
732735

733736
/*

0 commit comments

Comments
 (0)