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

Revision 2865, 36.5 KB checked in by alexandrecorreia, 14 years ago (diff)

Ticket #986 - [ FEITO POR Emmanuel Ferro SERPRO ] Internacionalizacao, criado o arquivo i18n_pt_BR

  • 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                        if( _preferencesIM[0] == "openWindowJabberit:true" )
186                        {
187                                configEvents( _statusJabber, 'onclick', function(){ rosterDiv(); });
188                        }
189                        else
190                        {
191                                configEvents( _statusJabber, 'onclick', function(){ TrophyIM.load(); });
192                        }
193                }
194        }
195
196        function autoStatus()
197        {
198                var _div_status = ( getElement('status_jabber_expresso') != null ) ?  getElement('status_jabber_expresso') : null;
199               
200                if ( _autoStatus )
201                        clearTimeout(_autoStatus);
202
203                if ( _div_status != null )
204                {
205                        var _status = _div_status.style.backgroundImage;
206                                _status = _status.substr(_status.lastIndexOf('/') + 1);
207                                _status = _status.substr(0, _status.indexOf('.'));
208                               
209                        if( _status == "xa" && _div_status.getAttribute('autoStatus') )
210                        {
211                                if( getStatusMessage() != "")
212                                        TrophyIM.setPresence("available", getStatusMessage());
213                                else
214                                        TrophyIM.setPresence("available");
215                               
216                                _div_status.removeAttribute('autoStatus');
217                                loadscript.setStatusJabber("Disponível","available");
218                        }
219                }
220               
221                var TimeStatus = _preferencesIM[2].split(':');
222
223                if( TimeStatus[1] )
224                        _autoStatus = setTimeout( function(){ autoStatusHandler();}, parseInt(TimeStatus[1]) * _autoStatusTime );
225                else
226                        _autoStatus = setTimeout( function(){ autoStatusHandler();}, parseInt(_autoStatusTime));
227        }
228       
229        function autoStatusHandler()
230        {
231                var _div_status = ( getElement('status_jabber_expresso') != null ) ?  getElement('status_jabber_expresso') : null;
232               
233                if ( _div_status != null )
234                {
235                        var _status = _div_status.style.backgroundImage;
236                                _status = _status.substr(_status.lastIndexOf('/') + 1);
237                                _status = _status.substr(0, _status.indexOf('.'));
238                       
239                        if( _status == "available" )
240                        {
241                                if(getStatusMessage() != "")
242                                        TrophyIM.setPresence("xa", getStatusMessage());
243                                else
244                                        TrophyIM.setPresence("xa");
245
246                                _div_status.setAttribute('autoStatus','true');
247                                loadscript.setStatusJabber("Não Disponível","xa");
248                        }
249                }
250        }
251
252        function clrAllContacts()
253        {
254                getElement("JabberIMRoster").innerHTML = "";
255        }
256       
257        function configEvents(pObj, pEvent, pHandler)
258        {
259                if ( typeof pObj == 'object' )
260                {
261                        if ( pEvent.substring(0, 2) == 'on' )
262                                pEvent = pEvent.substring(2, pEvent.length );
263
264                        if ( arguments.length == 3 )
265                        {
266                                if ( pObj.addEventListener )
267                                        pObj.addEventListener(pEvent, pHandler, false );
268                                else if ( pObj.attachEvent )
269                                        pObj.attachEvent( 'on' + pEvent, pHandler );
270                        }
271                        else if ( arguments.length == 4 )
272                        {
273                                if ( pObj.removeEventListener )
274                                        pObj.removeEventListener( pEvent, pHandler, false );
275                                else if ( pObj.detachEvent )
276                                        pObj.detachEvent( 'on' + pEvent, pHandler );
277                        }
278                }
279        }
280       
281        function fastMenu()
282        {
283                if( arguments.length > 0 )
284                {
285                        var element = arguments[0];
286
287                        if( showhidden == null )
288                                showhidden = new ShowHidden(300);
289
290                        var _options = [
291                                                ['Adicionar Contato', 'loadscript.addContact();' ],
292                                                ['Ajuda', 'alert("2")' ],
293                                                ['Preferências', 'loadscript.preferences();'],
294                                                   ];
295
296                        var _itens = "";
297                       
298                        for( var i in _options )
299                        {
300                                if( _options[i].constructor == Function )
301                                        continue;
302                               
303                                _itens += '<img src="'+arrow_right.src+'"/>';
304                                _itens += '<span style="cursor:pointer; margin:3px;" onclick='+_options[i][1]+'>';
305                                _itens += _options[i][0] + '</span><br/>';
306                        }
307                       
308                        var _optionsItens = document.createElement("div");
309                                _optionsItens.id        = "fastMenu_Jabber";                           
310                                _optionsItens.style.marginTop   = "19px";
311                                _optionsItens.style.marginLeft  = "-8px";
312                                _optionsItens.className         = "x-menu";
313                                _optionsItens.style.zIndex      = '999999';
314                                _optionsItens.innerHTML         = _itens;
315                                _optionsItens.onclick           = function(){ showhidden.hiddenObject(false); };
316                                _optionsItens.onmouseout        = function(){ showhidden.hiddenObject(false); };
317                                _optionsItens.onmouseover       = function(){ showhidden.hiddenObject(true); };
318                                                                                 
319                                showhidden.action('onmouseover', 'onmouseout', _optionsItens);
320                               
321                        element.parentNode.appendChild( _optionsItens );
322                }
323        }
324       
325        function getElement( elementId )
326        {
327                return document.getElementById( elementId );
328        }
329       
330        function getIsIE()
331        {
332                return is_ie;
333        }
334       
335        function getPhotoUser( jid )
336        {
337                try
338                {
339                var _divPhoto = getElement( jid + '__photo' );
340
341                if( _divPhoto.style.backgroundImage.indexOf('photo.png') > 0 )
342                {
343                        var _imgUser  = path_jabberit + 'inc/WebService.php?' + Date.parse( new Date );
344                                _imgUser += '&photo_ldap=' + jid;
345
346                        _divPhoto.style.backgroundImage = 'url(' + _imgUser + ')';
347                }
348                }
349                catch(e)
350                {}
351        }
352       
353        function getShowContactsOffline()
354        {
355                if( _preferencesIM[3] )
356                {
357                        var showOffline = _preferencesIM[3].split(":");
358                       
359                        if( showOffline[1] === "true")
360                                return true;
361                        else
362                                return false;
363                }
364               
365                return true;
366        }
367       
368        function getSmiles( String )
369        {
370                String = String.replace( /:\)|:-\)/g    , " <img src='"+path_jabberit+"templates/default/images/smiles/1.gif'/> ");
371                String = String.replace( /:-D/g                 , " <img src='"+path_jabberit+"templates/default/images/smiles/2.gif'/> ");
372                String = String.replace( /;-\)/g                , " <img src='"+path_jabberit+"templates/default/images/smiles/3.gif'/> ");
373                String = String.replace( /=-O/g                 , " <img src='"+path_jabberit+"templates/default/images/smiles/4.gif'/> ");
374                String = String.replace( /:P/g                  , " <img src='"+path_jabberit+"templates/default/images/smiles/5.gif'/> ");
375                String = String.replace( /8-\)/g                , " <img src='"+path_jabberit+"templates/default/images/smiles/6.gif'/> ");
376                String = String.replace( /\>:o/g                , " <img src='"+path_jabberit+"templates/default/images/smiles/7.gif'/> ");
377                String = String.replace( /:-\$/g                , " <img src='"+path_jabberit+"templates/default/images/smiles/8.gif'/> ");
378                String = String.replace( /:s|:-X/g              , " <img src='"+path_jabberit+"templates/default/images/smiles/9.gif'/> ");
379                String = String.replace( /:-\(/g                , " <img src='"+path_jabberit+"templates/default/images/smiles/10.gif'/> ");
380                String = String.replace( /:\'\(/g               , " <img src='"+path_jabberit+"templates/default/images/smiles/11.gif'/> ");
381                String = String.replace( /:\|/g                 , " <img src='"+path_jabberit+"templates/default/images/smiles/12.gif'/> ");
382                String = String.replace( /O:-\)/g               , " <img src='"+path_jabberit+"templates/default/images/smiles/13.gif'/> ");
383                String = String.replace( /\*\*@#%/g             , " <img src='"+path_jabberit+"templates/default/images/smiles/14.gif'/> ");
384                String = String.replace( /\(I\)/g               , " <img src='"+path_jabberit+"templates/default/images/smiles/15.gif'/> ");
385 
386                return String;
387        }
388       
389        function getStatusMessage()
390        {
391                return _statusMessage;
392        }
393       
394        function getUserCurrent()
395        {
396                return userCurrent;
397        }
398       
399        function getZindex()
400        {
401                return zIndex++;
402        }
403       
404        function groupsHidden()
405        {
406                if( arguments.length > 0 )
407                {
408                        var _element = arguments[0];
409                                _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_right.gif') no-repeat center left";
410                                _element.onclick = function(){ groupsVisible(_element);};
411                               
412                                // Hidden all
413                                var _elementNext = _element.nextSibling;
414                               
415                                while( _elementNext )
416                                {       
417                                        if( _elementNext.nodeType == 1 )
418                                                _elementNext.style.display = "none";
419                                       
420                                        _elementNext = _elementNext.nextSibling;
421                                }
422                }
423        }
424       
425        function groupsVisible()
426        {
427                if( arguments.length > 0 )
428                {
429                        var _element = arguments[0];
430                                _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_down.gif') no-repeat center left";
431                                _element.onclick = function(){ groupsHidden(_element);};
432
433                                // Display all
434                                var _elementNext = _element.nextSibling;
435                               
436                                while( _elementNext )
437                                {       
438                                        if( _elementNext.nodeType == 1 && _elementNext.nodeName.toLowerCase() == "div" )
439                                        {
440                                                var is_off = _elementNext.style.backgroundImage.indexOf("unavailable");
441
442                                                if( is_off > 0 && !getShowContactsOffline())
443                                                {
444                                                        _elementNext.style.display = "none";
445                                                        getElement("span_show_" + _elementNext.id ).style.display = "none";
446                                                       
447                                                }
448                                                else
449                                                {
450                                                        _elementNext.style.display = "block";
451                                                        getElement("span_show_" + _elementNext.id ).style.display = "block";
452                                                }
453                                        }
454
455                                        _elementNext = _elementNext.nextSibling;
456                                }
457                }
458        }
459       
460        function keyPressSearch()
461        {
462                if( arguments.length > 0 )
463                {
464                        var ev          = arguments[0];
465                        var element     = arguments[1];
466       
467                        if ( ev.keyCode == 13 )
468                                if( element.value.length >= 3 )
469                                        searchUser( element.value );   
470                                else
471                                        alert('Your search argument must be longer than 3 characters.');
472                }
473        }
474
475       
476        function loginPage()
477        {
478                var paramsLoginPage =
479                {
480                        'username' : ((( Base64.decode(getUserCurrent().jid) )) ? Base64.decode(getUserCurrent().jid) : ""),
481                        'password' : ((( Base64.decode(getUserCurrent().password) )) ? Base64.decode(getUserCurrent().password) : "")
482                }
483               
484                var winLoginPage =
485                {       
486                         id_window              : "window_login_page",
487                         width                  : 260,
488                         height                 : 120,
489                         top                    : 100,
490                         left                   : 400,
491                         draggable              : true,
492                         visible                : "display",
493                         resizable              : true,
494                         zindex                 : zIndex++,
495                         title                  : "Expresso Messenger - Login",
496                         closeAction    : "remove",
497                         content                : Xtools.parse(Xtools.xml("login_page"), "loginPage.xsl", paramsLoginPage)     
498                };
499
500                _winBuild( winLoginPage );
501        }
502
503        function loadScripts(pFiles)
504        {
505                // Load JavaScript
506                var loadJavaScript = function(pJs)
507                {
508                        var newScript = document.createElement("script");
509                                newScript.setAttribute("type", "text/javascript");
510                                newScript.setAttribute("src", pJs );
511                               
512                        return newScript;
513                };
514               
515                // Load CSS
516                var loadStyleSheet = function(pCss)
517                {
518                        var newStyle = document.createElement("link");
519                                newStyle.setAttribute("rel", "stylesheet");
520                                newStyle.setAttribute("type", "text/css");
521                                newStyle.setAttribute("href", pCss);
522                               
523                        return newStyle;
524                };
525               
526                for(var i = 0; i < pFiles.length; i++)
527                {
528                        if( pFiles[i].indexOf(".js") > -1 )
529                                document.getElementsByTagName("head")[0].appendChild(loadJavaScript(pFiles[i]));
530                               
531                        if( pFiles[i].indexOf(".css") > -1 )
532                                document.getElementsByTagName("head")[0].appendChild(loadStyleSheet(pFiles[i]));
533                }
534        }
535       
536        function notificationNewMessage()
537        {
538                var _doc                = document;
539                var _id                 = arguments[0];
540                var _win_name   = _id.replace( /\W/g, '' );
541               
542                if ( windowPOPUP( _id ) )
543                {
544                        _doc = windowPopUp[_win_name].document;
545                }
546               
547                var oldTitle    = _doc.title;
548                var newTitle    = "## NOVA MENSAGEM ##";
549
550                if( timeoutId == null )
551                {
552                        timeoutId = setInterval(function()
553                        {
554                                _doc.title = ( _doc.title == newTitle ) ? oldTitle : newTitle;
555                        }, 1000);
556                       
557                        configEvents( _doc, 'onclick', function()
558                        {
559                                clearInterval(timeoutId);
560                                _doc.title      = oldTitle;
561                                timeoutId               = null;
562                        });
563                       
564                        configEvents( _doc, 'onkeypress', function()
565                        {
566                                clearInterval(timeoutId);
567                                _doc.title      = oldTitle;
568                                timeoutId               = null;
569                        });
570                }
571        }
572
573        function optionsItensContact()
574        {
575                if( arguments.length > 0 )
576                {
577                        var jid         = arguments[0];
578                        var index       = arguments[1];
579                        var coord       = arguments[2];
580                        var element = getElement('itenContact_' + jid + '_' + index );
581                        var action      = ( element.getAttribute("subscription") === "not-in-roster" ) ? "Adicionar" : "Autorizar";     
582                       
583                        if( showhidden == null )
584                                showhidden = new ShowHidden(300);
585
586                        var _options = [
587                                                [ action , 'loadscript.setAutorization(\''+jid+'\',\''+index+'\')'],
588                                                ['Remover' , 'loadscript.removeContact(\''+jid+'\',\''+index+'\')'],
589                                                ['Renomear' , 'loadscript.renameContact(\''+jid+'\',\''+index+'\')'],
590                                                ['Trocar grupo' , 'loadscript.renameGroup(\''+jid+'\',\''+index+'\')']
591                                                   ];
592
593                        var _itens = "";
594                       
595                        for( var i in _options )
596                        {
597                                if( typeof(_options[i]) == "object")
598                                {
599                                        _itens += '<img src="'+arrow_right.src+'"/>';
600                                        _itens += '<span style="cursor:pointer;margin:3px;font-weight:normal;" onclick='+_options[i][1]+'>';
601                                        _itens += _options[i][0] + '</span><br/>';
602                                }
603                        }
604                       
605                        var _optionsItens = document.createElement("div");
606                                _optionsItens.className         = "x-menu";
607                                _optionsItens.style.top         = coord.Y;
608                                _optionsItens.style.left        = ( coord.X - element.offsetLeft );
609                                _optionsItens.style.zIndex      = getZindex();
610                                _optionsItens.innerHTML         = _itens; 
611                                _optionsItens.onclick           = function(){ showhidden.hiddenObject(false); };
612                                _optionsItens.onmouseout        = function(){ showhidden.hiddenObject(false); };       
613                                _optionsItens.onmouseover       = function(){ showhidden.hiddenObject(true); };
614                               
615                                showhidden.action('onmouseover', 'onmouseout', _optionsItens);
616                               
617                        window.document.body.appendChild(_optionsItens);
618                }
619        }
620
621        function parse()
622        {
623                if( arguments.length == 2 )
624                        return Xtools.parse(Xtools.xml(arguments[0]), arguments[1] );
625               
626                if( arguments.length === 3 )
627                        return Xtools.parse(Xtools.xml(arguments[0]), arguments[1], arguments[2] );
628        }
629       
630        function preferences()
631        {
632                var paramPreferences =
633                {
634                        'path'  : path,
635                        'lang1' : 'Suas Preferências',
636                        'lang2' : 'Conexão',   
637                        'lang3' : 'Conectar Automaticamente o IM',
638                        'lang4' : 'Usuários OffLine',
639                        'lang5' : 'Exibir amigos Offline',
640                        'lang6' : 'Salvar',
641                        'lang7' : 'Cancelar',
642                        'lang8' : 'Janela de Contatos',
643                        'lang9' : 'Abrir janela como Pop-up',
644                        'lang10' : 'Ausente',
645                        'lang11' : 'Definir status de ausente depois de',
646                        'lang12' : 'minutos',   
647                        'lang13' : 'Mostrar Contatos', 
648                        'lang14' : 'Mostrar contatos desconectados',
649                        'langYes': 'Sim',
650                        'langNo' : 'Não'                                                                                           
651                };
652               
653               
654                var _win_preferences =
655                {
656                                id_window        : "jabberit_preferences",
657                                width            : 430,
658                                height           : 350,
659                                top                      : 150,
660                                left             : 100,
661                                draggable        : true,
662                                visible          : "display",
663                                resizable        : true,
664                                zindex           : zIndex++,
665                                title            : 'Expresso Messenger - Preferências',
666                                closeAction  : "remove",
667                                content          : Xtools.parse(Xtools.xml('preferences'), 'preferences.xsl', paramPreferences)
668                };
669
670                _winBuild(_win_preferences);
671               
672               
673                var _pButtons = {
674                                'lang1' : 'Salvar',
675                                'lang2' : 'Fechar',
676                                'onclickClose' : '_winBuild("jabberit_preferences","remove");',
677                                'onclickSubmit' : 'javascript:loadscript.setPreferences();'
678                };
679               
680                document.getElementById('buttons_preferences_jabberit').innerHTML = Xtools.parse(Xtools.xml('buttons_main'), 'buttons.xsl', _pButtons);
681               
682                // Element openWindowJabberit
683                var value1                      = _preferencesIM[0].split(':');
684                var element1            = document.getElementById(value1[0]);
685                var valueSelect1        = value1[1];
686               
687                for(var i = 0; i < element1.options.length; i++)
688                        if( element1.options[i].value == valueSelect1 )
689                                element1.options[i].selected = true;
690
691                // Element openWindowJabberitPopUp
692                var value2                      = _preferencesIM[1].split(':');
693                       
694                // Element flagAwayIM
695                var value3              = _preferencesIM[2].split(':');
696                var element3    = document.getElementById(value3[0]);
697                element3.value  = value3[1];
698               
699                // Element showContactsOfflineJabberit
700                var value4                      = _preferencesIM[3].split(':');
701                var element4            = document.getElementById(value4[0]);
702                var valueSelect4        = value4[1];
703                for(var i = 0; i < element4.options.length; i++)
704                        if( element4.options[i].value == valueSelect4 )
705                                element4.options[i].selected = true;
706        }
707       
708        function removeContact(jid, index)
709        {
710                setTimeout(function()
711                {
712                        TrophyIM.removeContact(jid, index);
713                       
714                },300);
715        }
716       
717        function removeElement( )
718        {
719                if( arguments.length > 0 )
720                {
721                        var _element = arguments[0]
722                        var _parent  = _element.parentNode;
723       
724                        _parent.removeChild( _element );
725                }
726        }
727       
728        function removeGroup()
729        {
730                var _parent = arguments[0];
731               
732                if( _parent.childNodes.length <= 2 )
733                        _parent.parentNode.removeChild(_parent);
734        }
735       
736        function renameContact()
737        {
738                if( arguments.length > 0 )
739                {
740                        var _jid        = arguments[0];
741                        var _index      = arguments[1];
742                       
743                        TrophyIM.renameContact( _jid, _index );
744                }
745        }
746       
747        function renameGroup()
748        {
749                if( arguments.length > 0 )
750                {
751                        var _jid        = arguments[0];
752                        var _index      = arguments[1];
753                       
754                        TrophyIM.renameGroup( _jid , _index );
755                }
756        }
757       
758        function rosterDiv()
759        {
760                var _rosterDiv = function()
761                {
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(); }, 200 );
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( i18n.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 = "( " + i18n.TYPE_YOUR_MESSAGE_HERE_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 !=  i18n.TYPE_YOUR_MESSAGE_HERE_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               
940                for(var i = 0 ; i < elementOpenW.options.length; i++)
941                        if( elementOpenW.options[i].selected == true)
942                        {
943                                value = 'preferences1=openWindowJabberit:' + elementOpenW.options[i].value;
944                                _preferencesIM[0] = 'openWindowJabberit:' + elementOpenW.options[i].value;
945                        }
946
947                // Element openWindowJabberitPopUp
948                value += '&preferences2=openWindowJabberitPopUp:false';
949                _preferencesIM[1] = 'openWindowJabberitPopUp:false';
950               
951                // Element flagAwayIM
952                var elementFlagIM = document.getElementById('flagAwayIM');
953               
954                if( elementFlagIM.value.length > 0 && parseInt(elementFlagIM.value) > 0 )
955                {
956                        _preferencesIM[2] = 'flagAwayIM:' + elementFlagIM.value;
957                        value += '&preferences3=flagAwayIM:' + elementFlagIM.value;
958                }
959                else
960                {
961                        alert('Informe um valor igual ou maior que 1!');
962                        return false;
963                }
964
965                // Element showContactsOfflineJabberit
966                var elementShowOffline  = document.getElementById('showContactsOfflineJabberit');
967               
968                for(var i = 0 ; i < elementShowOffline.options.length; i++)
969                        if( elementShowOffline.options[i].selected == true)
970                        {
971                                _preferencesIM[3] = 'showContactsOfflineJabberit:' + elementShowOffline.options[i].value;
972                                value += '&preferences4=showContactsOfflineJabberit:' + elementShowOffline.options[i].value;
973                        }
974               
975                // Save Preferences
976                conn.go('p.pf.setPreferences',
977                                 function(data)
978                                 {
979                                        if( data == 'false' )
980                                        {
981                                                alert('Erro salvando suas preferências!');
982                                        }
983
984                                        _winBuild('jabberit_preferences', 'remove');
985                                 },
986                                 value);
987        }
988       
989        function setPresence()
990        {
991                if( arguments.length > 0 )
992                {
993                        var element = arguments[0];
994                       
995                        if( showhidden == null )
996                                showhidden = new ShowHidden(300);
997                       
998                        var _status = [
999                                               ['Afastado', 'away', '<img src="'+path_jabberit+'templates/default/images/away.gif" />'],
1000                                               ['Disponível', 'available', '<img src="'+path_jabberit+'templates/default/images/available.gif" />'],
1001                                               ['Livre p/ Conversa', 'chat', '<img src="'+path_jabberit+'templates/default/images/chat.gif" />'],
1002                                               ['Não Disponível', 'xa', '<img src="'+path_jabberit+'templates/default/images/xa.gif" />'],
1003                                               ['Ocupado', 'dnd', '<img src="'+path_jabberit+'templates/default/images/dnd.gif" />'],
1004                                               ['Desconectado', 'unavailable', '<img src="'+path_jabberit+'templates/default/images/unavailable.gif" />'],
1005                                               ['Mensagem de Status...', 'status', '<img src="'+path_jabberit+'templates/default/images/message_normal.gif" />'],                                               
1006                                          ];
1007                       
1008                        var _itens = "";
1009                       
1010                        for( var i in _status )
1011                        {
1012                                if( typeof( _status[i]) == "object" )
1013                                {
1014                                        _itens += '<span style="cursor:pointer;" onclick="TrophyIM.setPresence(\''+_status[i][1]+'\'); loadscript.setStatusJabber(\''+_status[i][0]+'\',\''+_status[i][1]+'\');">';
1015                                        _itens += _status[i][2]+ "<span style='margin:3px;'>" + _status[i][0] + "</span></span><br/>";
1016                                }
1017                        }
1018                       
1019                        var _statusItens = document.createElement("div");
1020                                _statusItens.style.marginTop    = "65px";
1021                                _statusItens.style.marginLeft   = "67px";
1022                                _statusItens.className                  = "x-menu";
1023                                _statusItens.style.zIndex               = '99999';
1024                                _statusItens.innerHTML                  = _itens; 
1025                                _statusItens.onclick                    = function(){ showhidden.hiddenObject(false); };
1026                                                                                 
1027                                showhidden.action('onmouseover', 'onmouseout', _statusItens);
1028                               
1029                        element.parentNode.onmouseout   = function(){ showhidden.hiddenObject(false); };
1030                        element.parentNode.onmouseover  = function(){ showhidden.hiddenObject(true); };
1031                        element.parentNode.appendChild(_statusItens);
1032                }
1033        }
1034
1035        function setSelectEditable(element)
1036        {
1037                if( getElement('selectBox0') == null )
1038                        selectEditable.create(element);
1039        }
1040
1041        function setStatusJabber()
1042        {
1043                if( arguments.length > 0 )
1044                {
1045                        if( arguments[1] != 'status' )
1046                        {
1047                                var _text       = arguments[0];
1048                                var _img        = arguments[1];
1049
1050                                getElement('statusJabberText').innerHTML                = _text;
1051                                getElement('statusJabberImg').style.background  = "url('"+path_jabberit+"templates/default/images/"+_img+".gif')";
1052                                getElement('status_jabber_expresso').style.background = "url('"+path_jabberit+"templates/default/images/"+_img+".gif') no-repeat";
1053                        }
1054                }       
1055        }
1056
1057        function _setUserCurrent( _user )
1058        {
1059                userCurrent =
1060                {
1061                        'jid'           : _user.jid.substring(11, _user.jid.length),
1062                        'password'      : _user.password.substring(11, _user.password.length)
1063                }               
1064        }
1065       
1066        function setUserCurrent()
1067        {
1068                if( getUserCurrent() == null )
1069                {
1070                        conn.go('p.ff.data_0',
1071                                                function(_User)
1072                                                {
1073                                                        var _user = _User;
1074                                                       
1075                                                        conn.go('p.ff.data_1',
1076                                                                        function(_pass)
1077                                                                        {
1078                                                                                _setUserCurrent( { jid : _user, password : _pass } );
1079                                                                        });
1080                                                });
1081                }
1082        }
1083
1084        var _stylesheets = [ ];
1085        var _links = document.getElementsByTagName( 'link' );
1086       
1087        for ( var i = 0; i < _links.length; i++ )
1088                if ( _links.item( i ).type && _links.item( i ).type.toLowerCase( ) == 'text/css' )
1089                        _stylesheets[ _stylesheets.length ] = _links.item( i ); 
1090       
1091        function windowPOPUP()
1092        {
1093                var _id = arguments[0];
1094                var _win_name = _id.replace( /\W/g, '' );
1095
1096                if ( arguments.length == 1 )
1097                {
1098                        if ( windowPopUp[_win_name] )
1099                                return true;
1100                        else
1101                                return false;
1102                }
1103               
1104                if( arguments.length == 2 )
1105                {       
1106                        if( !windowPopUp[_win_name] )
1107                        {
1108                                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');
1109                                var tmp = windowPopUp[_win_name].document;
1110                               
1111                                tmp.write('<html><head>');
1112                                tmp.write('</head><body>');
1113                                tmp.write('</body></html>');
1114                                tmp.close();
1115                               
1116                                for ( var i = 0; i < _stylesheets.length; i++ )
1117                                        tmp.documentElement.getElementsByTagName( 'head' ).item(0).appendChild( _stylesheets[ i ].cloneNode( true ) );
1118
1119                                var divPOP = getElement( _id + "__popUp" );
1120                                        divPOP.style.background = "url('"+path_jabberit+"templates/default/images/icon_down.png') no-repeat";
1121                                        divPOP.innerHTML = "PopIn";
1122                                       
1123                                function _close( )
1124                                {
1125                                        windowPopUp[_win_name].close();
1126                                        configEvents( divPOP ,'onclick', _close, true );
1127                                }
1128                                       
1129                                configEvents( divPOP ,'onclick', _close );
1130
1131                                var _content = tmp.documentElement.getElementsByTagName( 'body' ).item(0).appendChild( getElement(_id + '__chatBox' ).parentNode );
1132
1133                                _content.firstChild.scrollTop = _content.firstChild.scrollHeight;
1134
1135                                configEvents( windowPopUp[_win_name] ,'onbeforeunload', function()
1136                                {
1137                                        delete windowPopUp[_win_name];
1138                                        divPOP.style.background = "url('"+path_jabberit+"templates/default/images/icon_up.png') no-repeat";
1139                                        divPOP.innerHTML = "PopUp";
1140                                        divPOP.onclick  = function(){ loadscript.windowPOPUP( _id , true ); };
1141                                        _winBuild( 'window_chat_area_' + _id, "display" ).content( true );
1142                                });
1143
1144                                _winBuild( 'window_chat_area_' + _id, 'hidden' );
1145                        }
1146                }
1147        }
1148       
1149        function loadIM()
1150        {
1151                if( arguments.length > 0 )
1152                {
1153                        var files = [
1154                                                path_jabberit + 'js/connector.js',
1155                                                path_jabberit + 'js/xtools.js',
1156                                                path_jabberit + 'js/lang/i18n_pt_Br.js',
1157                                                path_jabberit + 'js/dragdrop.js',
1158                                                path_jabberit + 'js/makeW.js',
1159                                                path_jabberit + 'js/show_hidden.js',
1160                                                path_jabberit + 'js/trophyim.js',
1161                                                path_jabberit + 'js/strophe.js',
1162                                                path_jabberit + 'js/json2.js',
1163                                                path_jabberit + 'js/AddUser.js',
1164                                                path_jabberit + 'js/SelectEditable.js',
1165                                                path_jabberit + 'templates/default/css/button.css',
1166                                                path_jabberit + 'templates/default/css/common.css',
1167                                                path_jabberit + 'templates/default/css/selectEditableStyle.css',
1168                                                path_jabberit + 'templates/default/css/' + theme_jabberit
1169                                    ];
1170                        // FullName
1171                        fullName = arguments[0];
1172                       
1173                        // Preferences
1174                        _preferencesIM = arguments[1].split(";");
1175                       
1176                        if( !_preferencesIM[3] ) _preferencesIM[3] = "showContactsOfflineJabberit:false";
1177                       
1178                        loadScripts(files);
1179                       
1180                        setTimeout(function()
1181                        {
1182                                // Object Xtools       
1183                                if( Xtools == null )
1184                                        Xtools = new xtools(path_jabberit);
1185                               
1186                                // Object Conector
1187                                if( conn == null )
1188                                        conn = new AjaxConnector(path_jabberit);
1189                               
1190                                // Object Add User
1191                                if( addUser == null )
1192                                        addUser = new addUserIM(Xtools, conn);
1193
1194                               
1195                                // Object SelectEditable
1196                                if( selectEditable == null )
1197                                        selectEditable = new SelectEditable();
1198                                       
1199                                // Add Jabber in StatusBar;
1200                                addIcon();
1201
1202                                // Auto Connect
1203                                setTimeout(function()
1204                                {
1205                                        if( _preferencesIM[0] === 'openWindowJabberit:true' )
1206                                                TrophyIM.load();
1207                                },1500);
1208                               
1209                                // Auto Status
1210                                autoStatus();
1211                                configEvents( document, 'onmousemove', autoStatus );
1212                                configEvents( document, 'onkeypress', autoStatus );
1213                               
1214                        }, 2000);
1215                }
1216        }
1217       
1218        loadIM.prototype.adIcon                         = addIcon;
1219        loadIM.prototype.actionButton           = actionButton;
1220        loadIM.prototype.addContact                     = addContact;
1221        loadIM.prototype.clrAllContacts         = clrAllContacts;
1222        loadIM.prototype.configEvents           = configEvents;
1223        loadIM.prototype.getIsIE                        = getIsIE;
1224        loadIM.prototype.getPhotoUser           = getPhotoUser;
1225        loadIM.prototype.getSmiles                      = getSmiles;
1226        loadIM.prototype.getStatusMessage       = getStatusMessage;
1227        loadIM.prototype.getShowContactsOffline = getShowContactsOffline;
1228        loadIM.prototype.getUserCurrent         = getUserCurrent;
1229        loadIM.prototype.getZIndex                      = getZindex;
1230        loadIM.prototype.groupsHidden           = groupsHidden;
1231        loadIM.prototype.groupsVisible          = groupsVisible;
1232        loadIM.prototype.keyPressSearch         = keyPressSearch;       
1233        loadIM.prototype.loginPage                      = loginPage;
1234        loadIM.prototype.notification           = notificationNewMessage;
1235        loadIM.prototype.parse                          = parse;
1236        loadIM.prototype.preferences            = preferences;
1237        loadIM.prototype.searchUser                     = searchUser
1238        loadIM.prototype.setAutorization        = setAutorization;
1239        loadIM.prototype.setMessageStatus       = setMessageStatus;
1240        loadIM.prototype.setPreferences         = setPreferences;
1241        loadIM.prototype.setPresence            = setPresence;
1242        loadIM.prototype.setStatusJabber        = setStatusJabber;
1243        loadIM.prototype.setSelectEditable      = setSelectEditable;
1244        loadIM.prototype.setUserCurrent         = setUserCurrent;
1245        loadIM.prototype.removeContact          = removeContact;
1246        loadIM.prototype.removeElement          = removeElement;
1247        loadIM.prototype.removeGroup            = removeGroup;
1248        loadIM.prototype.renameContact          = renameContact;
1249        loadIM.prototype.renameGroup            = renameGroup;
1250        loadIM.prototype.rosterDiv                      = rosterDiv;
1251        loadIM.prototype.windowPOPUP            = windowPOPUP;
1252       
1253        window.LoadIM = loadIM;
1254       
1255       
1256        // Necessário para não ocasionar problema no ExpressoMail
1257        // quando os itens abaixo não são criados pelo próprio ExpressoMail
1258        if( is_ie )
1259        {
1260                configEvents( window, 'onload', function( )
1261                {
1262                        if ( ! document.getElementById( 'cc_msg_err_serialize_data_unknown' ) )
1263                        {
1264                                var fix = document.createElement('input');
1265                                        fix.type        = 'hidden';
1266                                        fix.id          = 'cc_msg_err_serialize_data_unknown';
1267                               
1268                                        document.appendChild( fix );
1269                        }
1270                        if ( ! window.showMessage )
1271                                window.showMessage = function(){};
1272                });
1273        }
1274       
1275})();
Note: See TracBrowser for help on using the repository browser.