|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 var doOKFunction = 0; |
|
6 var doCancelFunction = 0; |
|
7 var doButton2Function = 0; |
|
8 var doButton3Function = 0; |
|
9 |
|
10 // call this from dialog onload() to allow ok and cancel to call your code |
|
11 // functions should return true if they want the dialog to close |
|
12 function doSetOKCancel(okFunc, cancelFunc, button2Func, button3Func ) |
|
13 { |
|
14 //dump("top.window.navigator.platform: " + top.window.navigator.platform + "\n"); |
|
15 |
|
16 doOKFunction = okFunc; |
|
17 doCancelFunction = cancelFunc; |
|
18 doButton2Function = button2Func; |
|
19 doButton3Function = button3Func; |
|
20 } |
|
21 |
|
22 function doOKButton() |
|
23 { |
|
24 var close = true; |
|
25 |
|
26 if ( doOKFunction ) |
|
27 close = doOKFunction(); |
|
28 |
|
29 if (close && top) |
|
30 top.window.close(); |
|
31 } |
|
32 |
|
33 function doCancelButton() |
|
34 { |
|
35 var close = true; |
|
36 |
|
37 if ( doCancelFunction ) |
|
38 close = doCancelFunction(); |
|
39 |
|
40 if (close && top) |
|
41 top.window.close(); |
|
42 } |
|
43 |
|
44 function doButton2() |
|
45 { |
|
46 var close = true; |
|
47 |
|
48 if ( doButton2Function ) |
|
49 close = doButton2Function(); |
|
50 |
|
51 if (close && top) |
|
52 top.window.close(); |
|
53 } |
|
54 |
|
55 function doButton3() |
|
56 { |
|
57 var close = true; |
|
58 |
|
59 if ( doButton3Function ) |
|
60 close = doButton3Function(); |
|
61 |
|
62 if (close && top) |
|
63 top.window.close(); |
|
64 } |
|
65 |
|
66 function moveToAlertPosition() |
|
67 { |
|
68 // hack. we need this so the window has something like its final size |
|
69 if (window.outerWidth == 1) { |
|
70 dump("Trying to position a sizeless window; caller should have called sizeToContent() or sizeTo(). See bug 75649.\n"); |
|
71 sizeToContent(); |
|
72 } |
|
73 |
|
74 var xOffset = (opener.outerWidth - window.outerWidth) / 2; |
|
75 var yOffset = opener.outerHeight / 5; |
|
76 |
|
77 var newX = opener.screenX + xOffset; |
|
78 var newY = opener.screenY + yOffset; |
|
79 |
|
80 // ensure the window is fully onscreen (if smaller than the screen) |
|
81 if (newX < screen.availLeft) |
|
82 newX = screen.availLeft + 20; |
|
83 if ((newX + window.outerWidth) > (screen.availLeft + screen.availWidth)) |
|
84 newX = (screen.availLeft + screen.availWidth) - window.outerWidth - 20; |
|
85 |
|
86 if (newY < screen.availTop) |
|
87 newY = screen.availTop + 20; |
|
88 if ((newY + window.outerHeight) > (screen.availTop + screen.availHeight)) |
|
89 newY = (screen.availTop + screen.availHeight) - window.outerHeight - 60; |
|
90 |
|
91 window.moveTo( newX, newY ); |
|
92 } |
|
93 |
|
94 function centerWindowOnScreen() |
|
95 { |
|
96 var xOffset = screen.availWidth/2 - window.outerWidth/2; |
|
97 var yOffset = screen.availHeight/2 - window.outerHeight/2; //(opener.outerHeight *2)/10; |
|
98 |
|
99 xOffset = ( xOffset > 0 ) ? xOffset : 0; |
|
100 yOffset = ( yOffset > 0 ) ? yOffset : 0; |
|
101 window.moveTo( xOffset, yOffset); |
|
102 } |