source: trunk/modules/Dialogs/dialog.js @ 978

Last change on this file since 978 was 978, checked in by ray, 11 years ago
  • #1160 Safari puts selected HTML near bottom if edited
  • #1157 FF3B3 and popups
  • Property svn:eol-style set to native
  • Property svn:keywords set to LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
File size: 3.4 KB
Line 
1
2  /*--------------------------------------:noTabs=true:tabSize=2:indentSize=2:--
3    --  Xinha (is not htmlArea) - http://xinha.gogo.co.nz/
4    --
5    --  Use of Xinha is granted by the terms of the htmlArea License (based on
6    --  BSD license)  please read license.txt in this package for details.
7    --
8    --  Xinha was originally based on work by Mihai Bazon which is:
9    --      Copyright (c) 2003-2004 dynarch.com.
10    --      Copyright (c) 2002-2003 interactivetools.com, inc.
11    --      This copyright notice MUST stay intact for use.
12    --
13    --  This is the implementation of the standard popup dialog
14    --
15    --   Though "Dialog" looks like an object, it isn't really an object.  Instead
16    --   it's just namespace for protecting global symbols.
17    --
18    --
19    --  $HeadURL$
20    --  $LastChangedDate$
21    --  $LastChangedRevision$
22    --  $LastChangedBy$
23    --------------------------------------------------------------------------*/
24
25
26function Dialog(url, action, init) {
27        if (typeof init == "undefined") {
28                init = window;  // pass this window object by default
29        }
30        if (typeof window.showModalDialog == 'function' && !Xinha.is_webkit) // webkit easily looses the selection with window.showModalDialog
31        {
32                Dialog._return = function(retVal) {
33                        if (typeof action == 'function') action (retVal);
34                }
35                var r = window.showModalDialog(url, init, "dialogheight=300;dialogwidth=400;resizable=yes");
36        }
37        else
38        {
39                Dialog._geckoOpenModal(url, action, init);
40        }
41}
42
43Dialog._parentEvent = function(ev) {
44        setTimeout( function() { if (Dialog._modal && !Dialog._modal.closed) { Dialog._modal.focus() } }, 50);
45        try {
46                if (Dialog._modal && !Dialog._modal.closed) {
47                        Xinha._stopEvent(ev);
48                }
49        } catch (e) {
50                //after closing the popup in IE the events are not released and trying to access Dialog._modal.closed causes an error
51        }
52};
53
54
55// should be a function, the return handler of the currently opened dialog.
56Dialog._return = null;
57
58// constant, the currently opened dialog
59Dialog._modal = null;
60
61// the dialog will read it's args from this variable
62Dialog._arguments = null;
63
64Dialog._selection = null;
65
66Dialog._geckoOpenModal = function(url, action, init) {
67        var dlg = window.open(url, "hadialog",
68                              "toolbar=no,menubar=no,personalbar=no,width=10,height=10," +
69                              "scrollbars=no,resizable=yes,modal=yes,dependable=yes");
70        Dialog._modal = dlg;
71        Dialog._arguments = init;
72
73        // capture some window's events
74        function capwin(w) {
75                Xinha._addEvent(w, "click", Dialog._parentEvent);
76                Xinha._addEvent(w, "mousedown", Dialog._parentEvent);
77                Xinha._addEvent(w, "focus", Dialog._parentEvent);
78        }
79        // release the captured events
80        function relwin(w) {
81                Xinha._removeEvent(w, "click", Dialog._parentEvent);
82                Xinha._removeEvent(w, "mousedown", Dialog._parentEvent);
83                Xinha._removeEvent(w, "focus", Dialog._parentEvent);
84        }
85        capwin(window);
86        // capture other frames, note the exception trapping, this is because
87  // we are not permitted to add events to frames outside of the current
88  // window's domain.
89        for (var i = 0; i < window.frames.length; i++) {try { capwin(window.frames[i]); } catch(e) { } };
90        // make up a function to be called when the Dialog ends.
91        Dialog._return = function (val) {
92                if (val && action) {
93                        action(val);
94                }
95                relwin(window);
96                // capture other frames
97                for (var i = 0; i < window.frames.length; i++) { try { relwin(window.frames[i]); } catch(e) { } };
98                Dialog._modal = null;
99        };
100  Dialog._modal.focus();
101};
Note: See TracBrowser for help on using the repository browser.