source: trunk/plugins/ExtendedFileManager/assets/dialog.js @ 999

Last change on this file since 999 was 999, checked in by ray, 11 years ago

#1195 Allow to specify an external url to load a plugin from

  • Property svn:keywords set to LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
File size: 3.6 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:dialog.js 929 2008-01-09 21:10:59Z ray $
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// should be a function, the return handler of the currently opened dialog.
40Dialog._return = null;
41
42// constant, the currently opened dialog
43Dialog._modal = null;
44
45// the dialog will read it's args from this variable
46Dialog._arguments = null;
47
48Dialog._geckoOpenModal = function(url, action, init) {
49    //var urlLink = "hadialog"+url.toString();
50    var myURL = "hadialog"+url;
51    var regObj = /\W/g;
52    myURL = myURL.replace(regObj,'_');
53    var dlg = window.open(url, myURL,
54                  "toolbar=no,menubar=no,personalbar=no,width=10,height=10," +
55                  "scrollbars=no,resizable=yes,modal=yes,dependable=yes");
56    Dialog._modal = dlg;
57    Dialog._arguments = init;
58
59    // capture some window's events
60    function capwin(w) {
61        Dialog._addEvent(w, "click", Dialog._parentEvent);
62        Dialog._addEvent(w, "mousedown", Dialog._parentEvent);
63        Dialog._addEvent(w, "focus", Dialog._parentEvent);
64    };
65    // release the captured events
66    function relwin(w) {
67        Dialog._removeEvent(w, "click", Dialog._parentEvent);
68        Dialog._removeEvent(w, "mousedown", Dialog._parentEvent);
69        Dialog._removeEvent(w, "focus", Dialog._parentEvent);
70    };
71    capwin(window);
72    // capture other frames
73    for (var i = 0; i < window.frames.length; capwin(window.frames[i++]));
74    // make up a function to be called when the Dialog ends.
75    Dialog._return = function (val) {
76        if (val && action) {
77            action(val);
78        }
79        relwin(window);
80        // capture other frames
81        for (var i = 0; i < window.frames.length; relwin(window.frames[i++]));
82        Dialog._modal = null;
83    };
84};
85
86// event handling
87
88Dialog._addEvent = function(el, evname, func) {
89    if (Dialog.is_ie) {
90        el.attachEvent("on" + evname, func);
91    } else {
92        el.addEventListener(evname, func, true);
93    }
94};
95
96Dialog._removeEvent = function(el, evname, func) {
97    if (Dialog.is_ie) {
98        el.detachEvent("on" + evname, func);
99    } else {
100        el.removeEventListener(evname, func, true);
101    }
102};
103
104Dialog._stopEvent = function(ev) {
105    if (Dialog.is_ie) {
106        ev.cancelBubble = true;
107        ev.returnValue = false;
108    } else {
109        ev.preventDefault();
110        ev.stopPropagation();
111    }
112};
113
114Dialog.agt = navigator.userAgent.toLowerCase();
115Dialog.is_ie = ((Dialog.agt.indexOf("msie") != -1) && (Dialog.agt.indexOf("opera") == -1));
Note: See TracBrowser for help on using the repository browser.