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

Revision 2799, 36.4 KB checked in by alexandrecorreia, 14 years ago (diff)

Ticket #986 - Implementando recebimento/envio de mensagens para mostrar as imagens smiles.

  • 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 getShowContactsOffline()
347        {
348                if( _preferencesIM[3] )
349                {
350                        var showOffline = _preferencesIM[3].split(":");
351                       
352                        if( showOffline[1] === "true")
353                                return true;
354                        else
355                                return false;
356                }
357               
358                return true;
359        }
360       
361        function getSmiles( String )
362        {
363                String = String.replace( /:\)/g         , " <img src='"+path_jabberit+"templates/default/images/smiles/1.gif'/> ");
364                String = String.replace( /:-D/g         , " <img src='"+path_jabberit+"templates/default/images/smiles/2.gif'/> ");
365                String = String.replace( /;-\)/g        , " <img src='"+path_jabberit+"templates/default/images/smiles/3.gif'/> ");
366                String = String.replace( /=-O/g         , " <img src='"+path_jabberit+"templates/default/images/smiles/4.gif'/> ");
367                String = String.replace( /:P/g          , " <img src='"+path_jabberit+"templates/default/images/smiles/5.gif'/> ");
368                String = String.replace( /8-\)/g        , " <img src='"+path_jabberit+"templates/default/images/smiles/6.gif'/> ");
369                String = String.replace( /\>:o/g        , " <img src='"+path_jabberit+"templates/default/images/smiles/7.gif'/> ");
370                String = String.replace( /:-\$/g        , " <img src='"+path_jabberit+"templates/default/images/smiles/8.gif'/> ");
371                String = String.replace( /:s|:-X/g      , " <img src='"+path_jabberit+"templates/default/images/smiles/9.gif'/> ");
372                String = String.replace( /:-\(/g        , " <img src='"+path_jabberit+"templates/default/images/smiles/10.gif'/> ");
373                String = String.replace( /:\'\(/g       , " <img src='"+path_jabberit+"templates/default/images/smiles/11.gif'/> ");
374                String = String.replace( /:\|/g         , " <img src='"+path_jabberit+"templates/default/images/smiles/12.gif'/> ");
375                String = String.replace( /O:-\)/g       , " <img src='"+path_jabberit+"templates/default/images/smiles/13.gif'/> ");
376                String = String.replace( /\*\*@#%/g     , " <img src='"+path_jabberit+"templates/default/images/smiles/14.gif'/> ");
377                String = String.replace( /\(I\)/g       , " <img src='"+path_jabberit+"templates/default/images/smiles/15.gif'/> ");
378 
379                return String;
380        }
381       
382        function getStatusMessage()
383        {
384                return _statusMessage;
385        }
386       
387        function getUserCurrent()
388        {
389                return userCurrent;
390        }
391       
392        function getZindex()
393        {
394                return zIndex++;
395        }
396       
397        function groupsHidden()
398        {
399                if( arguments.length > 0 )
400                {
401                        var _element = arguments[0];
402                                _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_right.gif') no-repeat center left";
403                                _element.onclick = function(){ groupsVisible(_element);};
404                               
405                                // Hidden all
406                                var _elementNext = _element.nextSibling;
407                               
408                                while( _elementNext )
409                                {       
410                                        if( _elementNext.nodeType == 1 )
411                                                _elementNext.style.display = "none";
412                                       
413                                        _elementNext = _elementNext.nextSibling;
414                                }
415                }
416        }
417       
418        function groupsVisible()
419        {
420                if( arguments.length > 0 )
421                {
422                        var _element = arguments[0];
423                                _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_down.gif') no-repeat center left";
424                                _element.onclick = function(){ groupsHidden(_element);};
425
426                                // Display all
427                                var _elementNext = _element.nextSibling;
428                               
429                                while( _elementNext )
430                                {       
431                                        if( _elementNext.nodeType == 1 && _elementNext.nodeName.toLowerCase() == "div" )
432                                        {
433                                                var is_off = _elementNext.style.backgroundImage.indexOf("unavailable");
434
435                                                if( is_off > 0 && !getShowContactsOffline())
436                                                {
437                                                        _elementNext.style.display = "none";
438                                                        getElement("span_show_" + _elementNext.id ).style.display = "none";
439                                                       
440                                                }
441                                                else
442                                                {
443                                                        _elementNext.style.display = "block";
444                                                        getElement("span_show_" + _elementNext.id ).style.display = "block";
445                                                }
446                                        }
447
448                                        _elementNext = _elementNext.nextSibling;
449                                }
450                }
451        }
452       
453        function keyPressSearch()
454        {
455                if( arguments.length > 0 )
456                {
457                        var ev          = arguments[0];
458                        var element     = arguments[1];
459       
460                        if ( ev.keyCode == 13 )
461                                if( element.value.length >= 3 )
462                                        searchUser( element.value );   
463                                else
464                                        alert('Your search argument must be longer than 3 characters.');
465                }
466        }
467
468       
469        function loginPage()
470        {
471                var paramsLoginPage =
472                {
473                        'username' : ((( Base64.decode(getUserCurrent().jid) )) ? Base64.decode(getUserCurrent().jid) : ""),
474                        'password' : ((( Base64.decode(getUserCurrent().password) )) ? Base64.decode(getUserCurrent().password) : "")
475                }
476               
477                var winLoginPage =
478                {       
479                         id_window              : "window_login_page",
480                         width                  : 260,
481                         height                 : 120,
482                         top                    : 100,
483                         left                   : 400,
484                         draggable              : true,
485                         visible                : "display",
486                         resizable              : true,
487                         zindex                 : zIndex++,
488                         title                  : "Expresso Messenger - Login",
489                         closeAction    : "remove",
490                         content                : Xtools.parse(Xtools.xml("login_page"), "loginPage.xsl", paramsLoginPage)     
491                };
492
493                _winBuild( winLoginPage );
494        }
495
496        function loadScripts(pFiles)
497        {
498                // Load JavaScript
499                var loadJavaScript = function(pJs)
500                {
501                        var newScript = document.createElement("script");
502                                newScript.setAttribute("type", "text/javascript");
503                                newScript.setAttribute("src", pJs );
504                               
505                        return newScript;
506                };
507               
508                // Load CSS
509                var loadStyleSheet = function(pCss)
510                {
511                        var newStyle = document.createElement("link");
512                                newStyle.setAttribute("rel", "stylesheet");
513                                newStyle.setAttribute("type", "text/css");
514                                newStyle.setAttribute("href", pCss);
515                               
516                        return newStyle;
517                };
518               
519                for(var i = 0; i < pFiles.length; i++)
520                {
521                        if( pFiles[i].indexOf(".js") > -1 )
522                                document.getElementsByTagName("head")[0].appendChild(loadJavaScript(pFiles[i]));
523                               
524                        if( pFiles[i].indexOf(".css") > -1 )
525                                document.getElementsByTagName("head")[0].appendChild(loadStyleSheet(pFiles[i]));
526                }
527        }
528       
529        function notificationNewMessage()
530        {
531                var _doc                = document;
532                var _id                 = arguments[0];
533                var _win_name   = _id.replace( /\W/g, '' );
534               
535                if ( windowPOPUP( _id ) )
536                {
537                        _doc = windowPopUp[_win_name].document;
538                }
539               
540                var oldTitle    = _doc.title;
541                var newTitle    = "## NOVA MENSAGEM ##";
542
543                if( timeoutId == null )
544                {
545                        timeoutId = setInterval(function()
546                        {
547                                _doc.title = ( _doc.title == newTitle ) ? oldTitle : newTitle;
548                        }, 1000);
549                       
550                        configEvents( _doc, 'onclick', function()
551                        {
552                                clearInterval(timeoutId);
553                                _doc.title      = oldTitle;
554                                timeoutId               = null;
555                        });
556                       
557                        configEvents( _doc, 'onkeypress', function()
558                        {
559                                clearInterval(timeoutId);
560                                _doc.title      = oldTitle;
561                                timeoutId               = null;
562                        });
563                }
564        }
565
566        function optionsItensContact()
567        {
568                if( arguments.length > 0 )
569                {
570                        var jid         = arguments[0];
571                        var index       = arguments[1];
572                        var coord       = arguments[2];
573                        var element = getElement('itenContact_' + jid + '_' + index );
574                        var action      = ( element.getAttribute("subscription") === "not-in-roster" ) ? "Adicionar" : "Autorizar";     
575                       
576                        if( showhidden == null )
577                                showhidden = new ShowHidden(300);
578
579                        var _options = [
580                                                [ action , 'loadscript.setAutorization(\''+jid+'\',\''+index+'\')'],
581                                                ['Remover' , 'loadscript.removeContact(\''+jid+'\',\''+index+'\')'],
582                                                ['Renomear' , 'loadscript.renameContact(\''+jid+'\',\''+index+'\')'],
583                                                ['Trocar grupo' , 'loadscript.renameGroup(\''+jid+'\',\''+index+'\')']
584                                                   ];
585
586                        var _itens = "";
587                       
588                        for( var i in _options )
589                        {
590                                if( typeof(_options[i]) == "object")
591                                {
592                                        _itens += '<img src="'+arrow_right.src+'"/>';
593                                        _itens += '<span style="cursor:pointer;margin:3px;font-weight:normal;" onclick='+_options[i][1]+'>';
594                                        _itens += _options[i][0] + '</span><br/>';
595                                }
596                        }
597                       
598                        var _optionsItens = document.createElement("div");
599                                _optionsItens.className         = "x-menu";
600                                _optionsItens.style.top         = coord.Y;
601                                _optionsItens.style.left        = ( coord.X - element.offsetLeft );
602                                _optionsItens.style.zIndex      = getZindex();
603                                _optionsItens.innerHTML         = _itens; 
604                                _optionsItens.onclick           = function(){ showhidden.hiddenObject(false); };
605                                _optionsItens.onmouseout        = function(){ showhidden.hiddenObject(false); };       
606                                _optionsItens.onmouseover       = function(){ showhidden.hiddenObject(true); };
607                               
608                                showhidden.action('onmouseover', 'onmouseout', _optionsItens);
609                               
610                        window.document.body.appendChild(_optionsItens);
611                }
612        }
613
614        function parse()
615        {
616                if( arguments.length == 2 )
617                        return Xtools.parse(Xtools.xml(arguments[0]), arguments[1] );
618               
619                if( arguments.length === 3 )
620                        return Xtools.parse(Xtools.xml(arguments[0]), arguments[1], arguments[2] );
621        }
622       
623        function preferences()
624        {
625                var paramPreferences =
626                {
627                        'path'  : path,
628                        'lang1' : 'Suas Preferências',
629                        'lang2' : 'Conexão',   
630                        'lang3' : 'Conectar Automaticamente o IM',
631                        'lang4' : 'Usuários OffLine',
632                        'lang5' : 'Exibir amigos Offline',
633                        'lang6' : 'Salvar',
634                        'lang7' : 'Cancelar',
635                        'lang8' : 'Janela de Contatos',
636                        'lang9' : 'Abrir janela como Pop-up',
637                        'lang10' : 'Ausente',
638                        'lang11' : 'Definir status de ausente depois de',
639                        'lang12' : 'minutos',   
640                        'lang13' : 'Mostrar Contatos', 
641                        'lang14' : 'Mostrar contatos desconectados',
642                        'langYes': 'Sim',
643                        'langNo' : 'Não'                                                                                           
644                };
645               
646               
647                var _win_preferences =
648                {
649                                id_window        : "jabberit_preferences",
650                                width            : 430,
651                                height           : 410,
652                                top                      : 150,
653                                left             : 100,
654                                draggable        : true,
655                                visible          : "display",
656                                resizable        : true,
657                                zindex           : zIndex++,
658                                title            : 'Expresso Messenger - Preferências',
659                                closeAction  : "remove",
660                                content          : Xtools.parse(Xtools.xml('preferences'), 'preferences.xsl', paramPreferences)
661                };
662
663                _winBuild(_win_preferences);
664               
665               
666                var _pButtons = {
667                                'lang1' : 'Salvar',
668                                'lang2' : 'Fechar',
669                                'onclickClose' : '_winBuild("jabberit_preferences","remove");',
670                                'onclickSubmit' : 'javascript:loadscript.setPreferences();'
671                };
672               
673                document.getElementById('buttons_preferences_jabberit').innerHTML = Xtools.parse(Xtools.xml('buttons_main'), 'buttons.xsl', _pButtons);
674               
675                // Element openWindowJabberit
676                var value1                      = _preferencesIM[0].split(':');
677                var element1            = document.getElementById(value1[0]);
678                var valueSelect1        = value1[1];
679               
680                for(var i = 0; i < element1.options.length; i++)
681                        if( element1.options[i].value == valueSelect1 )
682                                element1.options[i].selected = true;
683
684                // Element openWindowJabberitPopUp
685                var value2                      = _preferencesIM[1].split(':');
686                var element2            = document.getElementById(value2[0]);
687                var valueSelect2        = value2[1];
688                       
689                for(var i = 0; i < element2.options.length; i++)
690                        if( element2.options[i].value == valueSelect2 )
691                                element2.options[i].selected = true;
692
693                // Element flagAwayIM
694                var value3              = _preferencesIM[2].split(':');
695                var element3    = document.getElementById(value3[0]);
696                element3.value  = value3[1];
697               
698                // Element showContactsOfflineJabberit
699                var value4                      = _preferencesIM[3].split(':');
700                var element4            = document.getElementById(value4[0]);
701                var valueSelect4        = value4[1];
702                for(var i = 0; i < element4.options.length; i++)
703                        if( element4.options[i].value == valueSelect4 )
704                                element4.options[i].selected = true;
705        }
706       
707        function removeContact(jid, index)
708        {
709                setTimeout(function()
710                {
711                        TrophyIM.removeContact(jid, index);
712                       
713                },300);
714        }
715       
716        function removeElement( )
717        {
718                if( arguments.length > 0 )
719                {
720                        var _element = arguments[0]
721                        var _parent  = _element.parentNode;
722       
723                        _parent.removeChild( _element );
724                }
725        }
726       
727        function removeGroup()
728        {
729                var _parent = arguments[0];
730               
731                if( _parent.childNodes.length <= 2 )
732                        _parent.parentNode.removeChild(_parent);
733        }
734       
735        function renameContact()
736        {
737                if( arguments.length > 0 )
738                {
739                        var _jid        = arguments[0];
740                        var _index      = arguments[1];
741                       
742                        TrophyIM.renameContact( _jid, _index );
743                }
744        }
745       
746        function renameGroup()
747        {
748                if( arguments.length > 0 )
749                {
750                        var _jid        = arguments[0];
751                        var _index      = arguments[1];
752                       
753                        TrophyIM.renameGroup( _jid , _index );
754                }
755        }
756       
757        function rosterDiv()
758        {
759                var _rosterDiv = function()
760                {
761                        var _popUp      = (_preferencesIM[1]).split(":");
762                        var _idUser     = Base64.decode(getUserCurrent().jid);
763                       
764                        var paramListContact =
765                        {
766                                'idUser'                : _idUser,
767                                'full_name'             : (( fullName.length < 25 ) ? fullName : ( fullName.substring( 0, 25) + "...")),
768                                'path_jabberit' : path_jabberit,
769                                'zIndex_'               : zIndex++
770                        };
771       
772                        var winRosterDiv =
773                        {
774                                 id_window              : "window_Roster_im",
775                                 width                  : 250,
776                                 height                 : 410,
777                                 top                    : 50,
778                                 left                   : -1500,
779                                 leftOld                : 50,
780                                 draggable              : true,
781                                 visible                : "display",
782                                 resizable              : true,
783                                 zindex                 : zIndex++,
784                                 title                  : "Expresso Messenger - Contatos",
785                                 closeAction    : "hidden",
786                                 content                : Xtools.parse(Xtools.xml("contacts_list"),"contactsList.xsl", paramListContact)       
787                        };
788                       
789                        if( _preferencesIM[0] == "openWindowJabberit:false" )
790                        {
791                                winRosterDiv.left               = 50;
792                                winRosterDiv.leftOld    = -1500;
793                        }
794                               
795                        _winBuild( winRosterDiv );
796                       
797                        // Photo User
798                        getPhotoUser(_idUser);
799                       
800                }
801               
802                setTimeout( function(){ _rosterDiv(); }, 550 );
803        }
804
805        function searchUser()
806        {
807                var _input      = getElement('search_user_jabber');
808               
809                if( _input.value.length >= 3 )
810                        addUser.search();
811                else
812                        alert('Your search argument must be longer than 3 characters.');
813        }
814       
815        function setAutorization(jidTo, indexTo)
816        {
817        var divItenContact = null;
818       
819        if( ( divItenContact = getElement('itenContact_' + jidTo + '_' + indexTo )))
820        {       
821                var subscription = divItenContact.getAttribute('subscription');
822               
823                switch(subscription)
824                {
825                        case 'from':
826                               
827                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribe');
828                                break;
829
830                        case 'none' :
831                       
832                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribe');
833                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribed');
834                               
835                                break;
836
837                        case 'not-in-roster':
838                                       
839                                setTimeout(function()
840                                        {
841                                        var _add = "";
842                               
843                                        if( ( _add = confirm("Deseja adicionar o usuario!")) )         
844                                        {
845                                                addUser.add( jidTo, indexTo );
846                                        }
847                                       
848                                        },100);
849                               
850                                        break;
851                                       
852                        case 'to' :
853                               
854                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribed');
855                                       
856                        case 'subscribe' :
857                               
858                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribe');
859                               
860                                        break;
861                }
862        }       
863        }
864       
865        function setMessageStatus()
866        {
867                if( arguments.length > 0 )
868                {
869                        var _element = arguments[0];
870                        var _parent      = _element.parentNode;                 
871
872                        if( _element.nodeName.toLowerCase() == "label")
873                        {
874                                var _input                              = document.createElement("input");
875                                        _input.size                     = "35";
876                                        _input.maxlength        = "35";
877                                        _input.style.border = "0";
878                                        _input.value            = _element.innerHTML;
879                                       
880                                // OnkeyUp
881                                configEvents( _input, "onkeyup", function(e)
882                                                {
883                                                        if( e.keyCode == 13 ) loadscript.setMessageStatus(_input, _element);
884                                                }
885                                );
886                               
887                                // Onblur       
888                            configEvents(_input, "onblur", function(){ loadscript.setMessageStatus(_input, _element)});         
889
890                           
891                                if( _parent != null )
892                                {       
893                                        // Remove label
894                                        if( _element != null )
895                                                _parent.removeChild( _element );
896                                               
897                                        // Add Input
898                                        if( _input != null )
899                                                _parent.appendChild( _input );
900                                }
901
902                                _input.focus();
903                                _input.select();
904                        }
905                        else
906                        {
907                                var _label              = arguments[1];
908                                _statusMessage  = _element.value.replace(/^\(+|\)+$/g,"");
909                               
910                                if( ( _statusMessage = _statusMessage.replace(/^\s+|\s+$|^\n|\n$/g,"") ) != "")
911                                        _label.innerHTML = "( " + _statusMessage + " )";
912                                else
913                                        _label.innerHTML = "( Digite aqui sua mensagem de Status )";
914                               
915                                if( _parent != null )
916                                {       
917                                        // Remove Input
918                                        if( _element != null )
919                                                _parent.removeChild( _element );
920                                               
921                                        // Add Label
922                                        if( _label != null )
923                                                _parent.appendChild( _label );
924                                }
925                               
926                                // Send Status Message
927                                _statusMessage = ( ( _statusMessage !=  "Digite aqui sua mensagem de Status") ? _statusMessage : "" );                         
928                               
929                                TrophyIM.setPresence("status", _statusMessage );
930                        }       
931                }
932        }
933       
934        function setPreferences()
935        {
936                // Element openWindowJabberit
937                var elementOpenW        = document.getElementById('openWindowJabberit');
938                var value                       = '';
939                var flagReload          = false;
940               
941                for(var i = 0 ; i < elementOpenW.options.length; i++)
942                        if( elementOpenW.options[i].selected == true)
943                        {
944                                value = 'preferences1=openWindowJabberit:' + elementOpenW.options[i].value;
945                                _preferencesIM[0] = 'openWindowJabberit:' + elementOpenW.options[i].value;
946                        }
947
948                // Element openWindowJabberitPopUp
949                var elementOpenPop = document.getElementById('openWindowJabberitPopUp');       
950
951                for(var i = 0; i < elementOpenPop.options.length; i++ )
952                        if( elementOpenPop.options[i].selected ==  true )
953                        {
954                                value += '&preferences2=openWindowJabberitPopUp:' + elementOpenPop.options[i].value;
955                               
956                                if( _preferencesIM[1] != 'openWindowJabberitPopUp:' + elementOpenPop.options[i].value)
957                                        flagReload = true;
958                                       
959                                _preferencesIM[1] = 'openWindowJabberitPopUp:' + elementOpenPop.options[i].value;
960                        }
961               
962                // Element flagAwayIM
963                var elementFlagIM = document.getElementById('flagAwayIM');
964               
965                if( elementFlagIM.value.length > 0 && parseInt(elementFlagIM.value) > 0 )
966                {
967                        _preferencesIM[2] = 'flagAwayIM:' + elementFlagIM.value;
968                        value += '&preferences3=flagAwayIM:' + elementFlagIM.value;
969                }
970                else
971                {
972                        alert('Informe um valor igual ou maior que 1!');
973                        return false;
974                }
975
976                // Element showContactsOfflineJabberit
977                var elementShowOffline  = document.getElementById('showContactsOfflineJabberit');
978               
979                for(var i = 0 ; i < elementShowOffline.options.length; i++)
980                        if( elementShowOffline.options[i].selected == true)
981                        {
982                                _preferencesIM[3] = 'showContactsOfflineJabberit:' + elementShowOffline.options[i].value;
983                                value += '&preferences4=showContactsOfflineJabberit:' + elementShowOffline.options[i].value;
984                        }
985
986                // Save Preferences
987                conn.go('p.pf.setPreferences',
988                                 function(data)
989                                 {
990                                        if(data == 'true')
991                                        {
992                                                if( flagReload )
993                                                {
994                                                        window.location.reload();
995                                                        myWindow.close();                                                       
996                                                }
997                                        }
998                                        else{ alert('Erro salvando suas preferências!'); }
999
1000                                        _winBuild('jabberit_preferences', 'remove');
1001                                 },
1002                                 value);
1003        }
1004       
1005        function setPresence()
1006        {
1007                if( arguments.length > 0 )
1008                {
1009                        var element = arguments[0];
1010                       
1011                        if( showhidden == null )
1012                                showhidden = new ShowHidden(300);
1013                       
1014                        var _status = [
1015                                               ['Afastado', 'away', '<img src="'+path_jabberit+'templates/default/images/away.gif" />'],
1016                                               ['Disponível', 'available', '<img src="'+path_jabberit+'templates/default/images/available.gif" />'],
1017                                               ['Livre p/ Conversa', 'chat', '<img src="'+path_jabberit+'templates/default/images/chat.gif" />'],
1018                                               ['Não Disponível', 'xa', '<img src="'+path_jabberit+'templates/default/images/xa.gif" />'],
1019                                               ['Ocupado', 'dnd', '<img src="'+path_jabberit+'templates/default/images/dnd.gif" />'],
1020                                               ['Desconectado', 'unavailable', '<img src="'+path_jabberit+'templates/default/images/unavailable.gif" />'],
1021                                               ['Mensagem de Status...', 'status', '<img src="'+path_jabberit+'templates/default/images/message_normal.gif" />'],                                               
1022                                          ];
1023                       
1024                        var _itens = "";
1025                       
1026                        for( var i in _status )
1027                        {
1028                                if( typeof( _status[i]) == "object" )
1029                                {
1030                                        _itens += '<span style="cursor:pointer;" onclick="TrophyIM.setPresence(\''+_status[i][1]+'\'); loadscript.setStatusJabber(\''+_status[i][0]+'\',\''+_status[i][1]+'\');">';
1031                                        _itens += _status[i][2]+ "<span style='margin:3px;'>" + _status[i][0] + "</span></span><br/>";
1032                                }
1033                        }
1034                       
1035                        var _statusItens = document.createElement("div");
1036                                _statusItens.style.marginTop    = "65px";
1037                                _statusItens.style.marginLeft   = "67px";
1038                                _statusItens.className                  = "x-menu";
1039                                _statusItens.style.zIndex               = '99999';
1040                                _statusItens.innerHTML                  = _itens; 
1041                                _statusItens.onclick                    = function(){ showhidden.hiddenObject(false); };
1042                                                                                 
1043                                showhidden.action('onmouseover', 'onmouseout', _statusItens);
1044                               
1045                        element.parentNode.onmouseout   = function(){ showhidden.hiddenObject(false); };
1046                        element.parentNode.onmouseover  = function(){ showhidden.hiddenObject(true); };
1047                        element.parentNode.appendChild(_statusItens);
1048                }
1049        }
1050
1051        function setSelectEditable(element)
1052        {
1053                if( getElement('selectBox0') == null )
1054                        selectEditable.create(element);
1055        }
1056
1057        function setStatusJabber()
1058        {
1059                if( arguments.length > 0 )
1060                {
1061                        if( arguments[1] != 'status' )
1062                        {
1063                                var _text       = arguments[0];
1064                                var _img        = arguments[1];
1065
1066                                getElement('statusJabberText').innerHTML                = _text;
1067                                getElement('statusJabberImg').style.background  = "url('"+path_jabberit+"templates/default/images/"+_img+".gif')";
1068                                getElement('status_jabber_expresso').style.background = "url('"+path_jabberit+"templates/default/images/"+_img+".gif') no-repeat";
1069                        }
1070                }       
1071        }
1072
1073        function _setUserCurrent( _jid, _password )
1074        {
1075                userCurrent =
1076                {
1077                        'jid'           : _jid.substring(11, _jid.length),
1078                        'password'      : _password.substring(11, _password.length)
1079                }               
1080        }
1081       
1082        function setUserCurrent()
1083        {
1084                if( getUserCurrent() == null )
1085                {
1086                        conn.go('p.ff.data_0',
1087                                                function(_User)
1088                                                {
1089                                                        var _user = _User;
1090                                                       
1091                                                        conn.go('p.ff.data_1',
1092                                                                        function(_pass)
1093                                                                        {
1094                                                                                _setUserCurrent( _user, _pass );
1095                                                                        });
1096                                                });
1097                }
1098        }
1099
1100        var _stylesheets = [ ];
1101        var _links = document.getElementsByTagName( 'link' );
1102       
1103        for ( var i = 0; i < _links.length; i++ )
1104                if ( _links.item( i ).type && _links.item( i ).type.toLowerCase( ) == 'text/css' )
1105                        _stylesheets[ _stylesheets.length ] = _links.item( i ); 
1106       
1107        function windowPOPUP()
1108        {
1109                var _id = arguments[0];
1110                var _win_name = _id.replace( /\W/g, '' );
1111
1112                if ( arguments.length == 1 )
1113                {
1114                        if ( windowPopUp[_win_name] )
1115                                return true;
1116                        else
1117                                return false;
1118                }
1119               
1120                if( arguments.length == 2 )
1121                {       
1122                        if( !windowPopUp[_win_name] )
1123                        {
1124                                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');
1125                                var tmp = windowPopUp[_win_name].document;
1126                               
1127                                tmp.write('<html><head>');
1128                                tmp.write('</head><body>');
1129                                tmp.write('</body></html>');
1130                                tmp.close();
1131                               
1132                                for ( var i = 0; i < _stylesheets.length; i++ )
1133                                        tmp.documentElement.getElementsByTagName( 'head' ).item(0).appendChild( _stylesheets[ i ].cloneNode( true ) );
1134
1135                                var divPOP = getElement( _id + "__popUp" );
1136                                        divPOP.style.background = "url('"+path_jabberit+"templates/default/images/icon_down.png') no-repeat";
1137                                        divPOP.innerHTML = "PopIn";
1138                                       
1139                                function _close( )
1140                                {
1141                                        windowPopUp[_win_name].close();
1142                                        configEvents( divPOP ,'onclick', _close, true );
1143                                }
1144                                       
1145                                configEvents( divPOP ,'onclick', _close );
1146
1147                                var _content = tmp.documentElement.getElementsByTagName( 'body' ).item(0).appendChild( getElement(_id + '__chatBox' ).parentNode );
1148
1149                                _content.firstChild.scrollTop = _content.firstChild.scrollHeight;
1150
1151                                configEvents( windowPopUp[_win_name] ,'onbeforeunload', function()
1152                                {
1153                                        delete windowPopUp[_win_name];
1154                                        divPOP.style.background = "url('"+path_jabberit+"templates/default/images/icon_up.png') no-repeat";
1155                                        divPOP.innerHTML = "PopOut";
1156                                        divPOP.onclick  = function(){ loadscript.windowPOPUP( _id , true ); };
1157                                        _winBuild( 'window_chat_area_' + _id, "display" ).content( true );
1158                                });
1159
1160                                _winBuild( 'window_chat_area_' + _id, 'hidden' );
1161                        }
1162                }
1163        }
1164       
1165        function loadIM()
1166        {
1167                if( arguments.length > 0 )
1168                {
1169                        var files = [
1170                                                path_jabberit + 'js/connector.js',
1171                                                path_jabberit + 'js/xtools.js',
1172                                                path_jabberit + 'js/dragdrop.js',
1173                                                path_jabberit + 'js/makeW.js',
1174                                                path_jabberit + 'js/show_hidden.js',
1175                                                path_jabberit + 'js/trophyim.js',
1176                                                path_jabberit + 'js/AddUser.js',
1177                                                path_jabberit + 'js/SelectEditable.js',
1178                                                path_jabberit + 'templates/default/css/button.css',
1179                                                path_jabberit + 'templates/default/css/common.css',
1180                                                path_jabberit + 'templates/default/css/selectEditableStyle.css',
1181                                                path_jabberit + 'templates/default/css/' + theme_jabberit
1182                                    ];
1183                        // FullName
1184                        fullName = arguments[0];
1185                       
1186                        // Preferences
1187                        _preferencesIM = arguments[1].split(";");
1188                       
1189                        if( !_preferencesIM[3] ) _preferencesIM[3] = "showContactsOfflineJabberit:false";
1190                               
1191                        loadScripts(files);
1192                       
1193                        setTimeout(function()
1194                        {
1195                                // Object Xtools       
1196                                if( Xtools == null )
1197                                        Xtools = new xtools(path_jabberit);
1198                               
1199                                // Object Conector
1200                                if( conn == null )
1201                                        conn = new AjaxConnector(path_jabberit);
1202                               
1203                                // Object Add User
1204                                if( addUser == null )
1205                                        addUser = new addUserIM(Xtools, conn);
1206
1207                               
1208                                // Object SelectEditable
1209                                if( selectEditable == null )
1210                                        selectEditable = new SelectEditable();
1211                                       
1212                                // Add Jabber in StatusBar;
1213                                addIcon();
1214
1215                                // Auto Connect
1216                                setTimeout(function()
1217                                {
1218                                        if( _preferencesIM[0] === 'openWindowJabberit:true' )
1219                                                TrophyIM.load();
1220                                },1500);
1221                               
1222                                // Auto Status
1223                                autoStatus();
1224                                configEvents( document, 'onmousemove', autoStatus );
1225                                configEvents( document, 'onkeypress', autoStatus );
1226
1227                        }, 2000);
1228                }
1229        }
1230       
1231        loadIM.prototype.adIcon                         = addIcon;
1232        loadIM.prototype.actionButton           = actionButton;
1233        loadIM.prototype.addContact                     = addContact;
1234        loadIM.prototype.clrAllContacts         = clrAllContacts;
1235        loadIM.prototype.configEvents           = configEvents;
1236        loadIM.prototype.getIsIE                        = getIsIE;
1237        loadIM.prototype.getPhotoUser           = getPhotoUser;
1238        loadIM.prototype.getSmiles                      = getSmiles;
1239        loadIM.prototype.getStatusMessage       = getStatusMessage;
1240        loadIM.prototype.getShowContactsOffline = getShowContactsOffline;
1241        loadIM.prototype.getUserCurrent         = getUserCurrent;
1242        loadIM.prototype.getZIndex                      = getZindex;
1243        loadIM.prototype.groupsHidden           = groupsHidden;
1244        loadIM.prototype.groupsVisible          = groupsVisible;
1245        loadIM.prototype.keyPressSearch         = keyPressSearch;       
1246        loadIM.prototype.loginPage                      = loginPage;
1247        loadIM.prototype.notification           = notificationNewMessage;
1248        loadIM.prototype.parse                          = parse;
1249        loadIM.prototype.preferences            = preferences;
1250        loadIM.prototype.searchUser                     = searchUser
1251        loadIM.prototype.setAutorization        = setAutorization;
1252        loadIM.prototype.setMessageStatus       = setMessageStatus;
1253        loadIM.prototype.setPreferences         = setPreferences;
1254        loadIM.prototype.setPresence            = setPresence;
1255        loadIM.prototype.setStatusJabber        = setStatusJabber;
1256        loadIM.prototype.setSelectEditable      = setSelectEditable;
1257        loadIM.prototype.setUserCurrent         = setUserCurrent;
1258        loadIM.prototype.removeContact          = removeContact;
1259        loadIM.prototype.removeElement          = removeElement;
1260        loadIM.prototype.removeGroup            = removeGroup;
1261        loadIM.prototype.renameContact          = renameContact;
1262        loadIM.prototype.renameGroup            = renameGroup;
1263        loadIM.prototype.rosterDiv                      = rosterDiv;
1264        loadIM.prototype.windowPOPUP            = windowPOPUP;
1265       
1266        window.LoadIM = loadIM;
1267       
1268})();
Note: See TracBrowser for help on using the repository browser.