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

Revision 2826, 35.7 KB checked in by alexandrecorreia, 14 years ago (diff)

Ticket #986 - Corrigido a palavra PopOut? para PopUp? no arquivo loadIM.js

  • 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           : 350,
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                       
687                // Element flagAwayIM
688                var value3              = _preferencesIM[2].split(':');
689                var element3    = document.getElementById(value3[0]);
690                element3.value  = value3[1];
691               
692                // Element showContactsOfflineJabberit
693                var value4                      = _preferencesIM[3].split(':');
694                var element4            = document.getElementById(value4[0]);
695                var valueSelect4        = value4[1];
696                for(var i = 0; i < element4.options.length; i++)
697                        if( element4.options[i].value == valueSelect4 )
698                                element4.options[i].selected = true;
699        }
700       
701        function removeContact(jid, index)
702        {
703                setTimeout(function()
704                {
705                        TrophyIM.removeContact(jid, index);
706                       
707                },300);
708        }
709       
710        function removeElement( )
711        {
712                if( arguments.length > 0 )
713                {
714                        var _element = arguments[0]
715                        var _parent  = _element.parentNode;
716       
717                        _parent.removeChild( _element );
718                }
719        }
720       
721        function removeGroup()
722        {
723                var _parent = arguments[0];
724               
725                if( _parent.childNodes.length <= 2 )
726                        _parent.parentNode.removeChild(_parent);
727        }
728       
729        function renameContact()
730        {
731                if( arguments.length > 0 )
732                {
733                        var _jid        = arguments[0];
734                        var _index      = arguments[1];
735                       
736                        TrophyIM.renameContact( _jid, _index );
737                }
738        }
739       
740        function renameGroup()
741        {
742                if( arguments.length > 0 )
743                {
744                        var _jid        = arguments[0];
745                        var _index      = arguments[1];
746                       
747                        TrophyIM.renameGroup( _jid , _index );
748                }
749        }
750       
751        function rosterDiv()
752        {
753                var _rosterDiv = function()
754                {
755                        var _idUser     = Base64.decode(getUserCurrent().jid);
756                       
757                        var paramListContact =
758                        {
759                                'idUser'                : _idUser,
760                                'full_name'             : (( fullName.length < 25 ) ? fullName : ( fullName.substring( 0, 25) + "...")),
761                                'path_jabberit' : path_jabberit,
762                                'zIndex_'               : zIndex++
763                        };
764       
765                        var winRosterDiv =
766                        {
767                                 id_window              : "window_Roster_im",
768                                 width                  : 250,
769                                 height                 : 410,
770                                 top                    : 50,
771                                 left                   : -1500,
772                                 leftOld                : 50,
773                                 draggable              : true,
774                                 visible                : "display",
775                                 resizable              : true,
776                                 zindex                 : zIndex++,
777                                 title                  : "Expresso Messenger - Contatos",
778                                 closeAction    : "hidden",
779                                 content                : Xtools.parse(Xtools.xml("contacts_list"),"contactsList.xsl", paramListContact)       
780                        };
781                       
782                        if( _preferencesIM[0] == "openWindowJabberit:false" )
783                        {
784                                winRosterDiv.left               = 50;
785                                winRosterDiv.leftOld    = -1500;
786                        }
787                               
788                        _winBuild( winRosterDiv );
789                       
790                        // Photo User
791                        getPhotoUser(_idUser);
792                       
793                }
794               
795                setTimeout( function(){ _rosterDiv(); }, 550 );
796        }
797
798        function searchUser()
799        {
800                var _input      = getElement('search_user_jabber');
801               
802                if( _input.value.length >= 3 )
803                        addUser.search();
804                else
805                        alert('Your search argument must be longer than 3 characters.');
806        }
807       
808        function setAutorization(jidTo, indexTo)
809        {
810        var divItenContact = null;
811       
812        if( ( divItenContact = getElement('itenContact_' + jidTo + '_' + indexTo )))
813        {       
814                var subscription = divItenContact.getAttribute('subscription');
815               
816                switch(subscription)
817                {
818                        case 'from':
819                               
820                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribe');
821                                break;
822
823                        case 'none' :
824                       
825                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribe');
826                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribed');
827                               
828                                break;
829
830                        case 'not-in-roster':
831                                       
832                                setTimeout(function()
833                                        {
834                                        var _add = "";
835                               
836                                        if( ( _add = confirm("Deseja adicionar o usuario!")) )         
837                                        {
838                                                addUser.add( jidTo, indexTo );
839                                        }
840                                       
841                                        },100);
842                               
843                                        break;
844                                       
845                        case 'to' :
846                               
847                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribed');
848                                       
849                        case 'subscribe' :
850                               
851                                TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribe');
852                               
853                                        break;
854                }
855        }       
856        }
857       
858        function setMessageStatus()
859        {
860                if( arguments.length > 0 )
861                {
862                        var _element = arguments[0];
863                        var _parent      = _element.parentNode;                 
864
865                        if( _element.nodeName.toLowerCase() == "label")
866                        {
867                                var _input                              = document.createElement("input");
868                                        _input.size                     = "35";
869                                        _input.maxlength        = "35";
870                                        _input.style.border = "0";
871                                        _input.value            = _element.innerHTML;
872                                       
873                                // OnkeyUp
874                                configEvents( _input, "onkeyup", function(e)
875                                                {
876                                                        if( e.keyCode == 13 ) loadscript.setMessageStatus(_input, _element);
877                                                }
878                                );
879                               
880                                // Onblur       
881                            configEvents(_input, "onblur", function(){ loadscript.setMessageStatus(_input, _element)});         
882
883                           
884                                if( _parent != null )
885                                {       
886                                        // Remove label
887                                        if( _element != null )
888                                                _parent.removeChild( _element );
889                                               
890                                        // Add Input
891                                        if( _input != null )
892                                                _parent.appendChild( _input );
893                                }
894
895                                _input.focus();
896                                _input.select();
897                        }
898                        else
899                        {
900                                var _label              = arguments[1];
901                                _statusMessage  = _element.value.replace(/^\(+|\)+$/g,"");
902                               
903                                if( ( _statusMessage = _statusMessage.replace(/^\s+|\s+$|^\n|\n$/g,"") ) != "")
904                                        _label.innerHTML = "( " + _statusMessage + " )";
905                                else
906                                        _label.innerHTML = "( Digite aqui sua mensagem de Status )";
907                               
908                                if( _parent != null )
909                                {       
910                                        // Remove Input
911                                        if( _element != null )
912                                                _parent.removeChild( _element );
913                                               
914                                        // Add Label
915                                        if( _label != null )
916                                                _parent.appendChild( _label );
917                                }
918                               
919                                // Send Status Message
920                                _statusMessage = ( ( _statusMessage !=  "Digite aqui sua mensagem de Status") ? _statusMessage : "" );                         
921                               
922                                TrophyIM.setPresence("status", _statusMessage );
923                        }       
924                }
925        }
926       
927        function setPreferences()
928        {
929                // Element openWindowJabberit
930                var elementOpenW        = document.getElementById('openWindowJabberit');
931                var value                       = '';
932               
933                for(var i = 0 ; i < elementOpenW.options.length; i++)
934                        if( elementOpenW.options[i].selected == true)
935                        {
936                                value = 'preferences1=openWindowJabberit:' + elementOpenW.options[i].value;
937                                _preferencesIM[0] = 'openWindowJabberit:' + elementOpenW.options[i].value;
938                        }
939
940                // Element openWindowJabberitPopUp
941                value += '&preferences2=openWindowJabberitPopUp:false';
942                _preferencesIM[1] = 'openWindowJabberitPopUp:false';
943               
944                // Element flagAwayIM
945                var elementFlagIM = document.getElementById('flagAwayIM');
946               
947                if( elementFlagIM.value.length > 0 && parseInt(elementFlagIM.value) > 0 )
948                {
949                        _preferencesIM[2] = 'flagAwayIM:' + elementFlagIM.value;
950                        value += '&preferences3=flagAwayIM:' + elementFlagIM.value;
951                }
952                else
953                {
954                        alert('Informe um valor igual ou maior que 1!');
955                        return false;
956                }
957
958                // Element showContactsOfflineJabberit
959                var elementShowOffline  = document.getElementById('showContactsOfflineJabberit');
960               
961                for(var i = 0 ; i < elementShowOffline.options.length; i++)
962                        if( elementShowOffline.options[i].selected == true)
963                        {
964                                _preferencesIM[3] = 'showContactsOfflineJabberit:' + elementShowOffline.options[i].value;
965                                value += '&preferences4=showContactsOfflineJabberit:' + elementShowOffline.options[i].value;
966                        }
967               
968                // Save Preferences
969                conn.go('p.pf.setPreferences',
970                                 function(data)
971                                 {
972                                        if( data == 'false' )
973                                        {
974                                                alert('Erro salvando suas preferências!');
975                                        }
976
977                                        _winBuild('jabberit_preferences', 'remove');
978                                 },
979                                 value);
980        }
981       
982        function setPresence()
983        {
984                if( arguments.length > 0 )
985                {
986                        var element = arguments[0];
987                       
988                        if( showhidden == null )
989                                showhidden = new ShowHidden(300);
990                       
991                        var _status = [
992                                               ['Afastado', 'away', '<img src="'+path_jabberit+'templates/default/images/away.gif" />'],
993                                               ['Disponível', 'available', '<img src="'+path_jabberit+'templates/default/images/available.gif" />'],
994                                               ['Livre p/ Conversa', 'chat', '<img src="'+path_jabberit+'templates/default/images/chat.gif" />'],
995                                               ['Não Disponível', 'xa', '<img src="'+path_jabberit+'templates/default/images/xa.gif" />'],
996                                               ['Ocupado', 'dnd', '<img src="'+path_jabberit+'templates/default/images/dnd.gif" />'],
997                                               ['Desconectado', 'unavailable', '<img src="'+path_jabberit+'templates/default/images/unavailable.gif" />'],
998                                               ['Mensagem de Status...', 'status', '<img src="'+path_jabberit+'templates/default/images/message_normal.gif" />'],                                               
999                                          ];
1000                       
1001                        var _itens = "";
1002                       
1003                        for( var i in _status )
1004                        {
1005                                if( typeof( _status[i]) == "object" )
1006                                {
1007                                        _itens += '<span style="cursor:pointer;" onclick="TrophyIM.setPresence(\''+_status[i][1]+'\'); loadscript.setStatusJabber(\''+_status[i][0]+'\',\''+_status[i][1]+'\');">';
1008                                        _itens += _status[i][2]+ "<span style='margin:3px;'>" + _status[i][0] + "</span></span><br/>";
1009                                }
1010                        }
1011                       
1012                        var _statusItens = document.createElement("div");
1013                                _statusItens.style.marginTop    = "65px";
1014                                _statusItens.style.marginLeft   = "67px";
1015                                _statusItens.className                  = "x-menu";
1016                                _statusItens.style.zIndex               = '99999';
1017                                _statusItens.innerHTML                  = _itens; 
1018                                _statusItens.onclick                    = function(){ showhidden.hiddenObject(false); };
1019                                                                                 
1020                                showhidden.action('onmouseover', 'onmouseout', _statusItens);
1021                               
1022                        element.parentNode.onmouseout   = function(){ showhidden.hiddenObject(false); };
1023                        element.parentNode.onmouseover  = function(){ showhidden.hiddenObject(true); };
1024                        element.parentNode.appendChild(_statusItens);
1025                }
1026        }
1027
1028        function setSelectEditable(element)
1029        {
1030                if( getElement('selectBox0') == null )
1031                        selectEditable.create(element);
1032        }
1033
1034        function setStatusJabber()
1035        {
1036                if( arguments.length > 0 )
1037                {
1038                        if( arguments[1] != 'status' )
1039                        {
1040                                var _text       = arguments[0];
1041                                var _img        = arguments[1];
1042
1043                                getElement('statusJabberText').innerHTML                = _text;
1044                                getElement('statusJabberImg').style.background  = "url('"+path_jabberit+"templates/default/images/"+_img+".gif')";
1045                                getElement('status_jabber_expresso').style.background = "url('"+path_jabberit+"templates/default/images/"+_img+".gif') no-repeat";
1046                        }
1047                }       
1048        }
1049
1050        function _setUserCurrent( _user )
1051        {
1052                userCurrent =
1053                {
1054                        'jid'           : _user.jid.substring(11, _user.jid.length),
1055                        'password'      : _user.password.substring(11, _user.password.length)
1056                }               
1057        }
1058       
1059        function setUserCurrent()
1060        {
1061                if( getUserCurrent() == null )
1062                {
1063                        conn.go('p.ff.data_0',
1064                                                function(_User)
1065                                                {
1066                                                        var _user = _User;
1067                                                       
1068                                                        conn.go('p.ff.data_1',
1069                                                                        function(_pass)
1070                                                                        {
1071                                                                                _setUserCurrent( { jid : _user, password : _pass } );
1072                                                                        });
1073                                                });
1074                }
1075        }
1076
1077        var _stylesheets = [ ];
1078        var _links = document.getElementsByTagName( 'link' );
1079       
1080        for ( var i = 0; i < _links.length; i++ )
1081                if ( _links.item( i ).type && _links.item( i ).type.toLowerCase( ) == 'text/css' )
1082                        _stylesheets[ _stylesheets.length ] = _links.item( i ); 
1083       
1084        function windowPOPUP()
1085        {
1086                var _id = arguments[0];
1087                var _win_name = _id.replace( /\W/g, '' );
1088
1089                if ( arguments.length == 1 )
1090                {
1091                        if ( windowPopUp[_win_name] )
1092                                return true;
1093                        else
1094                                return false;
1095                }
1096               
1097                if( arguments.length == 2 )
1098                {       
1099                        if( !windowPopUp[_win_name] )
1100                        {
1101                                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');
1102                                var tmp = windowPopUp[_win_name].document;
1103                               
1104                                tmp.write('<html><head>');
1105                                tmp.write('</head><body>');
1106                                tmp.write('</body></html>');
1107                                tmp.close();
1108                               
1109                                for ( var i = 0; i < _stylesheets.length; i++ )
1110                                        tmp.documentElement.getElementsByTagName( 'head' ).item(0).appendChild( _stylesheets[ i ].cloneNode( true ) );
1111
1112                                var divPOP = getElement( _id + "__popUp" );
1113                                        divPOP.style.background = "url('"+path_jabberit+"templates/default/images/icon_down.png') no-repeat";
1114                                        divPOP.innerHTML = "PopIn";
1115                                       
1116                                function _close( )
1117                                {
1118                                        windowPopUp[_win_name].close();
1119                                        configEvents( divPOP ,'onclick', _close, true );
1120                                }
1121                                       
1122                                configEvents( divPOP ,'onclick', _close );
1123
1124                                var _content = tmp.documentElement.getElementsByTagName( 'body' ).item(0).appendChild( getElement(_id + '__chatBox' ).parentNode );
1125
1126                                _content.firstChild.scrollTop = _content.firstChild.scrollHeight;
1127
1128                                configEvents( windowPopUp[_win_name] ,'onbeforeunload', function()
1129                                {
1130                                        delete windowPopUp[_win_name];
1131                                        divPOP.style.background = "url('"+path_jabberit+"templates/default/images/icon_up.png') no-repeat";
1132                                        divPOP.innerHTML = "PopUp";
1133                                        divPOP.onclick  = function(){ loadscript.windowPOPUP( _id , true ); };
1134                                        _winBuild( 'window_chat_area_' + _id, "display" ).content( true );
1135                                });
1136
1137                                _winBuild( 'window_chat_area_' + _id, 'hidden' );
1138                        }
1139                }
1140        }
1141       
1142        function loadIM()
1143        {
1144                if( arguments.length > 0 )
1145                {
1146                        var files = [
1147                                                path_jabberit + 'js/connector.js',
1148                                                path_jabberit + 'js/xtools.js',
1149                                                path_jabberit + 'js/dragdrop.js',
1150                                                path_jabberit + 'js/makeW.js',
1151                                                path_jabberit + 'js/show_hidden.js',
1152                                                path_jabberit + 'js/trophyim.js',
1153                                                path_jabberit + 'js/AddUser.js',
1154                                                path_jabberit + 'js/SelectEditable.js',
1155                                                path_jabberit + 'templates/default/css/button.css',
1156                                                path_jabberit + 'templates/default/css/common.css',
1157                                                path_jabberit + 'templates/default/css/selectEditableStyle.css',
1158                                                path_jabberit + 'templates/default/css/' + theme_jabberit
1159                                    ];
1160                        // FullName
1161                        fullName = arguments[0];
1162                       
1163                        // Preferences
1164                        _preferencesIM = arguments[1].split(";");
1165                       
1166                        if( !_preferencesIM[3] ) _preferencesIM[3] = "showContactsOfflineJabberit:false";
1167                               
1168                        loadScripts(files);
1169                       
1170                        setTimeout(function()
1171                        {
1172                                // Object Xtools       
1173                                if( Xtools == null )
1174                                        Xtools = new xtools(path_jabberit);
1175                               
1176                                // Object Conector
1177                                if( conn == null )
1178                                        conn = new AjaxConnector(path_jabberit);
1179                               
1180                                // Object Add User
1181                                if( addUser == null )
1182                                        addUser = new addUserIM(Xtools, conn);
1183
1184                               
1185                                // Object SelectEditable
1186                                if( selectEditable == null )
1187                                        selectEditable = new SelectEditable();
1188                                       
1189                                // Add Jabber in StatusBar;
1190                                addIcon();
1191
1192                                // Auto Connect
1193                                setTimeout(function()
1194                                {
1195                                        if( _preferencesIM[0] === 'openWindowJabberit:true' )
1196                                                TrophyIM.load();
1197                                },1500);
1198                               
1199                                // Auto Status
1200                                autoStatus();
1201                                configEvents( document, 'onmousemove', autoStatus );
1202                                configEvents( document, 'onkeypress', autoStatus );
1203
1204                        }, 2000);
1205                }
1206        }
1207       
1208        loadIM.prototype.adIcon                         = addIcon;
1209        loadIM.prototype.actionButton           = actionButton;
1210        loadIM.prototype.addContact                     = addContact;
1211        loadIM.prototype.clrAllContacts         = clrAllContacts;
1212        loadIM.prototype.configEvents           = configEvents;
1213        loadIM.prototype.getIsIE                        = getIsIE;
1214        loadIM.prototype.getPhotoUser           = getPhotoUser;
1215        loadIM.prototype.getSmiles                      = getSmiles;
1216        loadIM.prototype.getStatusMessage       = getStatusMessage;
1217        loadIM.prototype.getShowContactsOffline = getShowContactsOffline;
1218        loadIM.prototype.getUserCurrent         = getUserCurrent;
1219        loadIM.prototype.getZIndex                      = getZindex;
1220        loadIM.prototype.groupsHidden           = groupsHidden;
1221        loadIM.prototype.groupsVisible          = groupsVisible;
1222        loadIM.prototype.keyPressSearch         = keyPressSearch;       
1223        loadIM.prototype.loginPage                      = loginPage;
1224        loadIM.prototype.notification           = notificationNewMessage;
1225        loadIM.prototype.parse                          = parse;
1226        loadIM.prototype.preferences            = preferences;
1227        loadIM.prototype.searchUser                     = searchUser
1228        loadIM.prototype.setAutorization        = setAutorization;
1229        loadIM.prototype.setMessageStatus       = setMessageStatus;
1230        loadIM.prototype.setPreferences         = setPreferences;
1231        loadIM.prototype.setPresence            = setPresence;
1232        loadIM.prototype.setStatusJabber        = setStatusJabber;
1233        loadIM.prototype.setSelectEditable      = setSelectEditable;
1234        loadIM.prototype.setUserCurrent         = setUserCurrent;
1235        loadIM.prototype.removeContact          = removeContact;
1236        loadIM.prototype.removeElement          = removeElement;
1237        loadIM.prototype.removeGroup            = removeGroup;
1238        loadIM.prototype.renameContact          = renameContact;
1239        loadIM.prototype.renameGroup            = renameGroup;
1240        loadIM.prototype.rosterDiv                      = rosterDiv;
1241        loadIM.prototype.windowPOPUP            = windowPOPUP;
1242       
1243        window.LoadIM = loadIM;
1244       
1245})();
Note: See TracBrowser for help on using the repository browser.