source: branches/2.2.0.1/phpgwapi/js/dJSWin/dJSWin.js @ 4034

Revision 4034, 16.7 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #1598 - Implementada a barra de rolagem horizontal na busca por F9.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
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.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;if(document.getElementById("window_QuickCatalogSearch")) document.getElementById("window_QuickCatalogSearch").style.visibility = "hidden";};
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               
329                /* Add new window to the array */
330                arrayJSWin[params.content_id] = this;
331        }
332
333        dJSWin.prototype.close = function()
334        {
335                var _this = this;
336                _this.state = 0;
337                dd.elements[this.title.id].hide();
338                /* Turn the attribute visible false */
339                this.visible = false;
340                //Remove attribute onclick
341                var divBan = document.getElementById('divAppbox');
342                divBan.removeAttribute('onclick');
343                if (is_ie){
344                        divBan.onclick = function(){};
345                }
346        }
347       
348
349        dJSWin.prototype.open = function()
350        {
351/*              if (is_ie)
352                {
353                        this.moveTo(document.body.offsetWidth/2 - dd.elements[this.title.id].w/2,
354                                    document.body.offsetHeight/2 - dd.elements[this.winContainer.id].h/2);
355                }
356                else
357                {
358                        this.moveTo(window.innerWidth/2 - dd.elements[this.title.id].w/2,
359                                    window.innerHeight/2 - dd.elements[this.clientArea.id].h/2);
360                }
361*/
362                if (is_ie)
363                {
364                        this.moveTo(document.body.offsetWidth/2 + document.body.scrollLeft - dd.elements[this.title.id].w/2,
365                                    document.body.offsetHeight/2 + document.body.scrollTop - dd.elements[this.winContainer.id].h/2);
366                }
367                else
368                {
369                        this.moveTo(window.innerWidth/2 + window.pageXOffset - dd.elements[this.title.id].w/2,
370                                    window.innerHeight/2 + window.pageYOffset - dd.elements[this.clientArea.id].h/2);
371                }
372               
373                dd.elements[this.title.id].maximizeZ();
374                dd.elements[this.title.id].show();
375                /* Turn the attribute visible true */
376                this.visible = true;
377        }
378
379        dJSWin.prototype.show = function()
380        {
381                this.open();
382        }
383
384        dJSWin.prototype.hide = function()
385        {
386                this.close();
387        }
388
389        dJSWin.prototype.moveTo = function(x,y)
390        {
391                dd.elements[this.title.id].moveTo(x,y);
392        }
393
394        dJSWin.prototype.x = function()
395        {
396                return dd.elements[this.title.id].x;
397        }
398
399        dJSWin.prototype.y = function()
400        {
401                return dd.elements[this.title.id].y;
402        }
403
404        dJSWin.prototype.draw = function()
405        {
406                if (dd.elements && dd.elements[this.title.id])
407                {
408                        return;
409                }
410
411                if (is_ie)
412                {
413                        ADD_DHTML(this.winContainer.id+NO_DRAG);
414                }
415                else
416                {
417                        ADD_DHTML(this.border.t.id+NO_DRAG);
418                }
419                ADD_DHTML(this.title.id+CURSOR_MOVE);
420                ADD_DHTML(this.clientArea.id+NO_DRAG);
421                ADD_DHTML(this.buttons.xDIV.id+NO_DRAG);
422                ADD_DHTML(this.content.id+NO_DRAG);
423                ADD_DHTML(this.shadows.r.id+NO_DRAG);
424                ADD_DHTML(this.shadows.b.id+NO_DRAG);
425                ADD_DHTML(this.border.b.id+NO_DRAG);
426                ADD_DHTML(this.border.l.id+NO_DRAG);
427                ADD_DHTML(this.border.r.id+NO_DRAG);
428               
429                if (is_ie)
430                {
431                        dd.elements[this.title.id].addChild(dd.elements[this.winContainer.id]);
432                }
433                else
434                {
435                        dd.elements[this.title.id].addChild(dd.elements[this.border.t.id]);
436                }
437                //dd.elements[this.title.id].setZ(dd.elements[this.border.t.id].z+1);
438                //dd.elements[this.title.id].maximizeZ();
439
440                dd.elements[this.title.id].addChild(dd.elements[this.clientArea.id]);
441                dd.elements[this.title.id].addChild(dd.elements[this.buttons.xDIV.id]);
442                dd.elements[this.title.id].addChild(dd.elements[this.content.id]);
443                dd.elements[this.title.id].addChild(dd.elements[this.shadows.r.id]);
444                dd.elements[this.title.id].addChild(dd.elements[this.shadows.b.id]);
445                dd.elements[this.title.id].addChild(dd.elements[this.border.b.id]);
446                dd.elements[this.title.id].addChild(dd.elements[this.border.l.id]);
447                dd.elements[this.title.id].addChild(dd.elements[this.border.r.id]);
448
449
450                if (typeof(this.includedContents) == 'object')
451                {
452                        for (var i in this.includedContents)
453                        {
454                                ADD_DHTML(this.includedContents[i]+NO_DRAG);
455                                dd.elements[this.title.id].addChild(dd.elements[this.includedContents[i]]);
456                        }
457                }
458
459//              dd.elements[this.title.id].setZ('-1');
460
461                if (is_ie)
462                {
463                        dd.elements[this.title.id].moveTo(document.body.offsetWidth/2 - dd.elements[this.winContainer.id].w/2,
464                                                          document.body.offsetHeight/2 - dd.elements[this.winContainer.id].h/2)
465                }
466                else
467                {
468                        dd.elements[this.title.id].moveTo(window.innerWidth/2 - dd.elements[this.clientArea.id].w/2,
469                                                          window.innerHeight/2 - dd.elements[this.clientArea.id].h/2);
470                }
471               
472                dd.elements[this.title.id].hide();
473        }
474
475        function _dJSWinElement(id)
476        {
477                if (document.getElementById)
478                {
479                        return document.getElementById(id);
480                }
481                else if (document.all)
482                {
483                        return document.all[id];
484                }
485                else
486                {
487                        throw("Browser Not Supported!");
488                }
489        }
490
491        if (!dd.elements)
492        {
493                var div = document.createElement('div');
494                div.id = '__NONE__#';
495                div.style.position = 'absolute';
496               
497                SET_DHTML(div.id);
498        }
499}
Note: See TracBrowser for help on using the repository browser.