source: companies/serpro/phpgwapi/js/dJSWin/dJSWin.js @ 903

Revision 903, 16.2 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

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
13var arrayJSWin = new Array();
14
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.winContainer = document.createElement('iframe');
61                }
62                this.clientArea = document.createElement('div');
63                this.title = document.createElement('div');
64                this.title_text = document.createElement('span');
65                this.buttons = new Array();
66                this.button_ext = "";
67                this.state = "";
68                this.shadows = new Array();
69                this.border = new Array();
70                this.content = _dJSWinElement(params.content_id);
71                this.includedContents = params['include_contents'];
72                var _this = this;
73
74                if (is_moz1_6)
75                {
76                        var content_ = this.content;
77                        this.content = this.content.cloneNode(true);
78
79                        content_.id = content_.id+'CLONE';
80                        content_.style.display = 'none';
81                }
82
83                this.border['t'] = document.createElement('div');
84                this.border['b'] = document.createElement('div');
85                this.border['l'] = document.createElement('div');
86                this.border['r'] = document.createElement('div');
87
88                this.shadows['r'] = document.createElement('div');
89                this.shadows['b'] = document.createElement('div');
90
91                this.buttons['xDIV'] = document.createElement('div');
92
93                if (params['button_x_img'])
94                {
95                        this.buttons['xIMG'] = document.createElement('IMG');
96                        this.buttons['xIMG'].src = params['button_x_img'];
97                        this.buttons['xIMG'].style.cursor = 'hand';
98                        this.buttons['xDIV'].appendChild(this.buttons['xIMG']);
99                }
100                else
101                {
102                        this.buttons.xDIV.innerHTML = 'X';
103                }
104
105                if (params['button_y_img'])
106                {
107                        var _this = this;
108                       
109                        this.button_ext = document.createElement('IMG');
110                        this.button_ext.id = 'button_ext';
111                        this.button_ext.src = params['button_y_img'];
112                        this.button_ext.style.position = 'absolute';
113                        this.button_ext.style.cursor = 'pointer';
114                        this.button_ext.style.top = '1px';
115                        this.button_ext.style.left = parseInt(params['width']) - 28      + 'px';
116                        this.button_ext.style.zIndex = '1';
117                        this.button_ext.onclick = function(){_this.hide(); _this.state = 1;};
118                }
119               
120                /* Inicialization */
121                this.title.id = params['id'];
122                this.title.style.position = 'absolute';
123                this.title.style.visibility = 'hidden';
124                this.title.style.width = parseInt(params['width']) + 2 + 'px';
125                this.title.style.height = params['title_height'] ? params['title_height'] : '18px';
126                this.title.style.backgroundColor = params['title_color'];
127                this.title.style.top = '0px';
128                this.title.style.left = '0px';
129                this.title.style.zIndex = '1';
130               
131                this.title_text.style.position = 'relative';
132                this.title_text.className = params['title_class'];
133                this.title_text.style.fontWeight = 'bold';
134                this.title_text.style.color = params['title_text_color'] ? params['title_text_color'] : 'black';
135//              this.title_text.style.cursor = 'move';
136                this.title_text.innerHTML = params['title'];
137                this.title_text.style.zIndex = '1';
138
139                if (is_ie)
140                {
141                        this.winContainer.id = params['id']+'_winContainer';
142                        this.winContainer.style.position = 'absolute';
143                        this.winContainer.style.visibility = 'hidden';
144                        this.winContainer.style.width  = params['width'];
145                        //this.winContainer.style.height = parseInt(params['height']) + parseInt(this.title.style.height) + 'px';
146                        this.winContainer.style.height = params['height'];
147        //              this.winContainer.style.top = '0px';
148                        this.winContainer.style.top = this.title.style.height;
149                        this.winContainer.style.left = '0px';
150                        this.winContainer.style.zIndex = '-1';
151        //              this.winContainer.style.backgroundColor = params['bg_color'];
152        //              this.winContainer.className = params['win_class'];
153                        this.winContainer.src = '';
154                }
155               
156                this.clientArea.id = params['id']+'_clientArea';
157                this.clientArea.style.position = 'absolute';
158                this.clientArea.style.visibility = 'hidden';
159                this.clientArea.style.width  = parseInt(params['width']) + 2 + 'px';
160                this.clientArea.style.height = params['height'];
161                this.clientArea.style.top = parseInt(this.title.style.height) + 'px';
162                this.clientArea.style.left = '0px';
163                this.clientArea.style.backgroundColor = params['bg_color'];
164//              this.clientArea.style.overflow = 'auto';
165                this.clientArea.className = params['win_class'];
166               
167                this.buttons.xDIV.id = params['id']+'_button';
168                this.buttons.xDIV.style.position = 'absolute';
169                this.buttons.xDIV.style.visibility = 'hidden';
170                this.buttons.xDIV.style.cursor = 'hand';
171                this.buttons.xDIV.style.top = '1px';
172                this.buttons.xDIV.style.left = parseInt(params['width']) - 13 + 'px';
173                this.buttons.xDIV.style.zIndex = '1';
174                this.buttons.xDIV.onclick = function() {_this.close(); _this.state = 2;};
175               
176                this.content.style.visibility = 'hidden';
177                //this.content.style.top = parseInt(this.title.style.height) + 'px';
178                this.content.style.top = '0px';
179                this.content.style.left = '0px';
180               
181                this.shadows.b.id = params['id']+'_shadowb';
182                this.shadows.b.style.position = 'absolute';
183                this.shadows.b.style.visibility = 'hidden';
184                this.shadows.b.style.backgroundColor = '#666';
185                this.shadows.b.style.width = params['width'];
186                this.shadows.b.style.height = '4px';
187                this.shadows.b.style.top = parseInt(this.title.style.height) + parseInt(params['height']) + 'px';
188                this.shadows.b.style.left = '4px';
189               
190                this.shadows.r.id = params['id']+'_shadowr';
191                this.shadows.r.style.position = 'absolute';
192                this.shadows.r.style.visibility = 'hidden';
193                this.shadows.r.style.backgroundColor = '#666';
194                this.shadows.r.style.width = '4px';
195                this.shadows.r.style.height = parseInt(params['height']) + parseInt(this.title.style.height) + 'px';
196                this.shadows.r.style.top  = '4px';
197                this.shadows.r.style.left = params['width'];
198
199                this.border.t.id = params['id']+'_border_t';
200                this.border.b.id = params['id']+'_border_b';
201                this.border.l.id = params['id']+'_border_l';
202                this.border.r.id = params['id']+'_border_r';
203               
204                this.border.t.style.position = 'absolute';
205                this.border.b.style.position = 'absolute';
206                this.border.l.style.position = 'absolute';
207                this.border.r.style.position = 'absolute';
208
209                this.border.t.style.visibility = 'hidden';
210                this.border.b.style.visibility = 'hidden';
211                this.border.l.style.visibility = 'hidden';
212                this.border.r.style.visibility = 'hidden';
213
214                this.border.t.style.backgroundColor = params['title_color'];
215                this.border.b.style.backgroundColor = params['title_color'];
216                this.border.l.style.backgroundColor = params['title_color'];
217                this.border.r.style.backgroundColor = params['title_color'];
218               
219                this.border.t.className = params['title_class'];
220                this.border.b.className = params['title_class'];
221                this.border.l.className = params['title_class'];
222                this.border.r.className = params['title_class'];
223
224                this.border.t.style.border = '0px';
225                this.border.b.style.border = '0px';
226                this.border.l.style.border = '0px';
227                this.border.r.style.border = '0px';
228
229                if (params['border'])
230                {
231                        this.border.t.style.width = parseInt(params['width']) + 2 + 'px';
232                        this.border.b.style.width = parseInt(params['width']) + 2 + 'px';
233                        this.border.l.style.width = '2px';
234                        this.border.r.style.width = '2px';
235
236                        if (is_ie)
237                        {
238                                this.border.t.style.height = '0';
239                                this.border.b.style.height = '0';
240                                this.border.l.style.height = parseInt(params['height']) + parseInt(this.title.style.height) + 2 + 'px';
241                                this.border.r.style.height = parseInt(params['height']) + parseInt(this.title.style.height) + 2 + 'px';
242
243                                this.border.t.style.top = '0';
244                                this.border.b.style.top = parseInt(params['height']) + parseInt(this.title.style.height) + 'px';
245                                this.border.l.style.top = '0';
246                                this.border.r.style.top = '0';
247                        }
248                        else
249                        {
250                                this.border.t.style.height = '2px';
251                                this.border.b.style.height = '2px';
252                                this.border.l.style.height = parseInt(params['height']) + parseInt(this.title.style.height) + 4 + 'px';
253                                this.border.r.style.height = parseInt(params['height']) + parseInt(this.title.style.height) + 4 + 'px';
254
255                                this.border.t.style.top = '-2px';
256                                this.border.b.style.top = parseInt(params['height']) + parseInt(this.title.style.height) + 'px';
257                                this.border.l.style.top = '-2px';
258                                this.border.r.style.top = '-2px';
259                        }
260
261                        this.border.t.style.left = '-2px';
262                        this.border.b.style.left = '-2px';
263                        this.border.l.style.left = '-2px';
264                        this.border.r.style.left = params['width'];
265
266                        //this.winContainer.style.width  = parseInt(this.winContainer.style.width) + 4 + 'px';
267                        //this.winContainer.style.height = parseInt(this.winContainer.style.height) + 4 + 'px';
268                        //this.clientArea.style.width    = parseInt(this.clientArea.style.width) + 4 + 'px';
269                        //this.clientArea.style.height   = parseInt(this.clientArea.style.height) + 4 + 'px';
270
271                        //this.title.style.top = parseInt(this.title.style.top) + 2 + 'px';
272                        //this.clientArea.style.top = parseInt(this.clientArea.style.top) + 2 + 'px';
273                        //this.buttons.xDIV.style.top = parseInt(this.buttons.xDIV.style.top) + 2 + 'px';
274                        this.shadows.b.style.top = parseInt(this.shadows.b.style.top) + 2 + 'px';
275                        this.shadows.r.style.top = parseInt(this.shadows.r.style.top) + 2 + 'px';
276                        //this.content.style.top = parseInt(this.content.style.top) + 2 + 'px';
277
278                        //this.title.style.left = parseInt(this.title.style.left) + 2 + 'px';
279                        //this.clientArea.style.left = parseInt(this.clientArea.style.left) + 2 + 'px';
280                        //this.buttons.xDIV.style.left = parseInt(this.buttons.xDIV.style.left) + 2 + 'px';
281                        this.shadows.b.style.left = parseInt(this.shadows.b.style.left) + 2 + 'px';
282                        this.shadows.r.style.left = parseInt(this.shadows.r.style.left) + 2 + 'px';
283                        //this.content.style.left = '2px';
284                }
285                else
286                {
287                        this.border.t.style.width = '0px';
288                        this.border.b.style.width = '0px';
289                        this.border.l.style.width = '0px';
290                        this.border.r.style.width = '0px';
291                }
292               
293                if (!is_moz1_6)
294                {
295                        this.content.parentNode.removeChild(this.content);
296                }
297/*
298                this.winContainer.appendChild(this.title);
299                this.winContainer.appendChild(this.buttons.xDIV);
300                this.winContainer.appendChild(this.border.t);
301                this.winContainer.appendChild(this.border.b);
302                this.winContainer.appendChild(this.border.l);
303                this.winContainer.appendChild(this.border.r);
304                this.winContainer.appendChild(this.shadows.r);
305                this.winContainer.appendChild(this.shadows.b);
306                this.winContainer.appendChild(this.content);
307*/
308                if (is_ie)
309                {
310                        this.title.appendChild(this.winContainer);
311                }
312                else
313                {
314                        this.title.appendChild(this.border.t);
315                }
316                this.title.appendChild(this.title_text);
317                this.title.appendChild(this.clientArea);
318                this.title.appendChild(this.buttons.xDIV);
319                if(this.button_ext){this.title.appendChild(this.button_ext);};         
320                this.title.appendChild(this.border.b);
321                this.title.appendChild(this.border.l);
322                this.title.appendChild(this.border.r);
323                this.title.appendChild(this.shadows.r);
324                this.title.appendChild(this.shadows.b);
325                this.clientArea.appendChild(this.content);
326               
327                document.body.appendChild(this.title);
328                /* Add new window to the array */
329                arrayJSWin[params.content_id] = this;
330
331
332        }
333
334        dJSWin.prototype.close = function()
335        {
336                var _this = this;
337                _this.state = 0;
338                dd.elements[this.title.id].hide();
339        }
340
341        dJSWin.prototype.open = function()
342        {
343/*              if (is_ie)
344                {
345                        this.moveTo(document.body.offsetWidth/2 - dd.elements[this.title.id].w/2,
346                                    document.body.offsetHeight/2 - dd.elements[this.winContainer.id].h/2);
347                }
348                else
349                {
350                        this.moveTo(window.innerWidth/2 - dd.elements[this.title.id].w/2,
351                                    window.innerHeight/2 - dd.elements[this.clientArea.id].h/2);
352                }
353*/
354                if (is_ie)
355                {
356                        this.moveTo(document.body.offsetWidth/2 + document.body.scrollLeft - dd.elements[this.title.id].w/2,
357                                    document.body.offsetHeight/2 + document.body.scrollTop - dd.elements[this.winContainer.id].h/2);
358                }
359                else
360                {
361                        this.moveTo(window.innerWidth/2 + window.pageXOffset - dd.elements[this.title.id].w/2,
362                                    window.innerHeight/2 + window.pageYOffset - dd.elements[this.clientArea.id].h/2);
363                }
364               
365                dd.elements[this.title.id].maximizeZ();
366                dd.elements[this.title.id].show();
367        }
368
369        dJSWin.prototype.show = function()
370        {
371                this.open();
372        }
373
374        dJSWin.prototype.hide = function()
375        {
376                this.close();
377        }
378
379        dJSWin.prototype.moveTo = function(x,y)
380        {
381                dd.elements[this.title.id].moveTo(x,y);
382        }
383
384        dJSWin.prototype.x = function()
385        {
386                return dd.elements[this.title.id].x;
387        }
388
389        dJSWin.prototype.y = function()
390        {
391                return dd.elements[this.title.id].y;
392        }
393
394        dJSWin.prototype.draw = function()
395        {
396                if (dd.elements && dd.elements[this.title.id])
397                {
398                        return;
399                }
400
401                if (is_ie)
402                {
403                        ADD_DHTML(this.winContainer.id+NO_DRAG);
404                }
405                else
406                {
407                        ADD_DHTML(this.border.t.id+NO_DRAG);
408                }
409                ADD_DHTML(this.title.id+CURSOR_MOVE);
410                ADD_DHTML(this.clientArea.id+NO_DRAG);
411                ADD_DHTML(this.buttons.xDIV.id+NO_DRAG);
412                ADD_DHTML(this.content.id+NO_DRAG);
413                ADD_DHTML(this.shadows.r.id+NO_DRAG);
414                ADD_DHTML(this.shadows.b.id+NO_DRAG);
415                ADD_DHTML(this.border.b.id+NO_DRAG);
416                ADD_DHTML(this.border.l.id+NO_DRAG);
417                ADD_DHTML(this.border.r.id+NO_DRAG);
418               
419                if (is_ie)
420                {
421                        dd.elements[this.title.id].addChild(dd.elements[this.winContainer.id]);
422                }
423                else
424                {
425                        dd.elements[this.title.id].addChild(dd.elements[this.border.t.id]);
426                }
427                //dd.elements[this.title.id].setZ(dd.elements[this.border.t.id].z+1);
428                //dd.elements[this.title.id].maximizeZ();
429
430                dd.elements[this.title.id].addChild(dd.elements[this.clientArea.id]);
431                dd.elements[this.title.id].addChild(dd.elements[this.buttons.xDIV.id]);
432                dd.elements[this.title.id].addChild(dd.elements[this.content.id]);
433                dd.elements[this.title.id].addChild(dd.elements[this.shadows.r.id]);
434                dd.elements[this.title.id].addChild(dd.elements[this.shadows.b.id]);
435                dd.elements[this.title.id].addChild(dd.elements[this.border.b.id]);
436                dd.elements[this.title.id].addChild(dd.elements[this.border.l.id]);
437                dd.elements[this.title.id].addChild(dd.elements[this.border.r.id]);
438
439
440                if (typeof(this.includedContents) == 'object')
441                {
442                        for (var i in this.includedContents)
443                        {
444                                ADD_DHTML(this.includedContents[i]+NO_DRAG);
445                                dd.elements[this.title.id].addChild(dd.elements[this.includedContents[i]]);
446                        }
447                }
448
449//              dd.elements[this.title.id].setZ('-1');
450
451                if (is_ie)
452                {
453                        dd.elements[this.title.id].moveTo(document.body.offsetWidth/2 - dd.elements[this.winContainer.id].w/2,
454                                                          document.body.offsetHeight/2 - dd.elements[this.winContainer.id].h/2)
455                }
456                else
457                {
458                        dd.elements[this.title.id].moveTo(window.innerWidth/2 - dd.elements[this.clientArea.id].w/2,
459                                                          window.innerHeight/2 - dd.elements[this.clientArea.id].h/2);
460                }
461               
462                dd.elements[this.title.id].hide();
463        }
464
465        function _dJSWinElement(id)
466        {
467                if (document.getElementById)
468                {
469                        return document.getElementById(id);
470                }
471                else if (document.all)
472                {
473                        return document.all[id];
474                }
475                else
476                {
477                        throw("Browser Not Supported!");
478                }
479        }
480
481        if (!dd.elements)
482        {
483                var div = document.createElement('div');
484                div.id = '__NONE__#';
485                div.style.position = 'absolute';
486               
487                SET_DHTML(div.id);
488        }
489}
Note: See TracBrowser for help on using the repository browser.