source: trunk/phpgwapi/js/dJSWin/dJSWin.js @ 4761

Revision 4761, 16.9 KB checked in by roberto.santosjunior, 13 years ago (diff)

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