source: trunk/plugins/ImageManager/assets/dialog.js @ 929

Last change on this file since 929 was 929, checked in by ray, 11 years ago
  • #1115 Dialogs not working on firefox 3
  • #1127 InsertImage? and probably other things using insertNodeAtSelection() not working in FF3
  • Property svn:keywords set to LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
File size: 3.2 KB
Line 
1// Dialog v3.0 - Copyright (c) 2003-2004 interactivetools.com, inc.
2// This copyright notice MUST stay intact for use (see license.txt).
3//
4// Portions (c) dynarch.com, 2003-2004
5//
6// A free WYSIWYG editor replacement for <textarea> fields.
7// For full source code and docs, visit http://www.interactivetools.com/
8//
9// Version 3.0 developed by Mihai Bazon.
10//   http://dynarch.com/mishoo
11//
12// $Id$
13
14// Though "Dialog" looks like an object, it isn't really an object.  Instead
15// it's just namespace for protecting global symbols.
16
17function Dialog(url, action, init) {
18        if (typeof init == "undefined") {
19                init = window;  // pass this window object by default
20        }
21        if (typeof window.showModalDialog == 'function')
22        {
23                Dialog._return = action;
24                var r = window.showModalDialog(url, init, "dialogheight=10;dialogwidth=10;resizable=yes");
25        }
26        else
27        {
28                Dialog._geckoOpenModal(url, action, init);
29        }
30}
31
32Dialog._parentEvent = function(ev) {
33        setTimeout( function() { if (Dialog._modal && !Dialog._modal.closed) { Dialog._modal.focus() } }, 50);
34        if (Dialog._modal && !Dialog._modal.closed) {
35                Dialog._stopEvent(ev);
36        }
37};
38
39
40// should be a function, the return handler of the currently opened dialog.
41Dialog._return = null;
42
43// constant, the currently opened dialog
44Dialog._modal = null;
45
46// the dialog will read it's args from this variable
47Dialog._arguments = null;
48
49Dialog._geckoOpenModal = function(url, action, init) {
50        //var urlLink = "hadialog"+url.toString();
51        var myURL = "hadialog"+url;
52        var regObj = /\W/g;
53        myURL = myURL.replace(regObj,'_');
54        var dlg = window.open(url, myURL,
55                              "toolbar=no,menubar=no,personalbar=no,width=10,height=10," +
56                              "scrollbars=no,resizable=yes,modal=yes,dependable=yes");
57        Dialog._modal = dlg;
58        Dialog._arguments = init;
59
60        // capture some window's events
61        function capwin(w) {
62                Dialog._addEvent(w, "click", Dialog._parentEvent);
63                Dialog._addEvent(w, "mousedown", Dialog._parentEvent);
64                Dialog._addEvent(w, "focus", Dialog._parentEvent);
65        }
66        // release the captured events
67        function relwin(w) {
68                Dialog._removeEvent(w, "click", Dialog._parentEvent);
69                Dialog._removeEvent(w, "mousedown", Dialog._parentEvent);
70                Dialog._removeEvent(w, "focus", Dialog._parentEvent);
71        }
72        capwin(window);
73        // capture other frames
74        for (var i = 0; i < window.frames.length; capwin(window.frames[i++]));
75        // make up a function to be called when the Dialog ends.
76        Dialog._return = function (val) {
77                if (val && action) {
78                        action(val);
79                }
80                relwin(window);
81                // capture other frames
82                for (var i = 0; i < window.frames.length; relwin(window.frames[i++]));
83                Dialog._modal = null;
84        };
85};
86
87
88// event handling
89
90Dialog._addEvent = function(el, evname, func) {
91        if (Dialog.is_ie) {
92                el.attachEvent("on" + evname, func);
93        } else {
94                el.addEventListener(evname, func, true);
95        }
96};
97
98
99Dialog._removeEvent = function(el, evname, func) {
100        if (Dialog.is_ie) {
101                el.detachEvent("on" + evname, func);
102        } else {
103                el.removeEventListener(evname, func, true);
104        }
105};
106
107
108Dialog._stopEvent = function(ev) {
109        if (Dialog.is_ie) {
110                ev.cancelBubble = true;
111                ev.returnValue = false;
112        } else {
113                ev.preventDefault();
114                ev.stopPropagation();
115        }
116};
117
118Dialog.agt = navigator.userAgent.toLowerCase();
119Dialog.is_ie       = ((Dialog.agt.indexOf("msie") != -1) && (Dialog.agt.indexOf("opera") == -1));
Note: See TracBrowser for help on using the repository browser.