Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / lib / editor / tinymce / moodledialog.js
blobef02dda57009521b1d461b9540aa0de52481cda5
1 /**
2 * $Id$
4 * Though "Dialog" looks like an object, it isn't really an object. Instead
5 * it's just namespace for protecting global symbols.
6 **/
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) {
16 if ( document.all ) {
17 el.attachEvent("on" + evname, func);
18 } else {
19 el.addEventListener(evname, func, true);
23 Dialog._removeEvent = function (el, evname, func) {
24 if ( document.all ) {
25 el.detachEvent("on" + evname, func);
26 } else {
27 el.removeEventListener(evname, func, true);
31 Dialog._stopEvent = function (ev) {
32 if ( document.all ) {
33 ev.cancelBubble = true;
34 ev.returnValue = false;
35 } else {
36 ev.preventDefault();
37 ev.stopPropagation();
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
52 Dialog._modal = null;
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('.'));
60 var x,y;
61 x = width;
62 y = height;
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 +"");
67 Dialog._modal = dlg;
68 Dialog._arguments = init;
70 // capture some window's events
71 function capwin(w) {
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
77 function relwin(w) {
78 Dialog._removeEvent(w, "click", Dialog._parentEvent);
79 Dialog._removeEvent(w, "mousedown", Dialog._parentEvent);
80 Dialog._removeEvent(w, "focus", Dialog._parentEvent);
82 capwin(window);
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
85 // window's domain.
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) {
89 if (val && action) {
90 action(val);
92 relwin(window);
93 // capture other frames
94 for (var i = 0; i < window.frames.length; i++) { try { relwin(window.frames[i]); } catch(e) { } };
95 Dialog._modal = null;
97 Dialog._modal.focus();