source: trunk/jabberit_messenger/js/load.js @ 624

Revision 624, 16.7 KB checked in by niltonneto, 15 years ago (diff)

Correção de erro intermitente, quando a opção de abrir em
PopUp? está habilitada pelo usuário.

  • Property svn:executable set to *
Line 
1(function()
2{
3        var _conn   = new JITConnector(path_jabberit);
4        var _xtools = new JITXTools(path_jabberit);
5        var _showhidden = new ShowHidden(1500);
6        var myWindow      = '';
7        var flagMouseOver = '';
8        var flagOpenIM    = '';
9        var flagOpenPopup = '';
10   
11        // Sniffer Browser
12        var agt=navigator.userAgent.toLowerCase();
13    var is_major = parseInt(navigator.appVersion);
14    var is_minor = parseFloat(navigator.appVersion);   
15    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
16                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
17                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
18    var is_gecko = (agt.indexOf('gecko') != -1);
19    var is_gecko1_5 = (agt.indexOf('firefox/1.5') != -1 || agt.indexOf('firefox/2') != -1 || agt.indexOf('iceweasel/2') != -1);
20    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
21    var is_ie3    = (is_ie && (is_major < 4));
22    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
23    var is_ie4up  = (is_ie && (is_major >= 4));
24    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
25    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
26    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
27    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
28    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
29    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);   
30    var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
31
32        if ( !(document.getElementById('jabberit_messenger_content')) )
33        {
34                var _jabberit_content = document.createElement('div');
35                _jabberit_content.setAttribute('id', 'jabberit_messenger_content');
36                _jabberit_content = document.body.appendChild(_jabberit_content);
37        }
38
39        var _window = new JITWindows(_xtools, _jabberit_content);
40        var _ldap       = new JITLdap( _conn, _xtools, _window);
41
42        function addIcon()
43        {
44               
45                var StatusBar = document.getElementById('divStatusBar');
46
47                /**
48                 * @quando estiver habilitada a opção fora de escritório nos filtros.
49                 */
50               
51                if( div_write_msg = document.getElementById('em_div_write_msg') )
52                {               
53                        var StatusBarIM = document.getElementById('JabberMessenger');
54                        div_write_msg.parentNode.insertBefore(StatusBarIM, div_write_msg);
55                        StatusBarIM.style.paddingLeft = '33px';
56                        return;                 
57                }
58               
59                if( StatusBar )
60                {
61                        StatusBar.style.paddingLeft = '33px';
62                       
63                        var _div = document.createElement('div');
64                        _div.appendChild(StatusBar.parentNode.removeChild(StatusBar.previousSibling));
65                        StatusBar.parentNode.insertBefore(_div,StatusBar);
66                       
67                        var divJabber = document.createElement('div');
68                                divJabber.setAttribute('id', 'JabberMessenger');
69                       
70                        var _status = top.document.createElement('div');
71                                _status.setAttribute('id', 'jabberit_login');
72                                _status.style.background = 'no-repeat';
73                                _status.style.backgroundImage = 'url(' + jabberit_group_open.src + ')';
74                                _status.style.float = 'left';
75                                _status.style.height = '15px';
76                                _status.style.left = '7px';
77                                _status.style.margin = '8 0 0 10px';
78                                _status.style.padding = '0px';
79                                _status.style.position = 'absolute';
80                                _status.style.width = '15px';
81                                _status.style.cursor = 'pointer';
82
83                        divJabber.insertBefore(_status,divJabber.firstChild);
84
85                        var _menu;
86                                _menu = top.document.createElement('span');
87                                _menu.setAttribute('id','fast_menu_jabberit');
88                                _menu.style.backgroundColor = 'cecece';
89                                _menu.style.display = 'none';
90                                _menu.style.margin = '20px 5px 0px -15px';
91                                _menu.style.position = 'absolute';
92                                _menu.style.zIndex = '99999';
93                                _menu.style.border = '1px dashed #000';
94                               
95                        divJabber.insertBefore(_menu, divJabber.firstChild);
96
97                        var _menu_div = top.document.createElement('div');
98                                _menu_div.setAttribute('id','status_Jabber_Expresso');
99                                _menu_div.style.background = 'no-repeat';
100                                _menu_div.style.backgroundImage = 'url(' + jabberit_add_user.src + ')';
101                                _menu_div.style.float = 'left';
102                                _menu_div.style.height = '18px';
103                                _menu_div.style.left = '19px';
104                                _menu_div.style.margin = '0 0 0 10px';
105                                _menu_div.style.padding = '0px';
106                                _menu_div.style.position = 'absolute';
107                                _menu_div.style.width = '18px';
108                                _menu_div.style.cursor = 'pointer';
109                                _menu_div.style.zindex = '99999999';
110                       
111                        statusJabberExpresso = _menu_div;
112                       
113                        divJabber.insertBefore(_menu_div, divJabber.firstChild);
114                        StatusBar.insertBefore(divJabber, StatusBar.firstChild);                       
115                       
116                        configEvents(_menu_div,'onclick',showWindow);
117
118                        configEvents(
119                                _status,
120                                'onclick',
121                                function()
122                                {
123                                        var _options = [
124                                                ['Add Contacts',addContacts],
125                                                ['Help',helpJabberit],
126                                                ['Preferences', preferences]
127                                        ];
128
129                                        var _style_text = 'cursor: pointer; padding:2px 2px 2px 15px; background: no-repeat url(' + jabberit_group_close.src + ');';                                   
130
131                                        var _xml = _xtools.xml('menu');
132                                        var _option;
133                                        var _item;
134                                        var _action;
135                                        var _style;
136
137                                        for ( var i in _options )
138                                        {
139                                                _option = _xml.createElement('option');
140
141                                                _item = _xml.createElement('item');
142                                                _item.appendChild(_xml.createTextNode(jabberitGetLang(_options[i][0])));
143                                               
144                                                _style = _xml.createElement('style');
145                                                _style.appendChild(_xml.createTextNode(_style_text));
146
147                                                _option.appendChild(_item);
148                                                _option.appendChild(_style);
149
150                                                _xml.documentElement.appendChild(_option);
151                                        }
152
153                                        _menu.innerHTML = _xtools.parse(_xml, 'options.xsl');
154                                        _showhidden.action('onmouseover', 'onmouseout', _menu);
155
156                                        _item = _menu.firstChild;
157
158                                        for ( var i in _options )
159                                        {
160                                                _item.childNodes[i].setAttribute('presence', _options[i]);
161                                                configEvents(
162                                                        _item.childNodes[i],
163                                                        'onclick',
164                                                        _options[i][1]
165                                                );
166                                        }
167                                }
168                        );
169
170
171
172                //
173                }
174        }
175
176        function addContacts()
177        {
178                _ldap.add();
179        }
180
181        function changeLabel()
182        {
183                if( arguments.length > 0 )
184                {
185                        var element = arguments[0].parentNode.parentNode.firstChild;
186
187                        if(arguments[0].checked)
188                                element.innerHTML = "<span style='color:red;'>Digite o Email .: </span>";
189                        else
190                                element.innerHTML = "Nome do Contato .: ";
191                }
192        }
193
194        function configEvents(pObj, pEvent, pHandler)
195        {
196                if ( typeof pObj == 'object' )
197                {
198                        if ( pEvent.substring(0, 2) == 'on' )
199                                pEvent = pEvent.substring(2, pEvent.length);
200
201                        if ( pObj.addEventListener )
202                                pObj.addEventListener(pEvent, pHandler, false);
203                        else if ( pObj.attachEvent )
204                                pObj.attachEvent('on' + pEvent, pHandler);
205                }
206        }
207
208        function closeWindow()
209        {
210                myWindow = '';
211        }
212
213        function getElementStatus()
214        {
215                return document.getElementById('status_Jabber_Expresso');
216        }
217
218        function getPreferences()
219        {
220                if( flagOpenIM == '' )
221                {
222                        _conn.go("$this.db_im.getPreferences",
223                                                function(data)
224                                                {
225                                                        var autoConnect = '';
226                                                        flagOpenIM = data;
227                                                       
228                                                        if( data.indexOf(';') != -1)
229                                                        {
230                                                                var temp = data.split(';');
231                                                                autoConnect = flagOpenIM = temp[0];
232
233                                                                flagOpenPopup = 'openWindowJabberitPopUp:false';
234                                                               
235                                                                if( temp[1] )
236                                                                {
237                                                                        if( temp[1] == 'openWindowJabberitPopUp:true' || temp[1] == 'openWindowJabberitPopUp:false')
238                                                                                flagOpenPopup = temp[1];
239                                                                }
240                                                        }
241                                                        else
242                                                        {
243                                                                autoConnect = flagOpenIM;
244                                                        }
245       
246                                                        if( autoConnect == 'openWindowJabberit:true' )
247                                                        {
248                                                                setTimeout('loadscript.showW();', 2500);
249                                                        }
250                                                });
251                }
252
253        }
254
255        function helpJabberit()
256        {
257                var myWindowHelp = window.open( path_jabberit + 'help.php', 'HelpjabberIM', 'width=800,height=495,top=50,left=50,scrollbars=yes');
258        }
259
260        function keyPressSearch()
261        {
262                var ev = arguments[0];
263                var element = arguments[1];
264
265                if ( ev.keyCode == 13 )
266                        if( element.value.length >= 4 )
267                                _ldap.search( element.value ); 
268                        else
269                                alert(jabberitGetLang('Your search argument must be longer than 4 characters.'));
270        }
271
272        function openPopup()
273        {
274                var widPopup = '220';
275
276                if( is_ie )
277                        widPopup = '250';
278
279                try{
280
281                        if(!myWindow )
282                        {       
283                                myWindow = window.open('','JabberIM','width='+widPopup+',height=400,top=50,left=50,toolbar=0,menubar=0,resizable=0,scrollbars=0,status=0,location=0,titlebar=0');
284                                myWindow.close();
285                                myWindow = window.open(path_jabberit + 'client.php','JabberIM','width='+widPopup+',height=400,top=50,left=50,toolbar=0,menubar=0,resizable=0,scrollbars=0,status=0,location=0,titlebar=0');
286                                myWindow.blur();
287                                configEvents(myWindow,'onbeforeunload', closeWindow );
288                        }
289                        else
290                        {
291                                for( var i = 15 ; i > 0 ; i-- )
292                                {
293                                        myWindow.moveBy(i,0); myWindow.moveBy(-i,0);
294                                }
295                                myWindow.focus();
296                        }
297                }
298                catch(e)
299                {
300                        delete myWindow;
301                        myWindow = window.open(path_jabberit + 'client.php','JabberIM','width='+widPopup+',height=400,top=50,left=50,toolbar=0,menubar=0,resizable=0,scrollbars=0,status=0,location=0,titlebar=0');
302                        myWindow.blur();
303                        configEvents(myWindow,'onbeforeunload', closeWindow );
304                }
305        }
306
307        function openWindow()
308        {
309                var _win_contacts = _window.load('jabberit_contacts');
310
311                var flagOpenAux = '';
312               
313                if( flagOpenIM.indexOf(';') != -1 )
314                {
315                        var aux = flagOpenIM.split(';');
316                        flagOpenAux = aux[0];
317                }
318                else
319                        flagOpenAux = flagOpenIM;
320
321                if( flagOpenAux == 'openWindowJabberit:false' )
322                {
323                        if( !is_ie )
324                                _win_contacts.size(220,400);
325                        else   
326                                _win_contacts.size(250,400);
327                }                                       
328                else
329                {
330                        if( !is_ie )
331                        {
332                                _win_contacts.size(1,1);
333                                _win_contacts.wm.style.visibility = 'hidden';
334                        }
335                        else
336                        {
337                                _win_contacts.size(0,0);
338                        }
339                }
340
341                _win_contacts.bc.style.display = "none";
342                _win_contacts.bx.style.display = "none";
343
344                if( _win_contacts.bz.removeEventListener )
345                        _win_contacts.bz.removeEventListener('click',_win_contacts.button, false);
346                else
347                        _win_contacts.bz.detachEvent('onclick',_win_contacts.button);
348
349                configEvents(
350                        _win_contacts.bz,
351                        "onclick",
352                        function()
353                        {
354                                _win_contacts.size(1,1);
355                                _win_contacts.wm.style.visibility = 'hidden';
356                                _win_contacts.position(50,50);
357                                _win_contacts.title('');
358                        }
359                );
360
361                var _params = {'path' : path_jabberit};
362                _win_contacts.content(_xtools.parse(_xtools.xml('contacts_jabberit'), 'contacts_jabberit.xsl', _params));
363
364                if( flagOpenAux == 'openWindowJabberit:false' )
365                {
366                        if( !is_ie )
367                        {
368                                _win_contacts.wm.style.visibility = "visible";
369                                _win_contacts.size(220,400);
370                                _win_contacts.title('.:: Expresso - JMessenger ::.');
371                        }
372                        else
373                        {
374                                _win_contacts.size(250,400);
375                                _win_contacts.title('.:: Expresso - JMessenger ::.');
376                        }
377                        _win_contacts.position(50,50);
378                }
379                else
380                {
381                        if( !is_ie )
382                                _win_contacts.wm.style.visibility = "hidden";
383                }
384        }
385
386        function openWindowParticipantsExternal()
387        {
388                if( arguments.length > 0)
389                {
390                        var element = arguments[0];
391                        var orgPartExternal = externalParticipantsJabberit.split(",");
392                       
393                        var _splash = top.document.createElement('span');
394                                _splash.setAttribute('id','fast_splash_jabberit');
395                                _splash.style.backgroundColor = 'dedede';
396                                _splash.style.position = 'absolute';
397                                _splash.style.display = 'block';
398                                _splash.style.width = '200px';
399                                _splash.style.height = 'auto';
400                                _splash.style.margin = ( !is_ie ) ? '0px 5px 0px 130px' : '20px 0px 0px 0px';
401                                _splash.style.zIndex = '99999';
402                                _splash.style.border = '2px outset #000';
403                       
404                                for(var i = 0; i < orgPartExternal.length; i++)
405                                        _splash.innerHTML += '<div style="margin:5px;border-bottom:1px dashed #000;cursor:default !important;">' + (i + 1) + " - " + orgPartExternal[i] + '</div>';     
406                               
407                        _showhidden.action('onmouseover', 'onmouseout', _splash);
408                        element.appendChild(_splash);
409                }
410        }
411
412        function preferences()
413        {
414                if( !(_window.get('jabberit_preferences')) )
415                {
416                        var _win_preferences = _window.load('jabberit_preferences');
417                                _win_preferences.size(320,250);
418                                _win_preferences.position(150,100);
419                                _win_preferences.title('.:: Expresso - JMessenger '+jabberitGetLang('Preferences')+'::.');
420                                _win_preferences.bc.style.display = "none";
421                                _win_preferences.bx.style.display = "none";
422                                _win_preferences.wc.style.padding = "5px";                                                             
423
424                        if( _win_preferences.bz.removeEventListener )
425                                _win_preferences.bz.removeEventListener('click',_win_preferences.button, false);
426                        else
427                                _win_preferences.bz.detachEvent('onclick',_win_preferences.button);
428                               
429                        configEvents(
430                                _win_preferences.bz,
431                                "onclick",
432                                function()
433                                {
434                                        _win_preferences.size(1,1);
435                                        _win_preferences.wm.style.visibility = 'hidden';
436                                        _win_preferences.position(50,50);
437                                        _win_preferences.title('');
438                                });
439
440                        var _params = {'path'  : path_jabberit,
441                                                   'lang1' : jabberitGetLang('Your Preferences'),
442                                                   'lang2' : jabberitGetLang('Connection'),     
443                                                   'lang3' : jabberitGetLang('Enable Auto Login IM'),
444                                                   'lang4' : jabberitGetLang('Users OffLine'),
445                                                   'lang5' : jabberitGetLang('Show friends Offline'),
446                                                   'lang6' : jabberitGetLang('Save'),
447                                                   'lang7' : jabberitGetLang('Cancel'),
448                                                   'lang8' : jabberitGetLang('Window'),
449                                                   'lang9' : jabberitGetLang('Open as Pop-Up Window'),                                             
450                                                   'langYes': jabberitGetLang('Yes'),
451                                                   'langNo':  jabberitGetLang('No')                                                                                       
452                                                  };
453                        _win_preferences.content(_xtools.parse(_xtools.xml('preferences_jabberit'), 'preferences_jabberit.xsl', _params));
454                        _win_preferences.wc.lastChild.lastChild.onclick = _win_preferences.close;
455                }
456                else
457                {
458                        var _win_preferences = _window.get('jabberit_preferences');
459                        _win_preferences.wm.style.visibility = "visible";
460                        _win_preferences.position(150,100);                                                     
461                        _win_preferences.title('.:: Expresso - JMessenger '+jabberitGetLang('Preferences')+'::.');
462                        _win_preferences.size(320,250);
463                }
464
465                // Element openWindowJabberit
466                var value1 = flagOpenIM.split(':');
467                var element1 = document.getElementById(value1[0]);
468                var valueSelect1 = value1[1];
469               
470                for(var i = 0; i < element1.options.length; i++)
471                        if( element1.options[i].value == valueSelect1 )
472                                element1.options[i].selected = true;
473
474
475                // Element userOfflineJabberit
476                var value2 = flagOpenPopup.split(':');
477                var element2 = document.getElementById(value2[0]);
478                var valueSelect2 = value2[1];
479                       
480                for(var i = 0; i < element2.options.length; i++)
481                        if( element2.options[i].value == valueSelect2 )
482                                element2.options[i].selected = true;
483               
484        }
485
486        function searchUser()
487        {
488                var element = arguments[0].previousSibling;
489               
490                if( element.value.length >= 4 )
491                        _ldap.search( element.value ); 
492                else
493                        alert(jabberitGetLang('Your search argument must be longer than 4 characters.'));
494        }
495       
496        function setPreferences()
497        {
498                // Element openWindowJabberit
499                var elementOpenW = document.getElementById('openWindowJabberit');
500                var value = '';
501                var flagReload = false;
502               
503                for(var i = 0 ; i < elementOpenW.options.length; i++)
504                        if( elementOpenW.options[i].selected == true)
505                        {
506                                value = 'preferences1=openWindowJabberit:' + elementOpenW.options[i].value;
507                                flagOpenIM = 'openWindowJabberit:' + elementOpenW.options[i].value;
508                        }
509
510                // Element openWindowJabberitPopUp
511                var elementOpenPop = document.getElementById('openWindowJabberitPopUp');       
512
513                for(var i = 0; i < elementOpenPop.options.length; i++ )
514                        if( elementOpenPop.options[i].selected ==  true )
515                        {
516                                value += '&preferences2=openWindowJabberitPopUp:' + elementOpenPop.options[i].value;
517                               
518                                if( flagOpenPopup != 'openWindowJabberitPopUp:' + elementOpenPop.options[i].value)
519                                        flagReload = true;
520                                       
521                                flagOpenPopup = 'openWindowJabberitPopUp:' + elementOpenPop.options[i].value;
522                        }
523                       
524                _conn.go('$this.db_im.setPreferences',
525                                 function(data)
526                                 {
527                                        if(data == 'true')
528                                        {
529                                                if( flagReload )
530                                                {
531                                                        window.location.reload();
532                                                        myWindow.close();                                                       
533                                                }
534                                        }
535                                        else{ alert(jabberitGetLang('Error saving your preferences!')); }
536                                                                               
537                                        var _win_preferences = _window.get('jabberit_preferences');
538                                                _win_preferences.close();
539                                 },
540                                 value);
541        }
542       
543        function showDiv()
544        {
545                var _element = ( myWindow ) ? myWindow.document.body.firstChild : null ;
546                if( _element != null )
547                        _element.style.visibility = 'visible';
548        }
549
550        function showWindow()
551        {
552                var _win_contacts = _window.get('jabberit_contacts');
553               
554                if( flagOpenPopup == 'openWindowJabberitPopUp:true' )
555                {
556                        openPopup();                                   
557                }
558                else
559                {
560                        if ( _win_contacts )
561                        {       
562                                _win_contacts.wm.style.visibility = "visible";
563                                _win_contacts.title('.:: Expresso - JMessenger ::.');
564       
565                                if( !is_ie )
566                                        _win_contacts.size(220,400);
567                                else
568                                        _win_contacts.size(250,400);
569       
570                                _win_contacts.position(60,60);
571                        }
572                        else
573                                openWindow();
574                }
575        }
576
577        function Load()
578        {
579                addIcon();
580                getPreferences();
581        }
582
583        Load.prototype.adIcon   = addIcon;
584        Load.prototype.cLabel   = changeLabel;
585        Load.prototype.closeW   = closeWindow;
586        Load.prototype.getElement       = getElementStatus;
587        Load.prototype.keyPress         = keyPressSearch;
588        Load.prototype.openWinParExt = openWindowParticipantsExternal;
589        Load.prototype.search   = searchUser;
590        Load.prototype.setPrefe = setPreferences;
591        Load.prototype.show             = showDiv;
592        Load.prototype.showW    = showWindow;
593
594        window.loadscript = new Load;
595
596})();
Note: See TracBrowser for help on using the repository browser.