source: sandbox/jabberit_messenger/trophy_expresso/js/jscode/loadIM.js @ 2791

Revision 2791, 34.7 KB checked in by alexandrecorreia, 14 years ago (diff)

Ticket #986 - Implementado os popups para as janelas de conversa e somente para navegadores Firefox.

  • Property svn:executable set to *
Line 
1(function()
2{
3        var _autoStatus;
4        var _autoStatusTime     = 60000; // 1 minuto   
5        var addUser                             = null;
6        var conn                                = null;
7        var fullName                    = "";
8        var path                                = "";
9        var _preferencesIM              = "";
10        var selectEditable              = null;
11        var showhidden                  = null;
12        var _statusMessage              = "";
13        var timeoutId                   = null;
14        var userCurrent                 = null;
15        var Xtools                              = null;
16        var zIndex                              = 9001;
17        var windowPopUp                 = [];
18       
19        // Sniffer Browser
20        var agt = navigator.userAgent.toLowerCase();
21    var is_major = parseInt(navigator.appVersion);
22    var is_minor = parseFloat(navigator.appVersion);   
23    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
24                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
25                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
26    var is_gecko = (agt.indexOf('gecko') != -1);
27    var is_gecko1_5 = (agt.indexOf('firefox/1.5') != -1 || agt.indexOf('firefox/2') != -1 || agt.indexOf('iceweasel/2') != -1);
28    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
29    var is_ie3    = (is_ie && (is_major < 4));
30    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
31    var is_ie4up  = (is_ie && (is_major >= 4));
32    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
33    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
34    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
35    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
36    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
37    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);   
38    var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
39
40        // Images
41        var add_user = new Image();
42        add_user.src = path_jabberit + 'templates/default/images/adduser_azul.png';
43
44        var arrow_down = new Image();
45        arrow_down.src = path_jabberit + 'templates/default/images/arrow_down.gif';
46
47        var arrow_right = new Image();
48        arrow_right.src = path_jabberit + 'templates/default/images/arrow_right.gif';
49       
50        function actionButton()
51        {
52                if( arguments.length > 0 )
53                {
54                        var e                   = arguments[0];
55                        var _element    = ( e.target ) ? e.target : e.srcElement;
56                        var jid         = arguments[1];
57                        var index       = arguments[2];
58                        var coord       = null;
59
60                        if ( !e )
61                                e = window.event;
62
63                        var _X = e.clientX + document.body.scrollLeft - document.body.clientLeft;
64                        var _Y = e.clientY + document.body.scrollTop  - document.body.clientTop;
65                               
66                        coord = { X : _X, Y : _Y };
67               
68
69                        var _onContextMenu = function()
70                        {
71                                return false;
72                        };
73                       
74                        window.document.oncontextmenu   = _onContextMenu;
75                       
76                        if( e.button )
77                        {
78                                if( e.button > 1 )
79                                        optionsItensContact( jid, index, coord );
80                                else
81                                        TrophyIM.rosterClick(jid);
82                        }       
83                        else if( e.which )
84                        {
85                                if( e.which > 1 )
86                                        optionsItensContact( jid, index, coord );
87                                else
88                                        if( e.target.id )
89                                                TrophyIM.rosterClick(jid);
90                        }
91                       
92                        setTimeout(function()
93                        {
94                                window.document.oncontextmenu = function()
95                                {
96                                        return true;
97                                };
98                               
99                        },500);
100                }
101        }
102
103        function addContact()
104        {
105                if( arguments.length > 0 )
106                        addUser.add();
107                else
108                        addUser.show();
109        }
110       
111        function addIcon()
112        {
113               
114                var div_write_msg       = ( getElement('em_div_write_msg') != null ) ? getElement('em_div_write_msg') : null ;
115                var StatusBar           = ( getElement('divStatusBar') != null ) ? getElement('divStatusBar') : null ;
116                var StatusBarIM         = ( getElement('JabberMessenger') != null ) ?  getElement('JabberMessenger') : null;
117               
118                /**************************************************************************
119                 *
120                 * Quando estiver habilitada a opção fora de escritório nos filtros.
121                 * 
122                 */
123
124                if( ( div_write_msg && StatusBarIM ) != null )
125                {               
126                        div_write_msg.parentNode.insertBefore(StatusBarIM, div_write_msg);
127                        StatusBarIM.style.paddingLeft = '33px';
128                        return;
129                }
130               
131                /**************************************************************************/
132               
133                if ( !StatusBarIM )
134                {
135                        StatusBarIM = document.createElement('div');
136                        StatusBarIM.setAttribute('id', 'JabberMessenger');
137                }
138               
139                if( StatusBar )
140                {
141                        StatusBar.style.paddingLeft = '33px';
142                       
143                        var _div = document.createElement('div');
144                                _div.appendChild(StatusBar.parentNode.removeChild(StatusBar.previousSibling));
145                       
146                                StatusBar.parentNode.insertBefore( _div, StatusBar);
147                       
148                        var _fastMenu = top.document.createElement('div');
149                                _fastMenu.setAttribute('id', 'fast_menu_jabber_expresso');
150                                _fastMenu.style.background              = 'no-repeat';
151                                _fastMenu.style.backgroundImage = 'url(' + arrow_down.src + ')';
152                                _fastMenu.style.float                   = 'left';
153                                _fastMenu.style.height                  = '15px';
154                                _fastMenu.style.left                    = '7px';
155                                _fastMenu.style.margin                  = '8 0 0 10px';
156                                _fastMenu.style.padding                 = '0px';
157                                _fastMenu.style.position                = 'absolute';
158                                _fastMenu.style.width                   = '15px';
159                                _fastMenu.style.cursor                  = 'pointer';
160
161                        StatusBarIM.insertBefore( _fastMenu, StatusBarIM.firstChild );
162                       
163                        // Add event onclick element _fastMenu
164                        configEvents( _fastMenu, 'onclick', function(){ fastMenu(_fastMenu); });
165
166                        var _statusJabber = top.document.createElement('div');
167                                _statusJabber.setAttribute('id','status_jabber_expresso');
168                                _statusJabber.style.background          = 'no-repeat';
169                                _statusJabber.style.backgroundImage = 'url(' + add_user.src +')';
170                                _statusJabber.style.float                       = 'left';
171                                _statusJabber.style.height                      = '18px';
172                                _statusJabber.style.left                        = '19px';
173                                _statusJabber.style.margin                      = '0 0 0 10px';
174                                _statusJabber.style.padding                     = '0px';
175                                _statusJabber.style.position            = 'absolute';
176                                _statusJabber.style.width                       = '18px';
177                                _statusJabber.style.cursor                      = 'pointer';
178                                _statusJabber.style.zindex                      = '999999';
179                       
180                        StatusBarIM.insertBefore( _statusJabber, StatusBarIM.firstChild );
181                       
182                        StatusBar.insertBefore( StatusBarIM, StatusBar.firstChild );
183
184                        // Add event onclick element _statusJabber
185                        configEvents( _statusJabber, 'onclick', function(){ TrophyIM.load();});
186                }
187        }
188
189        function autoStatus()
190        {
191                var _div_status = ( getElement('status_jabber_expresso') != null ) ?  getElement('status_jabber_expresso') : null;
192               
193                if ( _autoStatus )
194                        clearTimeout(_autoStatus);
195
196                if ( _div_status != null )
197                {
198                        var _status = _div_status.style.backgroundImage;
199                                _status = _status.substr(_status.lastIndexOf('/') + 1);
200                                _status = _status.substr(0, _status.indexOf('.'));
201                               
202                        if( _status == "xa" && _div_status.getAttribute('autoStatus') )
203                        {
204                                if( getStatusMessage() != "")
205                                        TrophyIM.setPresence("available", getStatusMessage());
206                                else
207                                        TrophyIM.setPresence("available");
208                               
209                                _div_status.removeAttribute('autoStatus');
210                                loadscript.setStatusJabber("Disponível","available");
211                        }
212                }
213               
214                var TimeStatus = _preferencesIM[2].split(':');
215
216                if( TimeStatus[1] )
217                        _autoStatus = setTimeout( function(){ autoStatusHandler();}, parseInt(TimeStatus[1]) * _autoStatusTime );
218                else
219                        _autoStatus = setTimeout( function(){ autoStatusHandler();}, parseInt(_autoStatusTime));
220        }
221       
222        function autoStatusHandler()
223        {
224                var _div_status = ( getElement('status_jabber_expresso') != null ) ?  getElement('status_jabber_expresso') : null;
225               
226                if ( _div_status != null )
227                {
228                        var _status = _div_status.style.backgroundImage;
229                                _status = _status.substr(_status.lastIndexOf('/') + 1);
230                                _status = _status.substr(0, _status.indexOf('.'));
231                       
232                        if( _status == "available" )
233                        {
234                                if(getStatusMessage() != "")
235                                        TrophyIM.setPresence("xa", getStatusMessage());
236                                else
237                                        TrophyIM.setPresence("xa");
238
239                                _div_status.setAttribute('autoStatus','true');
240                                loadscript.setStatusJabber("Não Disponível","xa");
241                        }
242                }
243        }
244
245        function clrAllContacts()
246        {
247                getElement("JabberIMRoster").innerHTML = "";
248        }
249       
250        function configEvents(pObj, pEvent, pHandler)
251        {
252                if ( typeof pObj == 'object' )
253                {
254                        if ( pEvent.substring(0, 2) == 'on' )
255                                pEvent = pEvent.substring(2, pEvent.length );
256
257                        if ( arguments.length == 3 )
258                        {
259                                if ( pObj.addEventListener )
260                                        pObj.addEventListener(pEvent, pHandler, false );
261                                else if ( pObj.attachEvent )
262                                        pObj.attachEvent( 'on' + pEvent, pHandler );
263                        }
264                        else if ( arguments.length == 4 )
265                        {
266                                if ( pObj.removeEventListener )
267                                        pObj.removeEventListener( pEvent, pHandler, false );
268                                else if ( pObj.detachEvent )
269                                        pObj.detachEvent( 'on' + pEvent, pHandler );
270                        }
271                }
272        }
273       
274        function fastMenu()
275        {
276                if( arguments.length > 0 )
277                {
278                        var element = arguments[0];
279
280                        if( showhidden == null )
281                                showhidden = new ShowHidden(300);
282
283                        var _options = [
284                                                ['Adicionar Contato', 'loadscript.addContact();' ],
285                                                ['Ajuda', 'alert("2")' ],
286                                                ['Preferências', 'loadscript.preferences();'],
287                                                   ];
288
289                        var _itens = "";
290                       
291                        for( var i in _options )
292                        {
293                                if( _options[i].constructor == Function )
294                                        continue;
295                               
296                                _itens += '<img src="'+arrow_right.src+'"/>';
297                                _itens += '<span style="cursor:pointer; margin:3px;" onclick='+_options[i][1]+'>';
298                                _itens += _options[i][0] + '</span><br/>';
299                        }
300                       
301                        var _optionsItens = document.createElement("div");
302                                _optionsItens.id        = "fastMenu_Jabber";                           
303                                _optionsItens.style.marginTop   = "19px";
304                                _optionsItens.style.marginLeft  = "-8px";
305                                _optionsItens.className         = "x-menu";
306                                _optionsItens.style.zIndex      = '999999';
307                                _optionsItens.innerHTML         = _itens;
308                                _optionsItens.onclick           = function(){ showhidden.hiddenObject(false); };
309                                _optionsItens.onmouseout        = function(){ showhidden.hiddenObject(false); };
310                                _optionsItens.onmouseover       = function(){ showhidden.hiddenObject(true); };
311                                                                                 
312                                showhidden.action('onmouseover', 'onmouseout', _optionsItens);
313                               
314                        element.parentNode.appendChild( _optionsItens );
315                }
316        }
317       
318        function getElement( elementId )
319        {
320                return document.getElementById( elementId );
321        }
322       
323        function getIsIE()
324        {
325                return is_ie;
326        }
327       
328        function getPhotoUser( jid )
329        {
330                try
331                {
332                var _divPhoto = getElement( jid + '__photo' );
333
334                if( _divPhoto.style.backgroundImage.indexOf('photo.png') > 0 )
335                {
336                        var _imgUser  = path_jabberit + 'inc/WebService.php?' + Date.parse( new Date );
337                                _imgUser += '&photo_ldap=' + jid;
338
339                        _divPhoto.style.backgroundImage = 'url(' + _imgUser + ')';
340                }
341                }
342                catch(e)
343                {}
344        }
345       
346        function getStatusMessage()
347        {
348                return _statusMessage;
349        }
350       
351        function getShowContactsOffline()
352        {
353                if( _preferencesIM[3] )
354                {
355                        var showOffline = _preferencesIM[3].split(":");
356                       
357                        if( showOffline[1] === "true")
358                                return true;
359                        else
360                                return false;
361                }
362               
363                return true;
364        }
365
366        function getUserCurrent()
367        {
368                return userCurrent;
369        }
370       
371        function getZindex()
372        {
373                return zIndex++;
374        }
375       
376        function groupsHidden()
377        {
378                if( arguments.length > 0 )
379                {
380                        var _element = arguments[0];
381                                _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_right.gif') no-repeat center left";
382                                _element.onclick = function(){ groupsVisible(_element);};
383                               
384                                // Hidden all
385                                var _elementNext = _element.nextSibling;
386                               
387                                while( _elementNext )
388                                {       
389                                        if( _elementNext.nodeType == 1 )
390                                                _elementNext.style.display = "none";
391                                       
392                                        _elementNext = _elementNext.nextSibling;
393                                }
394                }
395        }
396       
397        function groupsVisible()
398        {
399                if( arguments.length > 0 )
400                {
401                        var _element = arguments[0];
402                                _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_down.gif') no-repeat center left";
403                                _element.onclick = function(){ groupsHidden(_element);};
404
405                                // Display all
406                                var _elementNext = _element.nextSibling;
407                               
408                                while( _elementNext )
409                                {       
410                                        if( _elementNext.nodeType == 1 && _elementNext.nodeName.toLowerCase() == "div" )
411                                        {
412                                                var is_off = _elementNext.style.backgroundImage.indexOf("unavailable");
413
414                                                if( is_off > 0 && !getShowContactsOffline())
415                                                {
416                                                        _elementNext.style.display = "none";
417                                                        getElement("span_show_" + _elementNext.id ).style.display = "none";
418                                                       
419                                                }
420                                                else
421                                                {
422                                                        _elementNext.style.display = "block";
423                                                        getElement("span_show_" + _elementNext.id ).style.display = "block";
424                                                }
425                                        }
426
427                                        _elementNext = _elementNext.nextSibling;
428                                }
429                }
430        }
431       
432        function keyPressSearch()
433        {
434                if( arguments.length > 0 )
435                {
436                        var ev          = arguments[0];
437                        var element     = arguments[1];
438       
439                        if ( ev.keyCode == 13 )
440                                if( element.value.length >= 3 )
441                                        searchUser( element.value );   
442                                else
443                                        alert('Your search argument must be longer than 3 characters.');
444                }
445        }
446
447       
448        function loginPage()
449        {
450                var paramsLoginPage =
451                {
452                        'username' : ((( Base64.decode(getUserCurrent().jid) )) ? Base64.decode(getUserCurrent().jid) : ""),
453                        'password' : ((( Base64.decode(getUserCurrent().password) )) ? Base64.decode(getUserCurrent().password) : "")
454                }
455               
456                var winLoginPage =
457                {       
458                         id_window              : "window_login_page",
459                         width                  : 260,
460                         height                 : 120,
461                         top                    : 100,
462                         left                   : 400,
463                         draggable              : true,
464                         visible                : "display",
465                         resizable              : true,
466                         zindex                 : zIndex++,
467                         title                  : "Expresso Messenger - Login",
468                         closeAction    : "remove",
469                         content                : Xtools.parse(Xtools.xml("login_page"), "loginPage.xsl", paramsLoginPage)     
470                };
471
472                _winBuild( winLoginPage );
473        }
474
475        function loadScripts(pFiles)
476        {
477                // Load JavaScript
478                var loadJavaScript = function(pJs)
479                {
480                        var newScript = document.createElement("script");
481                                newScript.setAttribute("type", "text/javascript");
482                                newScript.setAttribute("src", pJs );
483                               
484                        return newScript;
485                };
486               
487                // Load CSS
488                var loadStyleSheet = function(pCss)
489                {
490                        var newStyle = document.createElement("link");
491                                newStyle.setAttribute("rel", "stylesheet");
492                                newStyle.setAttribute("type", "text/css");
493                                newStyle.setAttribute("href", pCss);
494                               
495                        return newStyle;
496                };
497               
498                for(var i = 0; i < pFiles.length; i++)
499                {
500                        if( pFiles[i].indexOf(".js") > -1 )
501                                document.getElementsByTagName("head")[0].appendChild(loadJavaScript(pFiles[i]));
502                               
503                        if( pFiles[i].indexOf(".css") > -1 )
504                                document.getElementsByTagName("head")[0].appendChild(loadStyleSheet(pFiles[i]));
505                }
506        }
507       
508        function notificationNewMessage()
509        {
510                var _doc                = document;
511                var _id                 = arguments[0];
512                var _win_name   = _id.replace( /\W/g, '' );
513               
514                if ( windowPOPUP( _id ) )
515                {
516                        _doc = windowPopUp[_win_name].document;
517                }
518               
519                var oldTitle    = _doc.title;
520                var newTitle    = "## NOVA MENSAGEM ##";
521
522                if( timeoutId == null )
523                {
524                        timeoutId = setInterval(function()
525                        {
526                                _doc.title = ( _doc.title == newTitle ) ? oldTitle : newTitle;
527                        }, 1000);
528                       
529                        configEvents( _doc, 'onclick', function()
530                        {
531                                clearInterval(timeoutId);
532                                _doc.title      = oldTitle;
533                                timeoutId               = null;
534                        });
535                       
536                        configEvents( _doc, 'onkeypress', function()
537                        {
538                                clearInterval(timeoutId);
539                                _doc.title      = oldTitle;
540                                timeoutId               = null;
541                        });
542                }
543        }
544
545        function optionsItensContact()
546        {
547                if( arguments.length > 0 )
548                {
549                        var jid         = arguments[0];
550                        var index       = arguments[1];
551                        var coord       = arguments[2];
552                        var element = getElement('itenContact_' + jid + '_' + index );
553                        var action      = ( element.getAttribute("subscription") === "not-in-roster" ) ? "Adicionar" : "Autorizar";     
554                       
555                        if( showhidden == null )
556                                showhidden = new ShowHidden(300);
557
558                        var _options = [
559                                                [ action , 'loadscript.setAutorization(\''+jid+'\',\''+index+'\')'],
560                                                ['Remover' , 'loadscript.removeContact(\''+jid+'\',\''+index+'\')'],
561                                                ['Renomear' , 'loadscript.renameContact(\''+jid+'\',\''+index+'\')'],
562                                                ['Trocar grupo' , 'loadscript.renameGroup(\''+jid+'\',\''+index+'\')']
563                                                   ];
564
565                        var _itens = "";
566                       
567                        for( var i in _options )
568                        {
569                                if( typeof(_options[i]) == "object")
570                                {
571                                        _itens += '<img src="'+arrow_right.src+'"/>';
572                                        _itens += '<span style="cursor:pointer;margin:3px;font-weight:normal;" onclick='+_options[i][1]+'>';
573                                        _itens += _options[i][0] + '</span><br/>';
574                                }
575                        }
576                       
577                        var _optionsItens = document.createElement("div");
578                                _optionsItens.className         = "x-menu";
579                                _optionsItens.style.top         = coord.Y;
580                                _optionsItens.style.left        = ( coord.X - element.offsetLeft );
581                                _optionsItens.style.zIndex      = getZindex();
582                                _optionsItens.innerHTML         = _itens; 
583                                _optionsItens.onclick           = function(){ showhidden.hiddenObject(false); };
584                                _optionsItens.onmouseout        = function(){ showhidden.hiddenObject(false); };       
585                                _optionsItens.onmouseover       = function(){ showhidden.hiddenObject(true); };
586                               
587                                showhidden.action('onmouseover', 'onmouseout', _optionsItens);
588                               
589                        window.document.body.appendChild(_optionsItens);
590                }
591        }
592
593        function parse()
594        {
595                if( arguments.length == 2 )
596                        return Xtools.parse(Xtools.xml(arguments[0]), arguments[1] );
597               
598                if( arguments.length === 3 )
599                        return Xtools.parse(Xtools.xml(arguments[0]), arguments[1], arguments[2] );
600        }
601       
602        function preferences()
603        {
604                var paramPreferences =
605                {
606                        'path'  : path,
607                        'lang1' : 'Suas Preferências',
608                        'lang2' : 'Conexão',   
609                        'lang3' : 'Conectar Automaticamente o IM',
610                        'lang4' : 'Usuários OffLine',
611                        'lang5' : 'Exibir amigos Offline',
612                        'lang6' : 'Salvar',
613                        'lang7' : 'Cancelar',
614                        'lang8' : 'Janela de Contatos',
615                        'lang9' : 'Abrir janela como Pop-up',
616                        'lang10' : 'Ausente',
617                        'lang11' : 'Definir status de ausente depois de',
618                        'lang12' : 'minutos',   
619                        'lang13' : 'Mostrar Contatos', 
620                        'lang14' : 'Mostrar contatos desconectados',
621                        'langYes': 'Sim',
622                        'langNo' : 'Não'                                                                                           
623                };
624               
625               
626                var _win_preferences =
627                {
628                                id_window        : "jabberit_preferences",
629                                width            : 430,
630                                height           : 410,
631                                top                      : 150,
632                                left             : 100,
633                                draggable        : true,
634                                visible          : "display",
635                                resizable        : true,
636                                zindex           : zIndex++,
637                                title            : 'Expresso Messenger - Preferências',
638                                closeAction  : "remove",
639                                content          : Xtools.parse(Xtools.xml('preferences'), 'preferences.xsl', paramPreferences)
640                };
641
642                _winBuild(_win_preferences);
643               
644               
645                var _pButtons = {
646                                'lang1' : 'Salvar',
647                                'lang2' : 'Fechar',
648                                'onclickClose' : '_winBuild("jabberit_preferences","remove");',
649                                'onclickSubmit' : 'javascript:loadscript.setPreferences();'
650                };
651               
652                document.getElementById('buttons_preferences_jabberit').innerHTML = Xtools.parse(Xtools.xml('buttons_main'), 'buttons.xsl', _pButtons);
653               
654                // Element openWindowJabberit
655                var value1                      = _preferencesIM[0].split(':');
656                var element1            = document.getElementById(value1[0]);
657                var valueSelect1        = value1[1];
658               
659                for(var i = 0; i < element1.options.length; i++)
660                        if( element1.options[i].value == valueSelect1 )
661                                element1.options[i].selected = true;
662
663                // Element openWindowJabberitPopUp
664                var value2                      = _preferencesIM[1].split(':');
665                var element2            = document.getElementById(value2[0]);
666                var valueSelect2        = value2[1];
667                       
668                for(var i = 0; i < element2.options.length; i++)
669                        if( element2.options[i].value == valueSelect2 )
670                                element2.options[i].selected = true;
671
672                // Element flagAwayIM
673                var value3              = _preferencesIM[2].split(':');
674                var element3    = document.getElementById(value3[0]);
675                element3.value  = value3[1];
676               
677                // Element showContactsOfflineJabberit
678                var value4                      = _preferencesIM[3].split(':');
679                var element4            = document.getElementById(value4[0]);
680                var valueSelect4        = value4[1];
681                for(var i = 0; i < element4.options.length; i++)
682                        if( element4.options[i].value == valueSelect4 )
683                                element4.options[i].selected = true;
684        }
685       
686        function removeContact(jid, index)
687        {
688                setTimeout(function()
689                {
690                        TrophyIM.removeContact(jid, index);
691                       
692                },300);
693        }
694       
695        function removeElement( )
696        {
697                if( arguments.length > 0 )
698                {
699                        var _element = arguments[0]
700                        var _parent  = _element.parentNode;
701       
702                        _parent.removeChild( _element );
703                }
704        }
705       
706        function removeGroup()
707        {
708                var _parent = arguments[0];
709               
710                if( _parent.childNodes.length <= 2 )
711                        _parent.parentNode.removeChild(_parent);
712        }
713       
714        function renameContact()
715        {
716                if( arguments.length > 0 )
717                {
718                        var _jid        = arguments[0];
719                        var _index      = arguments[1];
720                       
721                        TrophyIM.renameContact( _jid, _index );
722                }
723        }
724       
725        function renameGroup()
726        {
727                if( arguments.length > 0 )
728                {
729                        var _jid        = arguments[0];
730                        var _index      = arguments[1];
731                       
732                        TrophyIM.renameGroup( _jid , _index );
733                }
734        }
735       
736        function rosterDiv()
737        {
738                var _rosterDiv = function()
739                {
740                        var _popUp      = (_preferencesIM[1]).split(":");
741                        var _idUser     = Base64.decode(getUserCurrent().jid);
742                       
743                        var paramListContact =
744                        {
745                                'idUser'                : _idUser,
746                                'full_name'             : (( fullName.length < 25 ) ? fullName : ( fullName.substring( 0, 25) + "...")),
747                                'path_jabberit' : path_jabberit,
748                                'zIndex_'               : zIndex++
749                        };
750       
751                        var winRosterDiv =
752                        {
753                                 id_window              : "window_Roster_im",
754                                 width                  : 250,
755                                 height                 : 410,
756                                 top                    : 50,
757                                 left                   : -1500,
758                                 leftOld                : 50,
759                                 draggable              : true,
760                                 visible                : "display",
761                                 resizable              : true,
762                                 zindex                 : zIndex++,
763                                 title                  : "Expresso Messenger - Contatos",
764                                 closeAction    : "hidden",
765                                 content                : Xtools.parse(Xtools.xml("contacts_list"),"contactsList.xsl", paramListContact)       
766                        };
767                       
768                        if( _preferencesIM[0] == "openWindowJabberit:false" )
769                        {
770                                winRosterDiv.left               = 50;
771                                winRosterDiv.leftOld    = -1500;
772                        }
773                               
774                        _winBuild( winRosterDiv );
775                       
776                        // Photo User
777                        getPhotoUser(_idUser);
778                       
779                }
780               
781                setTimeout( function(){ _rosterDiv(); }, 550 );
782        }
783
784        function searchUser()
785        {
786                var _input      = getElement('search_user_jabber');
787               
788                if( _input.value.length >= 3 )
789                        addUser.search();
790                else
791                        alert('Your search argument must be longer than 3 characters.');
792        }
793       
794        function setAutorization(jidTo, indexTo)
795        {
796        var divItenContact = null;
797       
798        if( ( divItenContact = getElement('itenContact_' + jidTo + '_' + indexTo )))
799        {       
800                var subscription = divItenContact.getAttribute('subscription');
801               
802                switch(subscription)
803                {
804                        case 'from':
805                               
806                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribe');
807                                break;
808
809                        case 'none' :
810                       
811                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribe');
812                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribed');
813                               
814                                break;
815
816                        case 'not-in-roster':
817                                       
818                                setTimeout(function()
819                                        {
820                                        var _add = "";
821                               
822                                        if( ( _add = confirm("Deseja adicionar o usuario!")) )         
823                                        {
824                                                addUser.add( jidTo, indexTo );
825                                        }
826                                       
827                                        },100);
828                               
829                                        break;
830                                       
831                        case 'to' :
832                               
833                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribed');
834                                       
835                        case 'subscribe' :
836                               
837                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribe');
838                               
839                                        break;
840                }
841        }       
842        }
843       
844        function setMessageStatus()
845        {
846                if( arguments.length > 0 )
847                {
848                        var _element = arguments[0];
849                        var _parent      = _element.parentNode;                 
850
851                        if( _element.nodeName.toLowerCase() == "label")
852                        {
853                                var _input                              = document.createElement("input");
854                                        _input.size                     = "35";
855                                        _input.maxlength        = "35";
856                                        _input.style.border = "0";
857                                        _input.value            = _element.innerHTML;
858                                       
859                                // OnkeyUp
860                                configEvents( _input, "onkeyup", function(e)
861                                                {
862                                                        if( e.keyCode == 13 ) loadscript.setMessageStatus(_input, _element);
863                                                }
864                                );
865                               
866                                // Onblur       
867                            configEvents(_input, "onblur", function(){ loadscript.setMessageStatus(_input, _element)});         
868
869                           
870                                if( _parent != null )
871                                {       
872                                        // Remove label
873                                        if( _element != null )
874                                                _parent.removeChild( _element );
875                                               
876                                        // Add Input
877                                        if( _input != null )
878                                                _parent.appendChild( _input );
879                                }
880
881                                _input.focus();
882                                _input.select();
883                        }
884                        else
885                        {
886                                var _label              = arguments[1];
887                                _statusMessage  = _element.value.replace(/^\(+|\)+$/g,"");
888                               
889                                if( ( _statusMessage = _statusMessage.replace(/^\s+|\s+$|^\n|\n$/g,"") ) != "")
890                                        _label.innerHTML = "( " + _statusMessage + " )";
891                                else
892                                        _label.innerHTML = "( Digite aqui sua mensagem de Status )";
893                               
894                                if( _parent != null )
895                                {       
896                                        // Remove Input
897                                        if( _element != null )
898                                                _parent.removeChild( _element );
899                                               
900                                        // Add Label
901                                        if( _label != null )
902                                                _parent.appendChild( _label );
903                                }
904                               
905                                // Send Status Message
906                                _statusMessage = ( ( _statusMessage !=  "Digite aqui sua mensagem de Status") ? _statusMessage : "" );                         
907                               
908                                TrophyIM.setPresence("status", _statusMessage );
909                        }       
910                }
911        }
912       
913        function setPreferences()
914        {
915                // Element openWindowJabberit
916                var elementOpenW        = document.getElementById('openWindowJabberit');
917                var value                       = '';
918                var flagReload          = false;
919               
920                for(var i = 0 ; i < elementOpenW.options.length; i++)
921                        if( elementOpenW.options[i].selected == true)
922                        {
923                                value = 'preferences1=openWindowJabberit:' + elementOpenW.options[i].value;
924                                _preferencesIM[0] = 'openWindowJabberit:' + elementOpenW.options[i].value;
925                        }
926
927                // Element openWindowJabberitPopUp
928                var elementOpenPop = document.getElementById('openWindowJabberitPopUp');       
929
930                for(var i = 0; i < elementOpenPop.options.length; i++ )
931                        if( elementOpenPop.options[i].selected ==  true )
932                        {
933                                value += '&preferences2=openWindowJabberitPopUp:' + elementOpenPop.options[i].value;
934                               
935                                if( _preferencesIM[1] != 'openWindowJabberitPopUp:' + elementOpenPop.options[i].value)
936                                        flagReload = true;
937                                       
938                                _preferencesIM[1] = 'openWindowJabberitPopUp:' + elementOpenPop.options[i].value;
939                        }
940               
941                // Element flagAwayIM
942                var elementFlagIM = document.getElementById('flagAwayIM');
943               
944                if( elementFlagIM.value.length > 0 && parseInt(elementFlagIM.value) > 0 )
945                {
946                        _preferencesIM[2] = 'flagAwayIM:' + elementFlagIM.value;
947                        value += '&preferences3=flagAwayIM:' + elementFlagIM.value;
948                }
949                else
950                {
951                        alert('Informe um valor igual ou maior que 1!');
952                        return false;
953                }
954
955                // Element showContactsOfflineJabberit
956                var elementShowOffline  = document.getElementById('showContactsOfflineJabberit');
957               
958                for(var i = 0 ; i < elementShowOffline.options.length; i++)
959                        if( elementShowOffline.options[i].selected == true)
960                        {
961                                _preferencesIM[3] = 'showContactsOfflineJabberit:' + elementShowOffline.options[i].value;
962                                value += '&preferences4=showContactsOfflineJabberit:' + elementShowOffline.options[i].value;
963                        }
964
965                // Save Preferences
966                conn.go('p.pf.setPreferences',
967                                 function(data)
968                                 {
969                                        if(data == 'true')
970                                        {
971                                                if( flagReload )
972                                                {
973                                                        window.location.reload();
974                                                        myWindow.close();                                                       
975                                                }
976                                        }
977                                        else{ alert('Erro salvando suas preferências!'); }
978
979                                        _winBuild('jabberit_preferences', 'remove');
980                                 },
981                                 value);
982        }
983       
984        function setPresence()
985        {
986                if( arguments.length > 0 )
987                {
988                        var element = arguments[0];
989                       
990                        if( showhidden == null )
991                                showhidden = new ShowHidden(300);
992                       
993                        var _status = [
994                                               ['Afastado', 'away', '<img src="'+path_jabberit+'templates/default/images/away.gif" />'],
995                                               ['Disponível', 'available', '<img src="'+path_jabberit+'templates/default/images/available.gif" />'],
996                                               ['Livre p/ Conversa', 'chat', '<img src="'+path_jabberit+'templates/default/images/chat.gif" />'],
997                                               ['Não Disponível', 'xa', '<img src="'+path_jabberit+'templates/default/images/xa.gif" />'],
998                                               ['Ocupado', 'dnd', '<img src="'+path_jabberit+'templates/default/images/dnd.gif" />'],
999                                               ['Desconectado', 'unavailable', '<img src="'+path_jabberit+'templates/default/images/unavailable.gif" />'],
1000                                               ['Mensagem de Status...', 'status', '<img src="'+path_jabberit+'templates/default/images/message_normal.gif" />'],                                               
1001                                          ];
1002                       
1003                        var _itens = "";
1004                       
1005                        for( var i in _status )
1006                        {
1007                                if( typeof( _status[i]) == "object" )
1008                                {
1009                                        _itens += '<span style="cursor:pointer;" onclick="TrophyIM.setPresence(\''+_status[i][1]+'\'); loadscript.setStatusJabber(\''+_status[i][0]+'\',\''+_status[i][1]+'\');">';
1010                                        _itens += _status[i][2]+ "<span style='margin:3px;'>" + _status[i][0] + "</span></span><br/>";
1011                                }
1012                        }
1013                       
1014                        var _statusItens = document.createElement("div");
1015                                _statusItens.style.marginTop    = "65px";
1016                                _statusItens.style.marginLeft   = "67px";
1017                                _statusItens.className                  = "x-menu";
1018                                _statusItens.style.zIndex               = '99999';
1019                                _statusItens.innerHTML                  = _itens; 
1020                                _statusItens.onclick                    = function(){ showhidden.hiddenObject(false); };
1021                                                                                 
1022                                showhidden.action('onmouseover', 'onmouseout', _statusItens);
1023                               
1024                        element.parentNode.onmouseout   = function(){ showhidden.hiddenObject(false); };
1025                        element.parentNode.onmouseover  = function(){ showhidden.hiddenObject(true); };
1026                        element.parentNode.appendChild(_statusItens);
1027                }
1028        }
1029
1030        function setSelectEditable(element)
1031        {
1032                if( getElement('selectBox0') == null )
1033                        selectEditable.create(element);
1034        }
1035
1036        function setStatusJabber()
1037        {
1038                if( arguments.length > 0 )
1039                {
1040                        if( arguments[1] != 'status' )
1041                        {
1042                                var _text       = arguments[0];
1043                                var _img        = arguments[1];
1044
1045                                getElement('statusJabberText').innerHTML                = _text;
1046                                getElement('statusJabberImg').style.background  = "url('"+path_jabberit+"templates/default/images/"+_img+".gif')";
1047                                getElement('status_jabber_expresso').style.background = "url('"+path_jabberit+"templates/default/images/"+_img+".gif') no-repeat";
1048                        }
1049                }       
1050        }
1051
1052        function _setUserCurrent( _jid, _password )
1053        {
1054                userCurrent =
1055                {
1056                        'jid'           : _jid.substring(11, _jid.length),
1057                        'password'      : _password.substring(11, _password.length)
1058                }               
1059        }
1060       
1061        function setUserCurrent()
1062        {
1063                if( getUserCurrent() == null )
1064                {
1065                        conn.go('p.ff.data_0',
1066                                                function(_User)
1067                                                {
1068                                                        var _user = _User;
1069                                                       
1070                                                        conn.go('p.ff.data_1',
1071                                                                        function(_pass)
1072                                                                        {
1073                                                                                _setUserCurrent( _user, _pass );
1074                                                                        });
1075                                                });
1076                }
1077        }
1078
1079        var _stylesheets = [ ];
1080        var _links = document.getElementsByTagName( 'link' );
1081       
1082        for ( var i = 0; i < _links.length; i++ )
1083                if ( _links.item( i ).type && _links.item( i ).type.toLowerCase( ) == 'text/css' )
1084                        _stylesheets[ _stylesheets.length ] = _links.item( i ); 
1085       
1086        function windowPOPUP()
1087        {
1088                var _id = arguments[0];
1089                var _win_name = _id.replace( /\W/g, '' );
1090
1091                if ( arguments.length == 1 )
1092                {
1093                        if ( windowPopUp[_win_name] )
1094                                return true;
1095                        else
1096                                return false;
1097                }
1098               
1099                if( arguments.length == 2 )
1100                {       
1101                        if( !windowPopUp[_win_name] )
1102                        {
1103                                windowPopUp[_win_name] = window.open( '', _win_name + '__popup', 'height=355,width=380,top=50,left=50,toolbar=no,menubar=no,resizable=no,scrollbars=no,status=no,location=no,titlebar=no');
1104                                var tmp = windowPopUp[_win_name].document;
1105                               
1106                                tmp.write('<html><head>');
1107                                tmp.write('</head><body>');
1108                                tmp.write('</body></html>');
1109                                tmp.close();
1110                               
1111                                for ( var i = 0; i < _stylesheets.length; i++ )
1112                                        tmp.documentElement.getElementsByTagName( 'head' ).item(0).appendChild( _stylesheets[ i ].cloneNode( true ) );
1113
1114                                var divPOP = getElement( _id + "__popUp" );
1115                                        divPOP.style.background = "url('"+path_jabberit+"templates/default/images/icon_down.png') no-repeat";
1116                                        divPOP.innerHTML = "PopIn";
1117                                       
1118                                function _close( )
1119                                {
1120                                        windowPopUp[_win_name].close();
1121                                        configEvents( divPOP ,'onclick', _close, true );
1122                                }
1123                                       
1124                                configEvents( divPOP ,'onclick', _close );
1125
1126                                var _content = tmp.documentElement.getElementsByTagName( 'body' ).item(0).appendChild( getElement(_id + '__chatBox' ).parentNode );
1127
1128                                _content.firstChild.scrollTop = _content.firstChild.scrollHeight;
1129
1130                                configEvents( windowPopUp[_win_name] ,'onbeforeunload', function()
1131                                {
1132                                        delete windowPopUp[_win_name];
1133                                        divPOP.style.background = "url('"+path_jabberit+"templates/default/images/icon_up.png') no-repeat";
1134                                        divPOP.innerHTML = "PopOut";
1135                                        divPOP.onclick  = function(){ loadscript.windowPOPUP( _id , true ); };
1136                                        _winBuild( 'window_chat_area_' + _id, "display" ).content( true );
1137                                });
1138
1139                                _winBuild( 'window_chat_area_' + _id, 'hidden' );
1140                        }
1141                }
1142        }
1143       
1144        function loadIM()
1145        {
1146                if( arguments.length > 0 )
1147                {
1148                        var files = [
1149                                                path_jabberit + 'js/connector.js',
1150                                                path_jabberit + 'js/xtools.js',
1151                                                path_jabberit + 'js/dragdrop.js',
1152                                                path_jabberit + 'js/makeW.js',
1153                                                path_jabberit + 'js/show_hidden.js',
1154                                                path_jabberit + 'js/trophyim.js',
1155                                                path_jabberit + 'js/AddUser.js',
1156                                                path_jabberit + 'js/SelectEditable.js',
1157                                                path_jabberit + 'templates/default/css/button.css',
1158                                                path_jabberit + 'templates/default/css/common.css',
1159                                                path_jabberit + 'templates/default/css/selectEditableStyle.css',
1160                                                path_jabberit + 'templates/default/css/' + theme_jabberit
1161                                    ];
1162                        // FullName
1163                        fullName = arguments[0];
1164                       
1165                        // Preferences
1166                        _preferencesIM = arguments[1].split(";");
1167                       
1168                        if( !_preferencesIM[3] ) _preferencesIM[3] = "showContactsOfflineJabberit:false";
1169                               
1170                        loadScripts(files);
1171                       
1172                        setTimeout(function()
1173                        {
1174                                // Object Xtools       
1175                                if( Xtools == null )
1176                                        Xtools = new xtools(path_jabberit);
1177                               
1178                                // Object Conector
1179                                if( conn == null )
1180                                        conn = new AjaxConnector(path_jabberit);
1181                               
1182                                // Object Add User
1183                                if( addUser == null )
1184                                        addUser = new addUserIM(Xtools, conn);
1185
1186                               
1187                                // Object SelectEditable
1188                                if( selectEditable == null )
1189                                        selectEditable = new SelectEditable();
1190                                       
1191                                // Add Jabber in StatusBar;
1192                                addIcon();
1193
1194                                // Auto Connect
1195                                setTimeout(function()
1196                                {
1197                                        if( _preferencesIM[0] === 'openWindowJabberit:true' )
1198                                                TrophyIM.load();
1199                                },1500);
1200                               
1201                                // Auto Status
1202                                autoStatus();
1203                                configEvents( document, 'onmousemove', autoStatus );
1204                                configEvents( document, 'onkeypress', autoStatus );
1205
1206                        }, 2000);
1207                }
1208        }
1209       
1210        loadIM.prototype.adIcon                         = addIcon;
1211        loadIM.prototype.actionButton           = actionButton;
1212        loadIM.prototype.addContact                     = addContact;
1213        loadIM.prototype.clrAllContacts         = clrAllContacts;
1214        loadIM.prototype.configEvents           = configEvents;
1215        loadIM.prototype.getIsIE                        = getIsIE;
1216        loadIM.prototype.getPhotoUser           = getPhotoUser;
1217        loadIM.prototype.getStatusMessage       = getStatusMessage;
1218        loadIM.prototype.getShowContactsOffline = getShowContactsOffline;
1219        loadIM.prototype.getUserCurrent         = getUserCurrent;
1220        loadIM.prototype.getZIndex                      = getZindex;
1221        loadIM.prototype.groupsHidden           = groupsHidden;
1222        loadIM.prototype.groupsVisible          = groupsVisible;
1223        loadIM.prototype.keyPressSearch         = keyPressSearch;       
1224        loadIM.prototype.loginPage                      = loginPage;
1225        loadIM.prototype.notification           = notificationNewMessage;
1226        loadIM.prototype.parse                          = parse;
1227        loadIM.prototype.preferences            = preferences;
1228        loadIM.prototype.searchUser                     = searchUser
1229        loadIM.prototype.setAutorization        = setAutorization;
1230        loadIM.prototype.setMessageStatus       = setMessageStatus;
1231        loadIM.prototype.setPreferences         = setPreferences;
1232        loadIM.prototype.setPresence            = setPresence;
1233        loadIM.prototype.setStatusJabber        = setStatusJabber;
1234        loadIM.prototype.setSelectEditable      = setSelectEditable;
1235        loadIM.prototype.setUserCurrent         = setUserCurrent;
1236        loadIM.prototype.removeContact          = removeContact;
1237        loadIM.prototype.removeElement          = removeElement;
1238        loadIM.prototype.removeGroup            = removeGroup;
1239        loadIM.prototype.renameContact          = renameContact;
1240        loadIM.prototype.renameGroup            = renameGroup;
1241        loadIM.prototype.rosterDiv                      = rosterDiv;
1242        loadIM.prototype.windowPOPUP            = windowPOPUP;
1243       
1244        window.LoadIM = loadIM;
1245       
1246})();
Note: See TracBrowser for help on using the repository browser.