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

Revision 624, 16.7 KB checked in by niltonneto, 16 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 *
RevLine 
[382]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 = '';
[417]8        var flagOpenIM    = '';
[622]9        var flagOpenPopup = '';
[382]10   
[417]11        // Sniffer Browser
[382]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');
[622]36                _jabberit_content = document.body.appendChild(_jabberit_content);
[382]37        }
38
39        var _window = new JITWindows(_xtools, _jabberit_content);
40        var _ldap       = new JITLdap( _conn, _xtools, _window);
41
42        function addIcon()
43        {
[622]44               
45                var StatusBar = document.getElementById('divStatusBar');
46
[439]47                /**
[622]48                 * @quando estiver habilitada a opção fora de escritório nos filtros.
[439]49                 */
50               
[622]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                }
[439]58               
[622]59                if( StatusBar )
[382]60                {
61                        StatusBar.style.paddingLeft = '33px';
[439]62                       
[622]63                        var _div = document.createElement('div');
64                        _div.appendChild(StatusBar.parentNode.removeChild(StatusBar.previousSibling));
65                        StatusBar.parentNode.insertBefore(_div,StatusBar);
66                       
[439]67                        var divJabber = document.createElement('div');
68                                divJabber.setAttribute('id', 'JabberMessenger');
69                       
[382]70                        var _status = top.document.createElement('div');
[439]71                                _status.setAttribute('id', 'jabberit_login');
[382]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
[439]83                        divJabber.insertBefore(_status,divJabber.firstChild);
[382]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';
[439]90                                _menu.style.margin = '20px 5px 0px -15px';
[382]91                                _menu.style.position = 'absolute';
92                                _menu.style.zIndex = '99999';
93                                _menu.style.border = '1px dashed #000';
[439]94                               
95                        divJabber.insertBefore(_menu, divJabber.firstChild);
[382]96
97                        var _menu_div = top.document.createElement('div');
[622]98                                _menu_div.setAttribute('id','status_Jabber_Expresso');
[382]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';
[439]109                                _menu_div.style.zindex = '99999999';
[382]110                       
[622]111                        statusJabberExpresso = _menu_div;
112                       
[439]113                        divJabber.insertBefore(_menu_div, divJabber.firstChild);
114                        StatusBar.insertBefore(divJabber, StatusBar.firstChild);                       
[382]115                       
116                        configEvents(_menu_div,'onclick',showWindow);
117
118                        configEvents(
119                                _status,
120                                'onclick',
121                                function()
122                                {
123                                        var _options = [
124                                                ['Add Contacts',addContacts],
[417]125                                                ['Help',helpJabberit],
126                                                ['Preferences', preferences]
[382]127                                        ];
128
[439]129                                        var _style_text = 'cursor: pointer; padding:2px 2px 2px 15px; background: no-repeat url(' + jabberit_group_close.src + ');';                                   
[382]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                        );
[622]169
170
171
172                //
[382]173                }
174        }
175
176        function addContacts()
177        {
178                _ldap.add();
179        }
180
[551]181        function changeLabel()
182        {
183                if( arguments.length > 0 )
184                {
185                        var element = arguments[0].parentNode.parentNode.firstChild;
186
187                        if(arguments[0].checked)
[560]188                                element.innerHTML = "<span style='color:red;'>Digite o Email .: </span>";
[551]189                        else
[560]190                                element.innerHTML = "Nome do Contato .: ";
[551]191                }
192        }
193
[382]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
[622]213        function getElementStatus()
[382]214        {
[622]215                return document.getElementById('status_Jabber_Expresso');
216        }
217
218        function getPreferences()
219        {
220                if( flagOpenIM == '' )
[382]221                {
[622]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                                                });
[382]251                }
[622]252
[382]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        {
[622]274                var widPopup = '220';
275
276                if( is_ie )
277                        widPopup = '250';
278
[417]279                try{
[624]280
[622]281                        if(!myWindow )
[417]282                        {       
[624]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();
[622]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');
[417]286                                myWindow.blur();
287                                configEvents(myWindow,'onbeforeunload', closeWindow );
[622]288                        }
289                        else
290                        {
291                                for( var i = 15 ; i > 0 ; i-- )
292                                {
293                                        myWindow.moveBy(i,0); myWindow.moveBy(-i,0);
294                                }
[417]295                                myWindow.focus();
[622]296                        }
[417]297                }
298                catch(e)
299                {
300                        delete myWindow;
[622]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');
[417]302                        myWindow.blur();
303                        configEvents(myWindow,'onbeforeunload', closeWindow );
304                }
[382]305        }
306
307        function openWindow()
308        {
309                var _win_contacts = _window.load('jabberit_contacts');
[622]310
[560]311                var flagOpenAux = '';
312               
313                if( flagOpenIM.indexOf(';') != -1 )
[417]314                {
[560]315                        var aux = flagOpenIM.split(';');
316                        flagOpenAux = aux[0];
317                }
318                else
319                        flagOpenAux = flagOpenIM;
[622]320
[560]321                if( flagOpenAux == 'openWindowJabberit:false' )
322                {
[622]323                        if( !is_ie )
324                                _win_contacts.size(220,400);
325                        else   
326                                _win_contacts.size(250,400);
[417]327                }                                       
[551]328                else
329                {
[622]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                        }
[551]339                }
[382]340
[417]341                _win_contacts.bc.style.display = "none";
342                _win_contacts.bx.style.display = "none";
[382]343
[417]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);
[382]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));
[417]363
[560]364                if( flagOpenAux == 'openWindowJabberit:false' )
[417]365                {
[622]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);
[417]378                }
[622]379                else
380                {
381                        if( !is_ie )
382                                _win_contacts.wm.style.visibility = "hidden";
[417]383                }
384        }
385
[560]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
[417]412        function preferences()
413        {
414                if( !(_window.get('jabberit_preferences')) )
415                {
416                        var _win_preferences = _window.load('jabberit_preferences');
[622]417                                _win_preferences.size(320,250);
[417]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,
[560]441                                                   'lang1' : jabberitGetLang('Your Preferences'),
[622]442                                                   'lang2' : jabberitGetLang('Connection'),     
[560]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'),
[622]448                                                   'lang8' : jabberitGetLang('Window'),
449                                                   'lang9' : jabberitGetLang('Open as Pop-Up Window'),                                             
[560]450                                                   'langYes': jabberitGetLang('Yes'),
451                                                   'langNo':  jabberitGetLang('No')                                                                                       
[417]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')+'::.');
[622]462                        _win_preferences.size(320,250);
[417]463                }
464
[622]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;
[417]473
[622]474
475                // Element userOfflineJabberit
476                var value2 = flagOpenPopup.split(':');
477                var element2 = document.getElementById(value2[0]);
478                var valueSelect2 = value2[1];
[560]479                       
[622]480                for(var i = 0; i < element2.options.length; i++)
481                        if( element2.options[i].value == valueSelect2 )
482                                element2.options[i].selected = true;
483               
[417]484        }
485
[382]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        }
[417]495       
496        function setPreferences()
497        {
[560]498                // Element openWindowJabberit
499                var elementOpenW = document.getElementById('openWindowJabberit');
500                var value = '';
[622]501                var flagReload = false;
[417]502               
[560]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;
[622]507                                flagOpenIM = 'openWindowJabberit:' + elementOpenW.options[i].value;
[560]508                        }
509
[622]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 )
[560]515                        {
[622]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                       
[417]524                _conn.go('$this.db_im.setPreferences',
525                                 function(data)
526                                 {
527                                        if(data == 'true')
528                                        {
[622]529                                                if( flagReload )
530                                                {
531                                                        window.location.reload();
[624]532                                                        myWindow.close();                                                       
[622]533                                                }
[417]534                                        }
[622]535                                        else{ alert(jabberitGetLang('Error saving your preferences!')); }
[417]536                                                                               
537                                        var _win_preferences = _window.get('jabberit_preferences');
538                                                _win_preferences.close();
539                                 },
[622]540                                 value);
[417]541        }
542       
[382]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');
[622]553               
554                if( flagOpenPopup == 'openWindowJabberitPopUp:true' )
[382]555                {
[622]556                        openPopup();                                   
557                }
558                else
559                {
[382]560                        if ( _win_contacts )
[551]561                        {       
[382]562                                _win_contacts.wm.style.visibility = "visible";
563                                _win_contacts.title('.:: Expresso - JMessenger ::.');
[622]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);
[382]571                        }
572                        else
573                                openWindow();
574                }
575        }
576
577        function Load()
578        {
579                addIcon();
[417]580                getPreferences();
[382]581        }
582
[560]583        Load.prototype.adIcon   = addIcon;
584        Load.prototype.cLabel   = changeLabel;
585        Load.prototype.closeW   = closeWindow;
[622]586        Load.prototype.getElement       = getElementStatus;
587        Load.prototype.keyPress         = keyPressSearch;
[560]588        Load.prototype.openWinParExt = openWindowParticipantsExternal;
589        Load.prototype.search   = searchUser;
[417]590        Load.prototype.setPrefe = setPreferences;
[560]591        Load.prototype.show             = showDiv;
592        Load.prototype.showW    = showWindow;
593
[382]594        window.loadscript = new Load;
595
[417]596})();
Note: See TracBrowser for help on using the repository browser.