4 * Though "Dialog" looks like an object, it isn't really an object. Instead
5 * it's just namespace for protecting global symbols.
8 function Dialog(url
, width
, height
, action
, init
) {
9 if (typeof init
== "undefined") {
10 init
= window
; // pass this window object by default
12 Dialog
._geckoOpenModal(url
, width
, height
, action
, init
);
15 Dialog
._addEvent = function (el
, evname
, func
) {
17 el
.attachEvent("on" + evname
, func
);
19 el
.addEventListener(evname
, func
, true);
23 Dialog
._removeEvent = function (el
, evname
, func
) {
25 el
.detachEvent("on" + evname
, func
);
27 el
.removeEventListener(evname
, func
, true);
31 Dialog
._stopEvent = function (ev
) {
33 ev
.cancelBubble
= true;
34 ev
.returnValue
= false;
41 Dialog
._parentEvent = function(ev
) {
42 if (Dialog
._modal
&& !Dialog
._modal
.closed
) {
43 Dialog
._modal
.focus();
44 Dialog
._stopEvent(ev
);
48 // should be a function, the return handler of the currently opened dialog.
49 Dialog
._return
= null;
51 // constant, the currently opened dialog
54 // the dialog will read it's args from this variable
55 Dialog
._arguments
= null;
57 Dialog
._geckoOpenModal = function(url
, width
, height
, action
, init
) {
59 var file
= url
.substring(url
.lastIndexOf('/') + 1, url
.lastIndexOf('.'));
64 var lx
= (screen
.width
- x
) / 2;
65 var tx
= (screen
.height
- y
) / 2;
66 var dlg
= window
.open(url
, "ha_dialog", "toolbar=no,menubar=no,personalbar=no, width="+ x
+",height="+ y
+",scrollbars=no,resizable=no, left="+ lx
+", top="+ tx
+"");
68 Dialog
._arguments
= init
;
70 // capture some window's events
72 Dialog
._addEvent(w
, "click", Dialog
._parentEvent
);
73 Dialog
._addEvent(w
, "mousedown", Dialog
._parentEvent
);
74 Dialog
._addEvent(w
, "focus", Dialog
._parentEvent
);
76 // release the captured events
78 Dialog
._removeEvent(w
, "click", Dialog
._parentEvent
);
79 Dialog
._removeEvent(w
, "mousedown", Dialog
._parentEvent
);
80 Dialog
._removeEvent(w
, "focus", Dialog
._parentEvent
);
83 // capture other frames, note the exception trapping, this is because
84 // we are not permitted to add events to frames outside of the current
86 for (var i
= 0; i
< window
.frames
.length
; i
++) {try { capwin(window
.frames
[i
]); } catch(e
) { } };
87 // make up a function to be called when the Dialog ends.
88 Dialog
._return = function (val
) {
93 // capture other frames
94 for (var i
= 0; i
< window
.frames
.length
; i
++) { try { relwin(window
.frames
[i
]); } catch(e
) { } };
97 Dialog
._modal
.focus();