source: sandbox/2.3-MailArchiver/phpgwapi/js/dJSWin/dJSWin.js @ 6779

Revision 6779, 17.4 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado Expresso(branch 2.3) integrado ao MailArchiver?.

Line 
1  /****************************************************************************\
2   * Dynamic JS Win - Javascript Object                                       *
3   *                                                                          *
4   * Written by:                                                              *
5   *  - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net>        *
6   * ------------------------------------------------------------------------ *
7   *  This program is free software; you can redistribute it and/or modify it *
8   *  under the terms of the GNU General Public License as published by the   *
9   *  Free Software Foundation; either version 2 of the License, or (at your  *
10   *  option) any later version.                                              *
11  \****************************************************************************/
12
13/* Global array for created windows */
14var arrayJSWin = new Array();
15
16if (!window.__DEFINE_DJSWIN__)
17{
18        __DEFINE_DJSWIN__ = true;
19       
20        if (document.all)
21        {
22                navigator.userAgent.toLowerCase().indexOf('msie 5') != -1 ? is_ie5 = true : is_ie5 = false;
23                is_ie = true;
24                is_moz1_6 = false;
25                is_mozilla = false;
26                is_ns4 = false;
27        }
28        else if (document.getElementById)
29        {
30                navigator.userAgent.toLowerCase().match('mozilla.*rv[:]1\.6.*gecko') ? is_moz1_6 = true : is_moz1_6 = false;
31                is_ie = false;
32                is_ie5 = false;
33                is_mozilla = true;
34                is_ns4 = false;
35        }
36        else if (document.layers)
37        {
38                is_ie = false;
39                is_ie5 = false
40                is_moz1_6 = false;
41                is_mozilla = false;
42                is_ns4 = true;
43        }
44
45        if (!window.dd)
46        {
47                throw("wz_dragdrop lib must be loaded!");
48        }
49               
50        function dJSWin(params)
51        {
52                if (!params || typeof(params) != 'object' || !params.id || !params.width || !params.height || !params.content_id)
53                {
54                        throw("Can't create empty window or window without width, height or ID");
55                }
56
57                /* Internal Variables */
58                if (is_ie)
59                {
60                        this.onclose = params.onclose;
61                        this.winContainer = document.createElement('iframe');
62                }
63                this.clientArea = document.createElement('div');
64                this.title = document.createElement('div');
65                this.title_text = document.createElement('span');
66                this.buttons = new Array();
67                this.button_ext = "";
68                this.state = "";
69                this.shadows = new Array();
70                this.border = new Array();
71                this.content = _dJSWinElement(params.content_id);
72                this.includedContents = params['include_contents'];
73                var _this = this;
74
75                if (is_moz1_6)
76                {
77                        var content_ = this.content;
78                        this.content = this.content.cloneNode(true);
79
80                        content_.id = content_.id+'CLONE';
81                        content_.style.display = 'none';
82                }
83
84                this.border['t'] = document.createElement('div');
85                this.border['b'] = document.createElement('div');
86                this.border['l'] = document.createElement('div');
87                this.border['r'] = document.createElement('div');
88
89                this.shadows['r'] = document.createElement('div');
90                this.shadows['b'] = document.createElement('div');
91
92                this.buttons['xDIV'] = document.createElement('div');
93
94                if (params['button_x_img'])
95                {
96                        this.buttons['xIMG'] = document.createElement('IMG');
97                        this.buttons['xIMG'].src = params['button_x_img'];
98                        this.buttons['xIMG'].style.cursor = 'hand';
99                        this.buttons['xDIV'].appendChild(this.buttons['xIMG']);
100                }
101                else
102                {
103                        this.buttons.xDIV.innerHTML = 'X';
104                }
105
106                if (params['button_y_img'])
107                {
108                        var _this = this;
109                       
110                        this.button_ext = document.createElement('IMG');
111                        this.button_ext.id = 'button_ext';
112                        this.button_ext.src = params['button_y_img'];
113                        this.button_ext.style.position = 'absolute';
114                        this.button_ext.style.cursor = 'pointer';
115                        this.button_ext.style.top = '1px';
116                        this.button_ext.style.left = parseInt(params['width']) - 28      + 'px';
117                        this.button_ext.style.zIndex = '1';
118                        this.button_ext.onclick = function(){_this.hide();_this.state = 1;};
119                }
120               
121                /* Inicialization */
122                this.title.id = params['id'];
123                this.title.style.position = 'absolute';
124                this.title.style.visibility = 'hidden';
125                this.title.style.width = parseInt(params['width']) + 2 + 'px';
126                this.title.style.height = params['title_height'] ? params['title_height'] : '18px';
127                this.title.style.backgroundColor = params['title_color'];
128                this.title.style.top = '0px';
129                this.title.style.left = '0px';
130                this.title.style.zIndex = '1';
131               
132                this.title_text.style.position = 'relative';
133                this.title_text.className = params['title_class'];
134                this.title_text.style.fontWeight = 'bold';
135                this.title_text.style.color = params['title_text_color'] ? params['title_text_color'] : 'black';
136//              this.title_text.style.cursor = 'move';
137                this.title_text.innerHTML = params['title'];
138                this.title_text.style.zIndex = '1';
139
140                if (is_ie)
141                {
142                        this.winContainer.id = params['id']+'_winContainer';
143                        this.winContainer.style.position = 'absolute';
144                        this.winContainer.style.visibility = 'hidden';
145                        this.winContainer.style.width  = params['width'];
146                        //this.winContainer.style.height = parseInt(params['height']) + parseInt(this.title.style.height) + 'px';
147                        this.winContainer.style.height = params['height'];
148        //              this.winContainer.style.top = '0px';
149                        this.winContainer.style.top = this.title.style.height;
150                        this.winContainer.style.left = '0px';
151                        this.winContainer.style.zIndex = '-1';
152        //              this.winContainer.style.backgroundColor = params['bg_color'];
153        //              this.winContainer.className = params['win_class'];
154                        this.winContainer.src = '';
155                }
156               
157                this.clientArea.id = params['id']+'_clientArea';
158                this.clientArea.style.position = 'absolute';
159                this.clientArea.style.visibility = 'hidden';
160                this.clientArea.style.width  = parseInt(params['width']) + 2 + 'px';
161                this.clientArea.style.height = params['height'];
162                this.clientArea.style.top = parseInt(this.title.style.height) + 'px';
163                this.clientArea.style.left = '0px';
164                this.clientArea.style.backgroundColor = params['bg_color'];
165//              this.clientArea.style.overflow = 'auto';
166                this.clientArea.className = params['win_class'];
167               
168                this.buttons.xDIV.id = params['id']+'_button';
169                this.buttons.xDIV.style.position = 'absolute';
170                this.buttons.xDIV.style.visibility = 'hidden';
171                this.buttons.xDIV.style.cursor = 'hand';
172                this.buttons.xDIV.style.top = '1px';
173                this.buttons.xDIV.style.left = parseInt(params['width']) - 13 + 'px';
174                this.buttons.xDIV.style.zIndex = '1';
175                this.buttons.xDIV.onclick = function() {_this.close();_this.state = 2;if(document.getElementById("window_QuickCatalogSearch")) document.getElementById("window_QuickCatalogSearch").style.visibility = "hidden";};
176               
177                this.content.style.visibility = 'hidden';
178                //this.content.style.top = parseInt(this.title.style.height) + 'px';
179                this.content.style.top = '0px';
180                this.content.style.left = '0px';
181               
182                this.shadows.b.id = params['id']+'_shadowb';
183                this.shadows.b.style.position = 'absolute';
184                this.shadows.b.style.visibility = 'hidden';
185                this.shadows.b.style.backgroundColor = '#666';
186                this.shadows.b.style.width = params['width'];
187                this.shadows.b.style.height = '4px';
188                this.shadows.b.style.top = parseInt(this.title.style.height) + parseInt(params['height']) + 'px';
189                this.shadows.b.style.left = '4px';
190               
191                this.shadows.r.id = params['id']+'_shadowr';
192                this.shadows.r.style.position = 'absolute';
193                this.shadows.r.style.visibility = 'hidden';
194                this.shadows.r.style.backgroundColor = '#666';
195                this.shadows.r.style.width = '4px';
196                this.shadows.r.style.height = parseInt(params['height']) + parseInt(this.title.style.height) + 'px';
197                this.shadows.r.style.top  = '4px';
198                this.shadows.r.style.left = params['width'];
199
200                this.border.t.id = params['id']+'_border_t';
201                this.border.b.id = params['id']+'_border_b';
202                this.border.l.id = params['id']+'_border_l';
203                this.border.r.id = params['id']+'_border_r';
204               
205                this.border.t.style.position = 'absolute';
206                this.border.b.style.position = 'absolute';
207                this.border.l.style.position = 'absolute';
208                this.border.r.style.position = 'absolute';
209
210                this.border.t.style.visibility = 'hidden';
211                this.border.b.style.visibility = 'hidden';
212                this.border.l.style.visibility = 'hidden';
213                this.border.r.style.visibility = 'hidden';
214
215                this.border.t.style.backgroundColor = params['title_color'];
216                this.border.b.style.backgroundColor = params['title_color'];
217                this.border.l.style.backgroundColor = params['title_color'];
218                this.border.r.style.backgroundColor = params['title_color'];
219               
220                this.border.t.className = params['title_class'];
221                this.border.b.className = params['title_class'];
222                this.border.l.className = params['title_class'];
223                this.border.r.className = params['title_class'];
224
225                this.border.t.style.border = '0px';
226                this.border.b.style.border = '0px';
227                this.border.l.style.border = '0px';
228                this.border.r.style.border = '0px';
229
230                if (params['border'])
231                {
232                        this.border.t.style.width = parseInt(params['width']) + 2 + 'px';
233                        this.border.b.style.width = parseInt(params['width']) + 2 + 'px';
234                        this.border.l.style.width = '2px';
235                        this.border.r.style.width = '2px';
236
237                        if (is_ie)
238                        {
239                                this.border.t.style.height = '0';
240                                this.border.b.style.height = '0';
241                                this.border.l.style.height = parseInt(params['height']) + parseInt(this.title.style.height) + 2 + 'px';
242                                this.border.r.style.height = parseInt(params['height']) + parseInt(this.title.style.height) + 2 + 'px';
243
244                                this.border.t.style.top = '0';
245                                this.border.b.style.top = parseInt(params['height']) + parseInt(this.title.style.height) + 'px';
246                                this.border.l.style.top = '0';
247                                this.border.r.style.top = '0';
248                        }
249                        else
250                        {
251                                this.border.t.style.height = '2px';
252                                this.border.b.style.height = '2px';
253                                this.border.l.style.height = parseInt(params['height']) + parseInt(this.title.style.height) + 4 + 'px';
254                                this.border.r.style.height = parseInt(params['height']) + parseInt(this.title.style.height) + 4 + 'px';
255
256                                this.border.t.style.top = '-2px';
257                                this.border.b.style.top = parseInt(params['height']) + parseInt(this.title.style.height) + 'px';
258                                this.border.l.style.top = '-2px';
259                                this.border.r.style.top = '-2px';
260                        }
261
262                        this.border.t.style.left = '-2px';
263                        this.border.b.style.left = '-2px';
264                        this.border.l.style.left = '-2px';
265                        this.border.r.style.left = params['width'];
266
267                        //this.winContainer.style.width  = parseInt(this.winContainer.style.width) + 4 + 'px';
268                        //this.winContainer.style.height = parseInt(this.winContainer.style.height) + 4 + 'px';
269                        //this.clientArea.style.width    = parseInt(this.clientArea.style.width) + 4 + 'px';
270                        //this.clientArea.style.height   = parseInt(this.clientArea.style.height) + 4 + 'px';
271
272                        //this.title.style.top = parseInt(this.title.style.top) + 2 + 'px';
273                        //this.clientArea.style.top = parseInt(this.clientArea.style.top) + 2 + 'px';
274                        //this.buttons.xDIV.style.top = parseInt(this.buttons.xDIV.style.top) + 2 + 'px';
275                        this.shadows.b.style.top = parseInt(this.shadows.b.style.top) + 2 + 'px';
276                        this.shadows.r.style.top = parseInt(this.shadows.r.style.top) + 2 + 'px';
277                        //this.content.style.top = parseInt(this.content.style.top) + 2 + 'px';
278
279                        //this.title.style.left = parseInt(this.title.style.left) + 2 + 'px';
280                        //this.clientArea.style.left = parseInt(this.clientArea.style.left) + 2 + 'px';
281                        //this.buttons.xDIV.style.left = parseInt(this.buttons.xDIV.style.left) + 2 + 'px';
282                        this.shadows.b.style.left = parseInt(this.shadows.b.style.left) + 2 + 'px';
283                        this.shadows.r.style.left = parseInt(this.shadows.r.style.left) + 2 + 'px';
284                        //this.content.style.left = '2px';
285                }
286                else
287                {
288                        this.border.t.style.width = '0px';
289                        this.border.b.style.width = '0px';
290                        this.border.l.style.width = '0px';
291                        this.border.r.style.width = '0px';
292                }
293               
294                if (!is_moz1_6)
295                {
296                        this.content.parentNode.removeChild(this.content);
297                }
298/*
299                this.winContainer.appendChild(this.title);
300                this.winContainer.appendChild(this.buttons.xDIV);
301                this.winContainer.appendChild(this.border.t);
302                this.winContainer.appendChild(this.border.b);
303                this.winContainer.appendChild(this.border.l);
304                this.winContainer.appendChild(this.border.r);
305                this.winContainer.appendChild(this.shadows.r);
306                this.winContainer.appendChild(this.shadows.b);
307                this.winContainer.appendChild(this.content);
308*/
309                if (is_ie)
310                {
311                        this.title.appendChild(this.winContainer);
312                }
313                else
314                {
315                        this.title.appendChild(this.border.t);
316                }
317                this.title.appendChild(this.title_text);
318                this.title.appendChild(this.clientArea);
319                this.title.appendChild(this.buttons.xDIV);
320                if(this.button_ext){this.title.appendChild(this.button_ext);};         
321                this.title.appendChild(this.border.b);
322                this.title.appendChild(this.border.l);
323                this.title.appendChild(this.border.r);
324                this.title.appendChild(this.shadows.r);
325                this.title.appendChild(this.shadows.b);
326                this.clientArea.appendChild(this.content);
327               
328                document.body.appendChild(this.title);
329               
330                /* Add new window to the array */
331                arrayJSWin[params.content_id] = this;
332        }
333
334        dJSWin.prototype.close = function()
335        {
336                var _this = this;
337                _this.state = 0;
338
339                if (typeof this.onclose != 'undefined')
340                {
341                    eval(this.onclose);
342                }
343               
344                //MailArchiver remove embeded iframe object
345                if(this.title.id == 'win_import_local_window'){
346                   var iframeobj = Element('ma_import_local');
347                   if(iframeobj){
348                       iframeobj.style.display = 'none';
349                       iframeobj.parentNode.removeChild(iframeobj);
350                   }                                 
351                }
352               
353                dd.elements[this.title.id].hide();
354                /* Turn the attribute visible false */
355                this.visible = false;
356                //Remove attribute onclick
357                var divBan = document.getElementById('divAppbox');
358                divBan.removeAttribute('onclick');
359                if (is_ie){
360                        divBan.onclick = function(){};
361                }   
362        }
363       
364
365        dJSWin.prototype.open = function()
366        {
367/*              if (is_ie)
368                {
369                        this.moveTo(document.body.offsetWidth/2 - dd.elements[this.title.id].w/2,
370                                    document.body.offsetHeight/2 - dd.elements[this.winContainer.id].h/2);
371                }
372                else
373                {
374                        this.moveTo(window.innerWidth/2 - dd.elements[this.title.id].w/2,
375                                    window.innerHeight/2 - dd.elements[this.clientArea.id].h/2);
376                }
377*/
378                if (is_ie)
379                {
380                        this.moveTo(document.body.offsetWidth/2 + document.body.scrollLeft - dd.elements[this.title.id].w/2,
381                                    document.body.offsetHeight/2 + document.body.scrollTop - dd.elements[this.winContainer.id].h/2);
382                }
383                else
384                {
385                        this.moveTo(window.innerWidth/2 + window.pageXOffset - dd.elements[this.title.id].w/2,
386                                    window.innerHeight/2 + window.pageYOffset - dd.elements[this.clientArea.id].h/2);
387                }
388               
389                dd.elements[this.title.id].maximizeZ();
390                dd.elements[this.title.id].show();
391               
392                /* Turn the attribute visible true */
393                this.visible = true;
394        }
395
396        dJSWin.prototype.show = function()
397        {
398                this.open();
399        }
400
401        dJSWin.prototype.hide = function()
402        {
403                this.close();
404        }
405
406        dJSWin.prototype.moveTo = function(x,y)
407        {
408                dd.elements[this.title.id].moveTo(x,y);
409        }
410
411        dJSWin.prototype.x = function()
412        {
413                return dd.elements[this.title.id].x;
414        }
415
416        dJSWin.prototype.y = function()
417        {
418                return dd.elements[this.title.id].y;
419        }
420
421        dJSWin.prototype.draw = function()
422        {
423                if (dd.elements && dd.elements[this.title.id])
424                {
425                        return;
426                }
427
428                if (is_ie)
429                {
430                        ADD_DHTML(this.winContainer.id+NO_DRAG);
431                }
432                else
433                {
434                        ADD_DHTML(this.border.t.id+NO_DRAG);
435                }
436                ADD_DHTML(this.title.id+CURSOR_MOVE);
437                ADD_DHTML(this.clientArea.id+NO_DRAG);
438                ADD_DHTML(this.buttons.xDIV.id+NO_DRAG);
439                ADD_DHTML(this.content.id+NO_DRAG);
440                ADD_DHTML(this.shadows.r.id+NO_DRAG);
441                ADD_DHTML(this.shadows.b.id+NO_DRAG);
442                ADD_DHTML(this.border.b.id+NO_DRAG);
443                ADD_DHTML(this.border.l.id+NO_DRAG);
444                ADD_DHTML(this.border.r.id+NO_DRAG);
445               
446                if (is_ie)
447                {
448                        dd.elements[this.title.id].addChild(dd.elements[this.winContainer.id]);
449                }
450                else
451                {
452                        dd.elements[this.title.id].addChild(dd.elements[this.border.t.id]);
453                }
454                //dd.elements[this.title.id].setZ(dd.elements[this.border.t.id].z+1);
455                //dd.elements[this.title.id].maximizeZ();
456
457                dd.elements[this.title.id].addChild(dd.elements[this.clientArea.id]);
458                dd.elements[this.title.id].addChild(dd.elements[this.buttons.xDIV.id]);
459                dd.elements[this.title.id].addChild(dd.elements[this.content.id]);
460                dd.elements[this.title.id].addChild(dd.elements[this.shadows.r.id]);
461                dd.elements[this.title.id].addChild(dd.elements[this.shadows.b.id]);
462                dd.elements[this.title.id].addChild(dd.elements[this.border.b.id]);
463                dd.elements[this.title.id].addChild(dd.elements[this.border.l.id]);
464                dd.elements[this.title.id].addChild(dd.elements[this.border.r.id]);
465
466
467                if (typeof(this.includedContents) == 'object')
468                {
469                        for (var i in this.includedContents)
470                        {
471                                ADD_DHTML(this.includedContents[i]+NO_DRAG);
472                                dd.elements[this.title.id].addChild(dd.elements[this.includedContents[i]]);
473                        }
474                }
475
476//              dd.elements[this.title.id].setZ('-1');
477
478                if (is_ie)
479                {
480                        dd.elements[this.title.id].moveTo(document.body.offsetWidth/2 - dd.elements[this.winContainer.id].w/2,
481                                                          document.body.offsetHeight/2 - dd.elements[this.winContainer.id].h/2)
482                }
483                else
484                {
485                        dd.elements[this.title.id].moveTo(window.innerWidth/2 - dd.elements[this.clientArea.id].w/2,
486                                                          window.innerHeight/2 - dd.elements[this.clientArea.id].h/2);
487                }
488               
489                dd.elements[this.title.id].hide();
490        }
491
492        function _dJSWinElement(id)
493        {
494                if (document.getElementById)
495                {
496                        return document.getElementById(id);
497                }
498                else if (document.all)
499                {
500                        return document.all[id];
501                }
502                else
503                {
504                        throw("Browser Not Supported!");
505                }
506        }
507
508        if (!dd.elements)
509        {
510                var div = document.createElement('div');
511                div.id = '__NONE__#';
512                div.style.position = 'absolute';
513               
514                SET_DHTML(div.id);
515        }
516}
Note: See TracBrowser for help on using the repository browser.