annotate get_data/cfg_array/info/Primary Screen_files/PopupWindow.js @ 0:89592faa2875 draft

Uploaded
author chrisb
date Wed, 23 Mar 2016 14:35:56 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
89592faa2875 Uploaded
chrisb
parents:
diff changeset
1 // ===================================================================
89592faa2875 Uploaded
chrisb
parents:
diff changeset
2 // Author: Matt Kruse <matt@mattkruse.com>
89592faa2875 Uploaded
chrisb
parents:
diff changeset
3 // WWW: http://www.mattkruse.com/
89592faa2875 Uploaded
chrisb
parents:
diff changeset
4 //
89592faa2875 Uploaded
chrisb
parents:
diff changeset
5 // NOTICE: You may use this code for any purpose, commercial or
89592faa2875 Uploaded
chrisb
parents:
diff changeset
6 // private, without any further permission from the author. You may
89592faa2875 Uploaded
chrisb
parents:
diff changeset
7 // remove this notice from your final code if you wish, however it is
89592faa2875 Uploaded
chrisb
parents:
diff changeset
8 // appreciated by the author if at least my web site address is kept.
89592faa2875 Uploaded
chrisb
parents:
diff changeset
9 //
89592faa2875 Uploaded
chrisb
parents:
diff changeset
10 // You may *NOT* re-distribute this code in any way except through its
89592faa2875 Uploaded
chrisb
parents:
diff changeset
11 // use. That means, you can include it in your product, or your web
89592faa2875 Uploaded
chrisb
parents:
diff changeset
12 // site, or any other form where the code is actually being used. You
89592faa2875 Uploaded
chrisb
parents:
diff changeset
13 // may not put the plain javascript up on your site for download or
89592faa2875 Uploaded
chrisb
parents:
diff changeset
14 // include it in your javascript libraries for download.
89592faa2875 Uploaded
chrisb
parents:
diff changeset
15 // If you wish to share this code with others, please just point them
89592faa2875 Uploaded
chrisb
parents:
diff changeset
16 // to the URL instead.
89592faa2875 Uploaded
chrisb
parents:
diff changeset
17 // Please DO NOT link directly to my .js files from your site. Copy
89592faa2875 Uploaded
chrisb
parents:
diff changeset
18 // the files to your server and use them there. Thank you.
89592faa2875 Uploaded
chrisb
parents:
diff changeset
19 // ===================================================================
89592faa2875 Uploaded
chrisb
parents:
diff changeset
20
89592faa2875 Uploaded
chrisb
parents:
diff changeset
21 /*
89592faa2875 Uploaded
chrisb
parents:
diff changeset
22 PopupWindow.js
89592faa2875 Uploaded
chrisb
parents:
diff changeset
23 Author: Matt Kruse
89592faa2875 Uploaded
chrisb
parents:
diff changeset
24 Last modified: 02/16/04
89592faa2875 Uploaded
chrisb
parents:
diff changeset
25
89592faa2875 Uploaded
chrisb
parents:
diff changeset
26 DESCRIPTION: This object allows you to easily and quickly popup a window
89592faa2875 Uploaded
chrisb
parents:
diff changeset
27 in a certain place. The window can either be a DIV or a separate browser
89592faa2875 Uploaded
chrisb
parents:
diff changeset
28 window.
89592faa2875 Uploaded
chrisb
parents:
diff changeset
29
89592faa2875 Uploaded
chrisb
parents:
diff changeset
30 COMPATABILITY: Works with Netscape 4.x, 6.x, IE 5.x on Windows. Some small
89592faa2875 Uploaded
chrisb
parents:
diff changeset
31 positioning errors - usually with Window positioning - occur on the
89592faa2875 Uploaded
chrisb
parents:
diff changeset
32 Macintosh platform. Due to bugs in Netscape 4.x, populating the popup
89592faa2875 Uploaded
chrisb
parents:
diff changeset
33 window with <STYLE> tags may cause errors.
89592faa2875 Uploaded
chrisb
parents:
diff changeset
34
89592faa2875 Uploaded
chrisb
parents:
diff changeset
35 USAGE:
89592faa2875 Uploaded
chrisb
parents:
diff changeset
36 // Create an object for a WINDOW popup
89592faa2875 Uploaded
chrisb
parents:
diff changeset
37 var win = new PopupWindow();
89592faa2875 Uploaded
chrisb
parents:
diff changeset
38
89592faa2875 Uploaded
chrisb
parents:
diff changeset
39 // Create an object for a DIV window using the DIV named 'mydiv'
89592faa2875 Uploaded
chrisb
parents:
diff changeset
40 var win = new PopupWindow('mydiv');
89592faa2875 Uploaded
chrisb
parents:
diff changeset
41
89592faa2875 Uploaded
chrisb
parents:
diff changeset
42 // Set the window to automatically hide itself when the user clicks
89592faa2875 Uploaded
chrisb
parents:
diff changeset
43 // anywhere else on the page except the popup
89592faa2875 Uploaded
chrisb
parents:
diff changeset
44 win.autoHide();
89592faa2875 Uploaded
chrisb
parents:
diff changeset
45
89592faa2875 Uploaded
chrisb
parents:
diff changeset
46 // Show the window relative to the anchor name passed in
89592faa2875 Uploaded
chrisb
parents:
diff changeset
47 win.showPopup(anchorname);
89592faa2875 Uploaded
chrisb
parents:
diff changeset
48
89592faa2875 Uploaded
chrisb
parents:
diff changeset
49 // Hide the popup
89592faa2875 Uploaded
chrisb
parents:
diff changeset
50 win.hidePopup();
89592faa2875 Uploaded
chrisb
parents:
diff changeset
51
89592faa2875 Uploaded
chrisb
parents:
diff changeset
52 // Set the size of the popup window (only applies to WINDOW popups
89592faa2875 Uploaded
chrisb
parents:
diff changeset
53 win.setSize(width,height);
89592faa2875 Uploaded
chrisb
parents:
diff changeset
54
89592faa2875 Uploaded
chrisb
parents:
diff changeset
55 // Populate the contents of the popup window that will be shown. If you
89592faa2875 Uploaded
chrisb
parents:
diff changeset
56 // change the contents while it is displayed, you will need to refresh()
89592faa2875 Uploaded
chrisb
parents:
diff changeset
57 win.populate(string);
89592faa2875 Uploaded
chrisb
parents:
diff changeset
58
89592faa2875 Uploaded
chrisb
parents:
diff changeset
59 // set the URL of the window, rather than populating its contents
89592faa2875 Uploaded
chrisb
parents:
diff changeset
60 // manually
89592faa2875 Uploaded
chrisb
parents:
diff changeset
61 win.setUrl("http://www.site.com/");
89592faa2875 Uploaded
chrisb
parents:
diff changeset
62
89592faa2875 Uploaded
chrisb
parents:
diff changeset
63 // Refresh the contents of the popup
89592faa2875 Uploaded
chrisb
parents:
diff changeset
64 win.refresh();
89592faa2875 Uploaded
chrisb
parents:
diff changeset
65
89592faa2875 Uploaded
chrisb
parents:
diff changeset
66 // Specify how many pixels to the right of the anchor the popup will appear
89592faa2875 Uploaded
chrisb
parents:
diff changeset
67 win.offsetX = 50;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
68
89592faa2875 Uploaded
chrisb
parents:
diff changeset
69 // Specify how many pixels below the anchor the popup will appear
89592faa2875 Uploaded
chrisb
parents:
diff changeset
70 win.offsetY = 100;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
71
89592faa2875 Uploaded
chrisb
parents:
diff changeset
72 NOTES:
89592faa2875 Uploaded
chrisb
parents:
diff changeset
73 1) Requires the functions in AnchorPosition.js
89592faa2875 Uploaded
chrisb
parents:
diff changeset
74
89592faa2875 Uploaded
chrisb
parents:
diff changeset
75 2) Your anchor tag MUST contain both NAME and ID attributes which are the
89592faa2875 Uploaded
chrisb
parents:
diff changeset
76 same. For example:
89592faa2875 Uploaded
chrisb
parents:
diff changeset
77 <A NAME="test" ID="test"> </A>
89592faa2875 Uploaded
chrisb
parents:
diff changeset
78
89592faa2875 Uploaded
chrisb
parents:
diff changeset
79 3) There must be at least a space between <A> </A> for IE5.5 to see the
89592faa2875 Uploaded
chrisb
parents:
diff changeset
80 anchor tag correctly. Do not do <A></A> with no space.
89592faa2875 Uploaded
chrisb
parents:
diff changeset
81
89592faa2875 Uploaded
chrisb
parents:
diff changeset
82 4) When a PopupWindow object is created, a handler for 'onmouseup' is
89592faa2875 Uploaded
chrisb
parents:
diff changeset
83 attached to any event handler you may have already defined. Do NOT define
89592faa2875 Uploaded
chrisb
parents:
diff changeset
84 an event handler for 'onmouseup' after you define a PopupWindow object or
89592faa2875 Uploaded
chrisb
parents:
diff changeset
85 the autoHide() will not work correctly.
89592faa2875 Uploaded
chrisb
parents:
diff changeset
86 */
89592faa2875 Uploaded
chrisb
parents:
diff changeset
87
89592faa2875 Uploaded
chrisb
parents:
diff changeset
88 // Set the position of the popup window based on the anchor
89592faa2875 Uploaded
chrisb
parents:
diff changeset
89 function PopupWindow_getXYPosition(anchorname) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
90 var coordinates;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
91 if (this.type == "WINDOW") {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
92 coordinates = getAnchorWindowPosition(anchorname);
89592faa2875 Uploaded
chrisb
parents:
diff changeset
93 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
94 else {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
95 coordinates = getAnchorPosition(anchorname);
89592faa2875 Uploaded
chrisb
parents:
diff changeset
96 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
97 this.x = coordinates.x;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
98 this.y = coordinates.y;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
99 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
100 // Set width/height of DIV/popup window
89592faa2875 Uploaded
chrisb
parents:
diff changeset
101 function PopupWindow_setSize(width,height) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
102 this.width = width;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
103 this.height = height;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
104 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
105 // Fill the window with contents
89592faa2875 Uploaded
chrisb
parents:
diff changeset
106 function PopupWindow_populate(contents) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
107 this.contents = contents;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
108 this.populated = false;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
109 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
110 // Set the URL to go to
89592faa2875 Uploaded
chrisb
parents:
diff changeset
111 function PopupWindow_setUrl(url) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
112 this.url = url;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
113 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
114 // Set the window popup properties
89592faa2875 Uploaded
chrisb
parents:
diff changeset
115 function PopupWindow_setWindowProperties(props) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
116 this.windowProperties = props;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
117 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
118 // Refresh the displayed contents of the popup
89592faa2875 Uploaded
chrisb
parents:
diff changeset
119 function PopupWindow_refresh() {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
120 if (this.divName != null) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
121 // refresh the DIV object
89592faa2875 Uploaded
chrisb
parents:
diff changeset
122 if (this.use_gebi) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
123 document.getElementById(this.divName).innerHTML = this.contents;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
124 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
125 else if (this.use_css) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
126 document.all[this.divName].innerHTML = this.contents;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
127 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
128 else if (this.use_layers) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
129 var d = document.layers[this.divName];
89592faa2875 Uploaded
chrisb
parents:
diff changeset
130 d.document.open();
89592faa2875 Uploaded
chrisb
parents:
diff changeset
131 d.document.writeln(this.contents);
89592faa2875 Uploaded
chrisb
parents:
diff changeset
132 d.document.close();
89592faa2875 Uploaded
chrisb
parents:
diff changeset
133 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
134 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
135 else {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
136 if (this.popupWindow != null && !this.popupWindow.closed) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
137 if (this.url!="") {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
138 this.popupWindow.location.href=this.url;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
139 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
140 else {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
141 this.popupWindow.document.open();
89592faa2875 Uploaded
chrisb
parents:
diff changeset
142 this.popupWindow.document.writeln(this.contents);
89592faa2875 Uploaded
chrisb
parents:
diff changeset
143 this.popupWindow.document.close();
89592faa2875 Uploaded
chrisb
parents:
diff changeset
144 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
145 this.popupWindow.focus();
89592faa2875 Uploaded
chrisb
parents:
diff changeset
146 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
147 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
148 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
149 // Position and show the popup, relative to an anchor object
89592faa2875 Uploaded
chrisb
parents:
diff changeset
150 function PopupWindow_showPopup(anchorname) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
151 this.getXYPosition(anchorname);
89592faa2875 Uploaded
chrisb
parents:
diff changeset
152 this.x += this.offsetX;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
153 this.y += this.offsetY;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
154 if (!this.populated && (this.contents != "")) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
155 this.populated = true;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
156 this.refresh();
89592faa2875 Uploaded
chrisb
parents:
diff changeset
157 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
158 if (this.divName != null) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
159 // Show the DIV object
89592faa2875 Uploaded
chrisb
parents:
diff changeset
160 if (this.use_gebi) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
161 document.getElementById(this.divName).style.left = this.x + "px";
89592faa2875 Uploaded
chrisb
parents:
diff changeset
162 document.getElementById(this.divName).style.top = this.y + "px";
89592faa2875 Uploaded
chrisb
parents:
diff changeset
163 document.getElementById(this.divName).style.visibility = "visible";
89592faa2875 Uploaded
chrisb
parents:
diff changeset
164 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
165 else if (this.use_css) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
166 document.all[this.divName].style.left = this.x;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
167 document.all[this.divName].style.top = this.y;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
168 document.all[this.divName].style.visibility = "visible";
89592faa2875 Uploaded
chrisb
parents:
diff changeset
169 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
170 else if (this.use_layers) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
171 document.layers[this.divName].left = this.x;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
172 document.layers[this.divName].top = this.y;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
173 document.layers[this.divName].visibility = "visible";
89592faa2875 Uploaded
chrisb
parents:
diff changeset
174 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
175 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
176 else {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
177 if (this.popupWindow == null || this.popupWindow.closed) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
178 // If the popup window will go off-screen, move it so it doesn't
89592faa2875 Uploaded
chrisb
parents:
diff changeset
179 if (this.x<0) { this.x=0; }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
180 if (this.y<0) { this.y=0; }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
181 if (screen && screen.availHeight) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
182 if ((this.y + this.height) > screen.availHeight) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
183 this.y = screen.availHeight - this.height;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
184 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
185 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
186 if (screen && screen.availWidth) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
187 if ((this.x + this.width) > screen.availWidth) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
188 this.x = screen.availWidth - this.width;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
189 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
190 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
191 var avoidAboutBlank = window.opera || ( document.layers && !navigator.mimeTypes['*'] ) || navigator.vendor == 'KDE' || ( document.childNodes && !document.all && !navigator.taintEnabled );
89592faa2875 Uploaded
chrisb
parents:
diff changeset
192 this.popupWindow = window.open(avoidAboutBlank?"":"about:blank","window_"+anchorname,this.windowProperties+",width="+this.width+",height="+this.height+",screenX="+this.x+",left="+this.x+",screenY="+this.y+",top="+this.y+"");
89592faa2875 Uploaded
chrisb
parents:
diff changeset
193 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
194 this.refresh();
89592faa2875 Uploaded
chrisb
parents:
diff changeset
195 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
196 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
197 // Hide the popup
89592faa2875 Uploaded
chrisb
parents:
diff changeset
198 function PopupWindow_hidePopup() {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
199 if (this.divName != null) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
200 if (this.use_gebi) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
201 document.getElementById(this.divName).style.visibility = "hidden";
89592faa2875 Uploaded
chrisb
parents:
diff changeset
202 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
203 else if (this.use_css) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
204 document.all[this.divName].style.visibility = "hidden";
89592faa2875 Uploaded
chrisb
parents:
diff changeset
205 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
206 else if (this.use_layers) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
207 document.layers[this.divName].visibility = "hidden";
89592faa2875 Uploaded
chrisb
parents:
diff changeset
208 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
209 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
210 else {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
211 if (this.popupWindow && !this.popupWindow.closed) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
212 this.popupWindow.close();
89592faa2875 Uploaded
chrisb
parents:
diff changeset
213 this.popupWindow = null;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
214 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
215 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
216 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
217 // Pass an event and return whether or not it was the popup DIV that was clicked
89592faa2875 Uploaded
chrisb
parents:
diff changeset
218 function PopupWindow_isClicked(e) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
219 if (this.divName != null) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
220 if (this.use_layers) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
221 var clickX = e.pageX;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
222 var clickY = e.pageY;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
223 var t = document.layers[this.divName];
89592faa2875 Uploaded
chrisb
parents:
diff changeset
224 if ((clickX > t.left) && (clickX < t.left+t.clip.width) && (clickY > t.top) && (clickY < t.top+t.clip.height)) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
225 return true;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
226 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
227 else { return false; }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
228 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
229 else if (document.all) { // Need to hard-code this to trap IE for error-handling
89592faa2875 Uploaded
chrisb
parents:
diff changeset
230 var t = window.event.srcElement;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
231 while (t.parentElement != null) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
232 if (t.id==this.divName) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
233 return true;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
234 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
235 t = t.parentElement;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
236 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
237 return false;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
238 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
239 else if (this.use_gebi && e) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
240 var t = e.originalTarget;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
241 while (t.parentNode != null) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
242 if (t.id==this.divName) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
243 return true;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
244 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
245 t = t.parentNode;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
246 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
247 return false;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
248 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
249 return false;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
250 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
251 return false;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
252 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
253
89592faa2875 Uploaded
chrisb
parents:
diff changeset
254 // Check an onMouseDown event to see if we should hide
89592faa2875 Uploaded
chrisb
parents:
diff changeset
255 function PopupWindow_hideIfNotClicked(e) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
256 if (this.autoHideEnabled && !this.isClicked(e)) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
257 this.hidePopup();
89592faa2875 Uploaded
chrisb
parents:
diff changeset
258 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
259 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
260 // Call this to make the DIV disable automatically when mouse is clicked outside it
89592faa2875 Uploaded
chrisb
parents:
diff changeset
261 function PopupWindow_autoHide() {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
262 this.autoHideEnabled = true;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
263 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
264 // This global function checks all PopupWindow objects onmouseup to see if they should be hidden
89592faa2875 Uploaded
chrisb
parents:
diff changeset
265 function PopupWindow_hidePopupWindows(e) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
266 for (var i=0; i<popupWindowObjects.length; i++) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
267 if (popupWindowObjects[i] != null) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
268 var p = popupWindowObjects[i];
89592faa2875 Uploaded
chrisb
parents:
diff changeset
269 p.hideIfNotClicked(e);
89592faa2875 Uploaded
chrisb
parents:
diff changeset
270 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
271 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
272 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
273 // Run this immediately to attach the event listener
89592faa2875 Uploaded
chrisb
parents:
diff changeset
274 function PopupWindow_attachListener() {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
275 if (document.layers) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
276 document.captureEvents(Event.MOUSEUP);
89592faa2875 Uploaded
chrisb
parents:
diff changeset
277 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
278 window.popupWindowOldEventListener = document.onmouseup;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
279 if (window.popupWindowOldEventListener != null) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
280 document.onmouseup = new Function("window.popupWindowOldEventListener(); PopupWindow_hidePopupWindows();");
89592faa2875 Uploaded
chrisb
parents:
diff changeset
281 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
282 else {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
283 document.onmouseup = PopupWindow_hidePopupWindows;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
284 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
285 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
286 // CONSTRUCTOR for the PopupWindow object
89592faa2875 Uploaded
chrisb
parents:
diff changeset
287 // Pass it a DIV name to use a DHTML popup, otherwise will default to window popup
89592faa2875 Uploaded
chrisb
parents:
diff changeset
288 function PopupWindow() {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
289 if (!window.popupWindowIndex) { window.popupWindowIndex = 0; }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
290 if (!window.popupWindowObjects) { window.popupWindowObjects = new Array(); }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
291 if (!window.listenerAttached) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
292 window.listenerAttached = true;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
293 PopupWindow_attachListener();
89592faa2875 Uploaded
chrisb
parents:
diff changeset
294 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
295 this.index = popupWindowIndex++;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
296 popupWindowObjects[this.index] = this;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
297 this.divName = null;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
298 this.popupWindow = null;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
299 this.width=0;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
300 this.height=0;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
301 this.populated = false;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
302 this.visible = false;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
303 this.autoHideEnabled = false;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
304
89592faa2875 Uploaded
chrisb
parents:
diff changeset
305 this.contents = "";
89592faa2875 Uploaded
chrisb
parents:
diff changeset
306 this.url="";
89592faa2875 Uploaded
chrisb
parents:
diff changeset
307 this.windowProperties="toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,resizable,alwaysRaised,dependent,titlebar=no";
89592faa2875 Uploaded
chrisb
parents:
diff changeset
308 if (arguments.length>0) {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
309 this.type="DIV";
89592faa2875 Uploaded
chrisb
parents:
diff changeset
310 this.divName = arguments[0];
89592faa2875 Uploaded
chrisb
parents:
diff changeset
311 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
312 else {
89592faa2875 Uploaded
chrisb
parents:
diff changeset
313 this.type="WINDOW";
89592faa2875 Uploaded
chrisb
parents:
diff changeset
314 }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
315 this.use_gebi = false;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
316 this.use_css = false;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
317 this.use_layers = false;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
318 if (document.getElementById) { this.use_gebi = true; }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
319 else if (document.all) { this.use_css = true; }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
320 else if (document.layers) { this.use_layers = true; }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
321 else { this.type = "WINDOW"; }
89592faa2875 Uploaded
chrisb
parents:
diff changeset
322 this.offsetX = 0;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
323 this.offsetY = 0;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
324 // Method mappings
89592faa2875 Uploaded
chrisb
parents:
diff changeset
325 this.getXYPosition = PopupWindow_getXYPosition;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
326 this.populate = PopupWindow_populate;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
327 this.setUrl = PopupWindow_setUrl;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
328 this.setWindowProperties = PopupWindow_setWindowProperties;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
329 this.refresh = PopupWindow_refresh;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
330 this.showPopup = PopupWindow_showPopup;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
331 this.hidePopup = PopupWindow_hidePopup;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
332 this.setSize = PopupWindow_setSize;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
333 this.isClicked = PopupWindow_isClicked;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
334 this.autoHide = PopupWindow_autoHide;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
335 this.hideIfNotClicked = PopupWindow_hideIfNotClicked;
89592faa2875 Uploaded
chrisb
parents:
diff changeset
336 }