default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / elements / qlib / wndctrl.js
1 /**\r
2  * QLIB 1.0 Window Abstraction\r
3  * Copyright (C) 2002 2003, Quazzle.com Serge Dolgov\r
4  * This program is free software; you can redistribute it and/or\r
5  * modify it under the terms of the GNU General Public License\r
6  * as published by the Free Software Foundation; either version 2\r
7  * of the License, or (at your option) any later version.\r
8  * http://qlib.quazzle.com\r
9  */\r
10 \r
11 function QWndCtrl_center_ie4() {\r
12     var b = this.document.body;\r
13     this.moveTo(b.scrollLeft + Math.max(0, Math.floor((b.clientWidth -\r
14         this.width) / 2)), b.scrollTop + 100);\r
15 }\r
16 \r
17 function QWndCtrl_center_moz() {\r
18     this.moveTo(self.pageXOffset + Math.max(0, Math.floor((self.innerWidth -\r
19         this.width) / 2)), self.pageYOffset + 100);\r
20 }\r
21 \r
22 function QWndCtrl_setEffects_ie4(fx) {\r
23     this.effects = fx;\r
24     with (this.wnd) {\r
25         filters[0].enabled = (fx & 256) != 0;\r
26         filters[1].enabled = (fx & 512) != 0;\r
27         filters[2].enabled = (fx & 1024) != 0;\r
28         filters[4].enabled = (fx & 2048) != 0;\r
29     }\r
30 }\r
31 \r
32 function QWndCtrl_setEffects_moz(fx) {\r
33     this.effects = fx;\r
34 }\r
35 \r
36 function QWndCtrl_setOpacity_ie4(op) {\r
37     this.opacity = Math.max(0, Math.min(100, Math.floor(op - 0)));\r
38     this.wnd.filters[3].opacity = this.opacity;\r
39     this.wnd.filters[3].enabled = (this.opacity < 100);\r
40 }\r
41 \r
42 function QWndCtrl_setOpacity_moz(op) {\r
43     this.opacity = Math.max(0, Math.min(100, Math.floor(op - 0)));\r
44     this.wnd.style.MozOpacity = this.opacity + "%";\r
45 }\r
46 \r
47 function QWndCtrl_setSize_css(w, h) {\r
48     this.wnd.style.width = (this.width = Math.floor(w - 0)) + "px";\r
49     this.wnd.style.height = typeof(h) == "number" ? (this.height = Math.floor(h)) + "px" : "auto";\r
50 }\r
51 \r
52 function QWndCtrl_setSize_ns4(w, h) {\r
53     this.wnd.clip.width = this.width = Math.floor(w - 0);\r
54     if (typeof(h) == "number") {\r
55         this.wnd.clip.height = this.height = Math.floor(h);\r
56     }\r
57 }\r
58 \r
59 function QWndCtrl_focus() {\r
60     this.setZIndex(QWndCtrl.TOPZINDEX++);\r
61 }\r
62 \r
63 function QWndCtrl_setZIndex_css(z) {\r
64     this.wnd.style.zIndex = this.zindex = z || 0;\r
65 }\r
66 \r
67 function QWndCtrl_setZIndex_ns4(z) {\r
68     this.wnd.zIndex = this.zindex = z || 0;\r
69 }\r
70 \r
71 function QWndCtrl_moveTo_css(x, y) {\r
72     this.wnd.style.left = (this.x = Math.floor(x - 0)) + "px";\r
73     this.wnd.style.top = (this.y = Math.floor(y - 0)) + "px";\r
74 }\r
75 \r
76 function QWndCtrl_moveTo_ns4(x, y) {\r
77     this.wnd.moveTo(this.x = Math.floor(x - 0), this.y = Math.floor(y - 0));\r
78 }\r
79 \r
80 function QWndCtrl_fxhandler() {\r
81     this.fxhandler = QControl.nop;\r
82     this.onShow(this.visible, this.tag);\r
83 }\r
84 \r
85 function QWndCtrl_show_ie4(show) {\r
86     if (this.visible != show) {\r
87         var fx = false;\r
88         switch (show ? this.effects & 15 : (this.effects & 240) >>> 4) {\r
89             case 1:\r
90                 fx = this.wnd.filters[5];\r
91                 break;\r
92             case 2:\r
93                 (fx = this.wnd.filters[6]).transition = show ? 1 : 0;\r
94                 break;\r
95             case 3:\r
96                 (fx = this.wnd.filters[6]).transition = show ? 3 : 2;\r
97                 break;\r
98             case 4:\r
99                 (fx = this.wnd.filters[6]).transition = show ? 5 : 4;\r
100                 break;\r
101             case 5:\r
102                 (fx = this.wnd.filters[6]).transition = show ? 14 : 13;\r
103                 break;\r
104             case 6:\r
105                 (fx = this.wnd.filters[6]).transition = show ? 16 : 15;\r
106                 break;\r
107             case 7:\r
108                 (fx = this.wnd.filters[6]).transition = 12;\r
109                 break;\r
110             case 8:\r
111                 (fx = this.wnd.filters[6]).transition = 8;\r
112                 break;\r
113             case 9:\r
114                 (fx = this.wnd.filters[6]).transition = 9;\r
115         }\r
116         if (fx) {\r
117             fx.apply();\r
118             this.wnd.style.visibility = (this.visible = show) ? "visible" : "hidden";\r
119             this.fxhandler = QWndCtrl_fxhandler;\r
120             fx.play(0.3);\r
121         } else {\r
122             this.wnd.style.visibility = (this.visible = show) ? "visible" : "hidden";\r
123             this.onShow(show, this.tag);\r
124         }\r
125     }\r
126 }\r
127 \r
128 function QWndCtrl_fade_moz(op, step) {\r
129     this._wndt = false;\r
130     if (step) {\r
131         op += step;\r
132         if ((op > 0) && (op < this.opacity)) {\r
133             this.wnd.style.MozOpacity = op + "%";\r
134             this._wndt = setTimeout(this.name + ".fade(" + op + "," + step + ")", 50);\r
135         } else {\r
136             if (op <= 0) {\r
137                 this.wnd.style.visibility = "hidden";\r
138                 this.visible = false;\r
139             }\r
140             this.wnd.style.MozOpacity = this.opacity + "%";\r
141             this.onShow(this.visible, this.tag);\r
142         }\r
143     }\r
144 }\r
145 \r
146 function QWndCtrl_show_moz(show) {\r
147     if (this.visible != show) {\r
148         if (this._wndt) {\r
149             clearTimeout(this._wndt);\r
150             this._wndt = false;\r
151         }\r
152         var step = show ? ((this.effects & 15) == 1) && Math.floor(this.opacity / 5) :\r
153             ((this.effects & 240) == 16) && -Math.floor(this.opacity / 5);\r
154         if (step) {\r
155             if (this.visible) {\r
156                 this.fade(this.opacity - 0, step);\r
157             } else {\r
158                 this.wnd.style.MozOpacity = "0%";\r
159                 this.wnd.style.visibility = "visible";\r
160                 this.visible = true;\r
161                 this.fade(0, step);\r
162             }\r
163         } else {\r
164             this.wnd.style.visibility = (this.visible = show) ? "visible" : "hidden";\r
165             this.onShow(show, this.tag);\r
166         }\r
167     }\r
168 }\r
169 \r
170 function QWndCtrl_show_css(show) {\r
171     if (this.visible != show) {\r
172         this.wnd.style.visibility = (this.visible = show) ? "visible" : "hidden";\r
173         this.onShow(show, this.tag);\r
174     }\r
175 }\r
176 \r
177 function QWndCtrl_show_ns4(show) {\r
178     if (this.visible != show) {\r
179         this.wnd.visibility = (this.visible = show) ? "show" : "hidden";\r
180         this.onShow(show, this.tag);\r
181     }\r
182 }\r
183 \r
184 function QWndCtrl_create_dom2() {\r
185     with (this) {\r
186         this.fxhandler = QControl.nop;\r
187         var ie4 = document.body && document.body.filters;\r
188         var moz = document.body && document.body.style &&\r
189             typeof(document.body.style.MozOpacity) == "string";\r
190         document.write('<div unselectable="on" id="' + id +\r
191             (ie4 ? '" onfilterchange="' + name + '.fxhandler()': '') +\r
192             '" style="position:absolute;left:' + x + 'px;top:' + y +\r
193             'px;width:' + width + (height != null ? 'px;height:' + height : '') +\r
194             'px;visibility:' + (visible ? 'visible' : 'hidden') +\r
195             ';overflow:hidden' + (zindex ? ';z-index:' + zindex : '') +\r
196             (ie4 ? ';filter:Gray(enabled=' + (effects & 256 ? '1' : '0') +\r
197             ') Xray(enabled=' + (effects & 512 ? '1' : '0') +\r
198             ') Invert(enabled=' + (effects & 1024 ? '1' : '0') +\r
199             ') alpha(enabled=' + (opacity < 100 ? '1' : '0') + ',opacity=' + opacity +\r
200             ') shadow(enabled=' + (effects & 2048 ? '1' : '0') +\r
201             ',direction=135) BlendTrans(enabled=0) RevealTrans(enabled=0)' : '') +\r
202             (moz && (opacity < 100) ? ';-moz-opacity:' + opacity + '%' : '') +\r
203             '"><div unselectable="on" class="qwindow">');\r
204         if (typeof(content) == "function") {\r
205             this.content();\r
206         } else {\r
207             document.write(content);\r
208         }\r
209         document.write('</div></div>');\r
210         if (this.wnd = document.getElementById ? document.getElementById(id) :\r
211             (document.all.item ? document.all.item(id) : document.all[id])) {\r
212             if (wnd.style) {\r
213                 ie4 = ie4 && wnd.filters;\r
214                 moz = moz && typeof(wnd.style.MozOpacity) == "string";\r
215                 this.moveTo = QWndCtrl_moveTo_css;\r
216                 this.setZIndex = QWndCtrl_setZIndex_css;\r
217                 this.focus = QWndCtrl_focus;\r
218                 this.setSize = QWndCtrl_setSize_css;\r
219                 this.show = ie4 ? QWndCtrl_show_ie4 : (moz ? QWndCtrl_show_moz : QWndCtrl_show_css);\r
220                 this.fade = moz ? QWndCtrl_fade_moz : QControl.nop;\r
221                 this.setOpacity = ie4 ? QWndCtrl_setOpacity_ie4 : (moz ? QWndCtrl_setOpacity_moz : QControl.nop);\r
222                 this.setEffects = ie4 ? QWndCtrl_setEffects_ie4 : (moz ? QWndCtrl_setEffects_moz : QControl.nop);\r
223                 this.center = self.innerWidth ? QWndCtrl_center_moz :\r
224                     (document.body && document.body.clientWidth ? QWndCtrl_center_ie4 : QControl.nop);\r
225             }\r
226         }\r
227     }\r
228 }\r
229 \r
230 function QWndCtrl_create_ns4(finalize) {\r
231     with (this) {\r
232         if (finalize) {\r
233             if (_wnde) {\r
234                 parent.window.onload = _wnde;\r
235                 parent.window.onload();\r
236             }\r
237             document.open();\r
238             document.write('<div class="qwindow">');\r
239             this.content();\r
240             document.write('</div>');\r
241             document.close();\r
242         } else {\r
243             document.write('<layer id="' + id + '" left="' + x + '" top="' + y +\r
244                 '" width="' + width + '" visibility="' + (visible ? 'show' : 'hidden') +\r
245                 (height != null ? '" height="' + height + '" clip="' + width + ',' + height : '') +\r
246                 (zindex ? '" z-index="' + zindex : '') + (typeof(content) != "function" ?\r
247                 '"><div class="qwindow">' + content + '</div></layer>' : '">&nbsp;</layer>'));\r
248             if (this.window = this.wnd = document.layers[id]) {\r
249                 if (this.document = wnd.document) {\r
250                     this.show = QWndCtrl_show_ns4;\r
251                     this.moveTo = QWndCtrl_moveTo_ns4;\r
252                     this.setZIndex = QWndCtrl_setZIndex_ns4;\r
253                     this.focus = QWndCtrl_focus;\r
254                     this.center = QWndCtrl_center_moz;\r
255                     this.setSize = QWndCtrl_setSize_ns4;\r
256                     if (typeof(content) == "function") {\r
257                         this._wnde = parent.window.onload;\r
258                         parent.window.onload = new Function(name + ".create(true)");\r
259                     }\r
260                 }\r
261             }\r
262         }\r
263     }\r
264 }\r
265 \r
266 function QWndCtrl_create_na() {\r
267     this.document.write('Object is not supported.');\r
268     this.wnd = null;\r
269 }\r
270 \r
271 function QWndCtrl_create() {\r
272     with (this) {\r
273         this.create = (document.getElementById || document.all) ? QWndCtrl_create_dom2 :\r
274             (document.layers ? QWndCtrl_create_ns4 : QWndCtrl_create_na);\r
275         create();\r
276     }\r
277 }\r
278 \r
279 function QWndCtrl() {\r
280     this.x = this.y = 0;\r
281     this.width = this.height = 0;\r
282     this.content = "";\r
283     this.visible = true;\r
284     this.effects = 0;\r
285     this.opacity = 100;\r
286     this.zindex = null;\r
287     this._wndt = this._wnde = false;\r
288     this.create = QWndCtrl_create;\r
289     this.show = QControl.nop;\r
290     this.focus = QControl.nop;\r
291     this.center = QControl.nop;\r
292     this.moveTo = QControl.nop;\r
293     this.setSize = QControl.nop;\r
294     this.setOpacity = QControl.nop;\r
295     this.setEffects = QControl.nop;\r
296     this.setZIndex  = QControl.nop;\r
297     this.onShow = QControl.event;\r
298 }\r
299 QWndCtrl.prototype = new QControl();\r
300 QWndCtrl.TOPZINDEX = 1000;\r
301 QWndCtrl.GRAY      = 256;\r
302 QWndCtrl.XRAY      = 512;\r
303 QWndCtrl.INVERT    = 1024;\r
304 QWndCtrl.SHADOW    = 2048;\r
305 QWndCtrl.FADEIN    = 1;\r
306 QWndCtrl.FADEOUT   = 16;\r
307 QWndCtrl.BOXIN     = 2;\r
308 QWndCtrl.BOXOUT    = 32;\r
309 QWndCtrl.CIRCLEIN  = 3;\r
310 QWndCtrl.CIRCLEOUT = 48;\r
311 QWndCtrl.WIPEIN    = 4;\r
312 QWndCtrl.WIPEOUT   = 64;\r
313 QWndCtrl.HBARNIN   = 5;\r
314 QWndCtrl.HBARNOUT  = 80;\r
315 QWndCtrl.VBARNIN   = 6;\r
316 QWndCtrl.VBARNOUT  = 96;\r
317 QWndCtrl.DISSOLVEIN  = 7;\r
318 QWndCtrl.DISSOLVEOUT = 112;\r
319 QWndCtrl.HBLINDSIN   = 8;\r
320 QWndCtrl.HBLINDSOUT  = 128;\r
321 QWndCtrl.VBLINDSIN   = 9;\r
322 QWndCtrl.VBLINDSOUT  = 144;\r