source: tags/instant_messenger/js/jabber.js @ 337

Revision 337, 21.8 KB checked in by niltonneto, 16 years ago (diff)
Line 
1(function()
2{
3        var _conn;
4        var _xtools;
5        var _window;
6        var _ldap;
7        var _menu;
8        var _cookies;
9
10        var _vcards = [];
11        var _info = [];
12        var _chats = [];
13
14        var _win_position = 0;
15
16        function _next_position()
17        {
18                if ( _win_position > 200 )
19                        _win_position = 0;
20                return (_win_position += 30);
21        }
22
23        function _chat(_pJid)
24        {
25                if ( !_chats[_pJid] )
26                        _chats[_pJid] = [];
27
28                var _win_pos = _next_position();
29                var _win_chat = _window.load('chat' + _pJid);
30                        _win_chat.title('.::Expresso Messenger::.');
31                        _win_chat.size(310);
32                        _win_chat.content(_xtools.parse('chat.xsl'));
33                        _win_chat.position(_win_pos, _win_pos);
34                        _win_chat.wc.style.padding = "3px";
35                        _win_chat.bz.style.display = 'none';
36
37                _ldap.photo(
38                        _pJid.substr(0,_pJid.indexOf('@')),
39                        _win_chat.wc.childNodes[2]
40                );
41
42                var _iframe = top.document.createElement('iframe');
43                        _iframe.id = 'iframe_' + _pJid;
44
45                _win_chat.wc.childNodes[2].appendChild(_iframe);
46
47                _iframe.style.width = '250px';
48                _iframe.style.height = '100%';
49                _iframe.style.border = '0';
50                _iframe.style.margin = '0';
51
52                var _contentWindow = _iframe.contentWindow;
53
54                _iframe = _contentWindow.document;
55                _iframe.write('<html><body style="padding:0;margin:0;"></body></html>');
56                _iframe.close();
57                _iframe.designMode = "On";
58
59                _contentWindow.focus();
60
61                _config(
62                        _win_chat.wc.childNodes[1].childNodes[5],
63                        'onclick',
64                        function()
65                        {
66                                _info[_pJid] = true;
67                                _vcard(_pJid);
68                        }
69                );
70
71                _config(
72                        _win_chat.wc.childNodes[1].lastChild.previousSibling,
73                        'onclick',
74                        function()
75                        {
76                                _sendMessage(
77                                        _pJid,
78                                        _iframe,
79                                        _win_chat.wc.firstChild
80                                );
81                                _iframe.body.innerHTML = '';
82                                _contentWindow.focus();
83                        }
84                );
85
86                var _composing_paused = null;
87                function _execKeyAction(e)
88                {
89                        if ( e.type.indexOf('keydown') != -1 )
90                        {
91                                if ( (e.keyCode > 48 && e.keyCode < 112) || e.keyCode > 186 )
92                                {
93                                        if ( _chats[_pJid]['composing_paused'] )
94                                        {
95                                                clearTimeout(_chats[_pJid]['composing_paused']);
96                                                _chats[_pJid]['composing_paused'] = null;
97                                        }
98                                        else
99                                                _conn.go('t.composing','jid='+_pJid);
100
101                                        _chats[_pJid]['composing_paused'] = setTimeout(
102                                        function()
103                                        {
104                                                if ( _chats[_pJid]['composing_paused'] )
105                                                {
106                                                        clearTimeout(_chats[_pJid]['composing_paused']);
107                                                        _chats[_pJid]['composing_paused'] = null;
108                                                }
109                                                _conn.go('t.paused','jid='+_pJid);
110                                        }, 5000);
111                                }
112                        }
113                        switch ( e.keyCode )
114                        {
115                                case 13 :
116                                        if ( !(e.shiftKey) )
117                                        {
118                                                if ( e.type.indexOf('keydown') != -1 )
119                                                {
120                                                        if ( _chats[_pJid]['composing_paused'] )
121                                                        {
122                                                                clearTimeout(_chats[_pJid]['composing_paused']);
123                                                                _chats[_pJid]['composing_paused'] = null;
124                                                        }
125
126                                                        _sendMessage(
127                                                                _pJid,
128                                                                _iframe,
129                                                                _win_chat.wc.firstChild
130                                                        );
131                                                }
132                                                else
133                                                        _iframe.body.innerHTML = '';
134
135                                                return false;
136                                        }
137                                break;
138                                case 27 :
139                                        if ( e.type.indexOf('keyup') != -1 )
140                                        {
141                                                if ( _chats[_pJid]['composing_paused'] )
142                                                {
143                                                        clearTimeout(_chats[_pJid]['composing_paused']);
144                                                        _chats[_pJid]['composing_paused'] = null;
145                                                }
146                                                _win_chat.button(_win_chat.bc);
147                                        }
148                                break;
149                        }
150                }
151                _config(_contentWindow.document, 'onkeyup', _execKeyAction);
152                _config(_contentWindow.document, 'onkeydown', _execKeyAction);
153
154                if ( !(_vcards[_pJid]) )
155                        _conn.go('$this.Ujabber.getVcard','jid='+_pJid);
156                else
157                        _readVCard(_vcards[_pJid]);
158
159                return _win_chat;
160        }
161
162        function _config(pObj, pEvent, pHandler)
163        {
164                if ( typeof pObj == 'object' )
165                {
166                        if ( pEvent.substring(0, 2) == 'on' )
167                                pEvent = pEvent.substring(2, pEvent.length);
168
169                        if ( pObj.addEventListener )
170                                pObj.addEventListener(pEvent, pHandler, false);
171                        else if ( pObj.attachEvent )
172                                pObj.attachEvent('on' + pEvent, pHandler);
173                }
174        }
175
176        function _openChat(el)
177        {
178                var id = el.getAttribute('jid');
179
180                if ( id.indexOf('/') > -1 )
181                        id = id.substr(0, id.indexOf('/'));
182
183                var _win = _window.get('chat' + id);
184                if ( !_win )
185                {
186                        _win = _chat(id);
187                        _win.title(el.getAttribute('idname'));
188                        if ( el.getAttribute('status') )
189                                _win.icon(eval('im_' + el.getAttribute('status') + '.src'));
190                }
191                else
192                {
193                        _win.wm.style.display = 'block';
194                        _win.focus();
195                        _win.wc.childNodes[2].firstChild.contentWindow.focus();
196                }
197        }
198
199        function _readContacts(_pContacts)
200        {
201                var _win_contact = _window.get('contact_list');
202                if ( !_win_contact )
203                {
204                        _win_contact = _window.load('contact_list');
205                        _win_contact.hidden();
206                        _win_contact.title('.::Expresso Messenger::.');
207                        _win_contact.size(170, 350);
208                        _win_contact.position(30, 30, true);
209                        _win_contact.icon(im_unavailable.src);
210                        _win_contact.bc.style.display = 'none';
211                }
212
213                var _params = {
214                        'lang1':imGetLang('nickname'),
215                        'lang2':imGetLang('add contact'),
216                        'lang3':imGetLang('preferences'),
217                        'nickname':imGetLang('username')
218                };
219                _win_contact.content(
220                        _xtools.parse(_xtools.xml('layer'),'layer.xsl', _params)
221                        + _xtools.parse(_pContacts, 'contacts.xsl', {'path':path_im})
222                );
223
224                _config(_win_contact.wc.firstChild.childNodes[5], 'onclick', _ldap.add);
225
226                var _contact_list = top.document.getElementById('im_contact_list');
227                if ( _contact_list )
228                {
229                        var _presence;
230                        if ( !(_presence = _cookies.get('IM_presence')) )
231                                _presence = 'available';
232
233                        var _img_status = eval('im_' + _presence + '.src');
234
235                        if ( _img_status )
236                        {
237                                _win_contact.icon(_img_status);
238
239                                var _status = top.document.getElementById('im_status');
240                                if ( _status )
241                                        _status.style.backgroundImage = 'url(' + _img_status + ')';
242                        }
243
244                        _ldap.photo('im_avatar', _win_contact.wc.firstChild);
245
246                        function _click(e)
247                        {
248                                var el = ( e.target ) ? e.target : e.srcElement;
249                                if ( (e.button == 0 && !document.all) || (e.button == 1 && document.all) )
250                                        _openChat(el);
251                                else
252                                {
253                                        var _options = [
254                                                imGetLang("Nickname"),
255                                                imGetLang("Group"),
256                                                imGetLang("Remove"),
257                                                imGetLang("It requisition permission"),
258                                                imGetLang("See Info")
259                                        ];
260
261                                        var _style_text = 'background: no-repeat url(' + path_im
262                                                                + 'templates/default/images/group_close.gif);'
263                                                                + 'padding:2px 4px 2px 16px;';
264
265                                        var _xml = _xtools.xml('menu');
266                                        var _option;
267                                        var _item;
268                                        var _action;
269                                        var _style;
270
271                                        for ( var i in _options )
272                                        {
273                                                _option = _xml.createElement('option');
274
275                                                _item = _xml.createElement('item');
276                                                _item.appendChild(_xml.createTextNode(_options[i]));
277
278                                                _style = _xml.createElement('style');
279                                                _style.appendChild(_xml.createTextNode(_style_text));
280
281                                                _option.appendChild(_item);
282                                                _option.appendChild(_style);
283
284                                                _xml.documentElement.appendChild(_option);
285                                        }
286
287                                        var _sub_menu = top.document.getElementById('sub_' + el.getAttribute('jid'));
288                                                _sub_menu.innerHTML = _xtools.parse(_xml, 'options.xsl');
289
290                                        _menu.action('onmouseover', 'onmouseout', _sub_menu);
291
292                                        _sub_menu = _sub_menu.firstChild;
293                                        _sub_menu.childNodes[0].style.display = 'none';
294                                        _sub_menu.childNodes[1].style.display = 'none';
295                                        _sub_menu.childNodes[3].style.display = 'none';
296                                        _config(
297                                                _sub_menu.childNodes[2],
298                                                'onclick',
299                                                function(e)
300                                                {
301                                                        var el = ( e.target ) ? e.target : e.srcElement;
302                                                        var jid = el.parentNode.parentNode.id.substr(4);
303                                                        var _contact = el.parentNode.parentNode.previousSibling;
304                                                        _contact.parentNode.removeChild(_contact.nextSibling);
305                                                        _contact.parentNode.removeChild(_contact);
306                                                        _conn.go('$this.Ujabber.removeContact','jid='+jid);
307                                                }
308                                        );
309                                        _config(
310                                                _sub_menu.childNodes[4],
311                                                'onclick',
312                                                function()
313                                                {
314                                                        _info[el.getAttribute('jid')] = true;
315                                                        _vcard(el.getAttribute('jid'));
316                                                }
317                                        );
318                                }
319                        }
320                        function _show_hidden_group(e)
321                        {
322                                var el = ( e.target ) ? e.target : e.srcElement;
323                                var _display = "none";
324                                var _image = im_group_close.src;
325
326                                if ( el.style.backgroundImage.indexOf('group_open') < 0 )
327                                {
328                                        _display = "block";
329                                        _image = im_group_open.src;
330                                }
331
332                                el.style.backgroundImage = 'url(' + _image + ')';
333
334                                el = el.nextSibling;
335                                while ( el.getAttribute('jid') )
336                                {
337                                        if ( _display == 'block' )
338                                        {
339                                                var _show_all = _cookies.get('IM_unavailable');
340                                                if ( (el.style.backgroundImage.indexOf('unavailable') > -1) && (_show_all == 'hidden') )
341                                                        _display = 'none';
342                                        }
343                                        el.style.display = _display;
344                                        el = el.nextSibling;
345                                        if ( el && el.nextSibling )
346                                                el = el.nextSibling;
347                                }
348                        }
349                        function _hover(e)
350                        {
351                                var el = ( e.target ) ? e.target : e.srcElement;
352                                var color = "#fff";
353                                if ( e.type.indexOf('mouseover') != -1 )
354                                        color = "#b4cfe5";
355                                el.style.backgroundColor = color;
356                        }
357                        var _contact = _contact_list.firstChild;
358                        var _show_all = _cookies.get('IM_unavailable');
359                        while ( _contact )
360                        {
361                                if ( _contact.nodeName.toLowerCase() == 'div' )
362                                {
363                                        _config(_contact, 'onmouseover', _hover);
364                                        _config(_contact, 'onmouseout', _hover);
365                                        // it is a group
366                                        if ( !(_contact.getAttribute('jid')) )
367                                                _config(_contact, 'onclick', _show_hidden_group);
368                                        // it is a contact
369                                        else
370                                        {
371                                                if ( _show_all != 'hidden' )
372                                                        _contact.style.display = 'block';
373                                                _config(_contact, 'onmouseup', _click);
374                                        }
375                                }
376                                _contact = _contact.nextSibling;
377                        }
378                }
379        }
380
381        function _setPresence()
382        {
383                if ( !(_cookies) )
384                        return false;
385
386                var _presence = false;
387                var _pPresence;
388                if ( arguments.length == 0 )
389                {
390                        if ( !(_pPresence = _cookies.get('IM_presence')) )
391                                _pPresence = 'available';
392                }
393                else
394                        _pPresence = arguments[0];
395
396                if ( _pPresence == 'auto' )
397                {
398                        if ( _cookies.get('IM_presence') == 'available' )
399                                _pPresence = 'xa';
400                }
401                else
402                        _cookies.set('IM_presence', _pPresence);
403
404                switch ( _pPresence )
405                {
406                        case 'away':
407                        case 'dnd':
408                        case 'xa':
409                                _presence = 'show=' + _pPresence;
410                        break;
411                        case 'available':
412                        case 'unavailable':
413                                _presence = 'type=' + _pPresence;
414                        break;
415                }
416
417                if ( _presence )
418                {
419                        var _img_status = eval('im_' + _pPresence + '.src');
420
421                        var _status = top.document.getElementById('im_status');
422                        if ( _status )
423                                _status.style.backgroundImage = 'url(' + _img_status + ')';
424
425                        var _win_contacts = _window.get('contact_list');
426                        if ( _win_contacts )
427                                _win_contacts.icon(_img_status);
428
429                        _conn.go('$this.Ujabber.setPresence', _presence);
430                }
431        }
432
433        function _vcard(_pJid)
434        {
435                var _win_vcard;
436                if ( !(_win_vcard = _window.get('vcard_' + _pJid)) )
437                {
438                        var _win_pos = _next_position();
439
440                        _win_vcard = _window.load('vcard_' + _pJid);
441                        _win_vcard.title('.:: ' + imGetLang('Information Contacts') + ' ::.');
442                        _win_vcard.size(300);
443                        _win_vcard.position(_win_pos, _win_pos);
444
445                        _win_vcard.wc.style.padding = "3px";
446                        _win_vcard.bx.style.display = "none";
447                }
448                else
449                        _win_vcard.focus();
450
451                if ( _vcards[_pJid] )
452                {
453                        if ( _info[_pJid] )
454                                delete _info[_pJid];
455
456                                var _params = {
457                                        'fullname' : imGetLang('Full Name'),
458                                        'nickname' : imGetLang('Nickname'),
459                                        'organization' : imGetLang('Organization'),
460                                        'sector' : imGetLang('Sector'),
461                                        'role' : imGetLang('Role'),
462                                        'birthday' : imGetLang('Birthday')
463                                };
464
465                                _win_vcard.content(
466                                        _xtools.parse(
467                                                _vcards[_pJid],
468                                                'vcard_contacts.xsl',
469                                                _params
470                                        )
471                                );
472                }
473                else
474                {
475                        _win_vcard.loading();
476                        _conn.go('$this.Ujabber.getVcard', 'jid='+_pJid);
477                }
478        }
479
480        function _readVCard(_pVCard)
481        {
482                _vcards[_pVCard.getAttribute('from')] = _pVCard;
483
484                switch ( _pVCard.getAttribute('id') )
485                {
486                        case "vCard_user" :
487                                var _layer_nickname = top.document.getElementById('im_layer_nickname');
488                                var _nickname = _pVCard.getElementsByTagName('NICKNAME');
489
490                                if ( _nickname.length && _layer_nickname )
491                                        _layer_nickname.innerHTML = _nickname[0].firstChild.nodeValue;
492                        break;
493                        case "vCard" :
494                                if ( _info[_pVCard.getAttribute('from')] )
495                                        _vcard(_pVCard.getAttribute('from'));
496                        break;
497                }
498        }
499
500        function _readIq(pIq)
501        {
502                switch ( pIq.getAttribute('id') )
503                {
504                        case 'contacts' :
505                                _readContacts(pIq);
506                        break;
507                        case 'vCard' :
508                        case 'vCard_user' :
509                                _readVCard(pIq);
510                        break;
511                        case 'last_time_user' :
512                                _readLastTimeUser(pIq);
513                        break;
514                        default : //alert('readIq : ' + pIq.getAttribute('id'));
515                }
516        }
517
518        function _readLastTimeUser(pIq)
519        {
520                if ( pIq.firstChild.getAttribute("seconds") != 0 )
521                        _conn.go('t.update');
522        }
523
524        function _readMessage(_pMessage)
525        {
526                var _from = _pMessage.getAttribute('from');
527
528                if ( _from.indexOf('/') > -1 )
529                        _from = _from.substr(0, _from.indexOf('/'));
530
531                var _contact_list = top.document.getElementById('contact_' + _from);
532
533                var _win = _window.get('chat' + _from);
534
535                if ( _contact_list && _pMessage.getElementsByTagName('composing').length > 0 )
536                {
537                        _contact_list.style.backgroundImage = 'url(' + im_composing.src + ')';
538                        setTimeout(function()
539                        {
540                                _contact_list.style.backgroundImage = 'url(' + eval('im_' + _contact_list.getAttribute('status') + '.src') + ')';
541                        }, 10000);
542                }
543
544                if ( _win && _pMessage.getElementsByTagName('composing').length > 0 )
545                {
546                        _win.wc.childNodes[1].lastChild.style.display = 'block';
547                        setTimeout(function(){_win.wc.childNodes[1].lastChild.style.display = 'none';}, 10000);
548                }
549
550                if ( _pMessage.getElementsByTagName('body').length > 0 )
551                {
552                        if ( !_win )
553                        {
554                                _win = _chat(_from);
555                                var _st = top.document.getElementById('contact_' + _from);
556                                if ( _st )
557                                {
558                                        _st = eval('im_' + _st.getAttribute('status') + '.src');
559                                        _win.icon(_st);
560                                }
561                        }
562                        _win.show();
563
564                        var _nickname;
565                        if ( _vcards[_from] )
566                        {
567                                _nickname = _vcards[_from].getElementsByTagName('NICKNAME');
568                                if ( _nickname.length )
569                                        _nickname = _nickname[0].firstChild.nodeValue;
570                                else
571                                        _nickname = _from;
572                        }
573                        else
574                                _nickname = _from;
575
576                        var _msg = _xtools.parse(_pMessage, 'message_new.xsl', {'nickname':_nickname,'time':Date().substr(16,5)});
577
578                        var _history = _win.wc.firstChild;
579                        if ( _history.scrollHeight == (_history.scrollTop + _history.clientHeight) )
580                        {
581                                _history.innerHTML += _msg;
582                                _history.scrollTop = _history.scrollHeight;
583                        }
584                        else
585                                // this "else" is to prevent the creation of a flag and the need to use another conditional
586                                _history.innerHTML += _msg;
587
588                        _win.wc.childNodes[1].lastChild.style.display = 'none';
589                        if ( _contact_list )
590                                _contact_list.style.backgroundImage = 'url(' + eval('im_' + _contact_list.getAttribute('status') + '.src') + ')';
591                }
592
593                if ( _contact_list && _pMessage.getElementsByTagName('paused').length > 0 )
594                        _contact_list.style.backgroundImage = 'url(' + eval('im_' + _contact_list.getAttribute('status') + '.src') + ')';
595
596                if ( _win && _pMessage.getElementsByTagName('paused').length > 0 )
597                        _win.wc.childNodes[1].lastChild.style.display = 'none';
598        }
599
600        function _readPresence(_pPresence)
601        {
602                var _from = _pPresence.getAttribute('from');
603                if ( _from.indexOf('/') > -1 )
604                        _from = _from.substr(0, _from.indexOf('/'));
605
606                var _presence_type = _pPresence.getAttribute('type');
607                var _img_status_contact = top.document.getElementById('contact_' + _from);
608                var _mensagem_status_contact = top.document.getElementById('status_' + _from);
609                var _win_chat = _window.get('chat' + _from);
610
611                if ( _mensagem_status_contact )
612                {
613                        _mensagem_status_contact.innerHTML = '';
614                        _mensagem_status_contact.style.display = 'none';
615                }
616
617                if ( _presence_type )
618                {
619                        switch( _presence_type )
620                        {
621                                case 'available' :
622                                case 'unavailable' :
623                                        _img_status_contact.setAttribute('status', _presence_type);
624
625                                        if ( _img_status_contact )
626                                                _img_status_contact.style.backgroundImage = 'url(' + eval('im_' + _presence_type + '.src') + ')';
627                                        if ( _win_chat )
628                                                _win_chat.icon(eval('im_' + _presence_type + '.src'));
629                                        if ( _presence_type == 'unavailable' )
630                                        {
631                                                var _show_all = _cookies.get('IM_unavailable');
632                                                if ( _show_all == 'hidden' )
633                                                        _img_status_contact.style.display = 'none';
634                                        }
635                                        else
636                                                _img_status_contact.style.display = 'block';
637                                break;
638                                case 'subscribe' :
639                                        if ( top.document.getElementById('contact_' + _from) )
640                                        {
641                                                _conn.go('$this.Ujabber.subscription', 'jid=' + _from + '&type=subscribed' );
642                                        }
643                                        else
644                                        {
645                                                if ( !_window.get('subscription' + _from) )
646                                                {
647                                                        var _win_pos = _next_position();
648                                                        var _win_subscription = _window.load('subscription' + _from);
649                                                                _win_subscription.title('.::Expresso Messenger::.');
650                                                                _win_subscription.position(_win_pos, _win_pos);
651                                                                _win_subscription.size(200);
652                                                                _win_subscription.wc.style.padding = "3px";
653                                                                _win_subscription.bc.style.display = 'none';
654                                                                _win_subscription.bx.style.display = 'none';
655                                                                _win_subscription.bz.style.display = 'none';
656
657                                                        var _params = {
658                                                                'jid' : _from,
659                                                                'lang1' : 'deseja adiciona-lo como contato.',
660                                                                'lang2' : imGetLang('nickname'),
661                                                                'lang3' : imGetLang('group'),
662                                                                'lang4' : imGetLang('allow'),
663                                                                'lang5' : imGetLang('deny')
664                                                        };
665
666                                                        _win_subscription.content(
667                                                                _xtools.parse(_xtools.xml('subscribe'), 'subscribe.xsl', _params)
668                                                        );
669
670                                                        _win_subscription.wc.childNodes[2].style.margin = '5px';
671                                                        _win_subscription.wc.childNodes[3].style.margin = '5px';
672
673                                                        _config(
674                                                                _win_subscription.wc.childNodes[2],
675                                                                'onclick',
676                                                                function()
677                                                                {
678                                                                        _win_subscription.wc.childNodes[1].style.display = 'block';
679                                                                        _win_subscription.size(450);
680                                                                        _config(
681                                                                                _win_subscription.wc.childNodes[2],
682                                                                                'onclick',
683                                                                                function()
684                                                                                {
685
686                                                                                        var _status = top.document.getElementById('im_status_add_' + _from);
687                                                                                        var _name = top.document.getElementById('im_name_' + _from);
688                                                                                        var _group = top.document.getElementById('im_group_' + _from);
689
690                                                                                        _name.value = _name.value.replace(/^( )*|( )*$/g, '');
691                                                                                        _group.value = _group.value.replace(/^( )*|( )*$/g, '');
692
693                                                                                        if ( !(_name.value) || !(_group.value) )
694                                                                                        {
695                                                                                                _status.innerHTML = '<br/>O campo destacado em vermelho é obrigatório!<br/>';
696
697                                                                                                if ( !(_name.value) )
698                                                                                                {
699                                                                                                        _name.previousSibling.style.color = "#f00";
700                                                                                                        _status.innerHTML += '<br/>** Informe um "NOME" para o contato.';
701                                                                                                }
702
703                                                                                                if ( !(_group.value) )
704                                                                                                {
705                                                                                                        _group.previousSibling.style.color = "#f00";
706                                                                                                        _status.innerHTML += '<br/>** Informe um "GRUPO" para o contato.';
707                                                                                                }
708                                                                                        }
709                                                                                        else
710                                                                                        {
711                                                                                                _status.innerHTML = '<br/>Adicionado contanto, aguarde.<br/>';
712
713                                                                                                _conn.go(
714                                                                                                        '$this.Ujabber.allowContact',
715                                                                                                        function()
716                                                                                                        {
717                                                                                                                _status.innerHTML = '<br/>Contato autorizado com "SUCESSO"!<br/>';
718                                                                                                                _win_subscription.button(_win_subscription.bc);
719                                                                                                        },
720                                                                                                        'uid='+_from.substr(0,_from.indexOf('@'))+'&name='+_name.value+'&group='+_group.value
721                                                                                                );
722
723                                                                                                _name.value = '';
724                                                                                                _group.value = '';
725                                                                                        }
726                                                                                }
727                                                                        );
728                                                                }
729                                                        );
730                                                }
731                                        }
732                                break;
733                                case 'unsubscribe' :
734                                case 'unsubscribed' :
735                                        _conn.go('$this.Ujabber.removeContact','jid=' + _from);
736                                break;
737                                default : //alert('readPresence : ' + _presence_type);
738                        }
739                }
740                else
741                {
742                        var _node = _pPresence.firstChild;
743                        while( _node )
744                        {
745                                if ( _node.hasChildNodes() )
746                                {
747                                        _img_status_contact.style.display = 'block';
748                                        switch ( _node.nodeName )
749                                        {
750                                                case "show" :
751                                                        var _show = _node.firstChild.nodeValue;
752                                                        _img_status_contact.setAttribute('status', _show);
753                                                        if ( _img_status_contact )
754                                                                _img_status_contact.style.backgroundImage = 'url(' + eval('im_' + _show + '.src') + ')';
755                                                        if ( _win_chat )
756                                                                _win_chat.icon(eval('im_' + _show + '.src'));
757                                                break;
758                                                case "status" :
759                                                        if ( _mensagem_status_contact )
760                                                        {
761                                                                if ( _node.firstChild.nodeValue )
762                                                                        _mensagem_status_contact.innerHTML = _node.firstChild.nodeValue;
763                                                                _mensagem_status_contact.style.display = 'block';
764                                                        }
765                                                break;
766                                                default :
767                                                        _img_status_contact.setAttribute('status', 'available');
768                                                        if ( _img_status_contact )
769                                                                _img_status_contact.style.backgroundImage = 'url(' + im_available.src + ')';
770                                                        if ( _win_chat )
771                                                                _win_chat.icon(im_available.src);
772                                        }
773                                }
774                                _node = _node.nextSibling;
775                        }
776                }
777        }
778
779        function _sendMessage(_pJid, _pMessage, _pHistory)
780        {
781                var m1 = _pMessage = _pMessage.body.innerHTML;
782                var m2 = _pMessage = _pMessage.replace(/(&nbsp;)+|( )+/ig, ' ');
783                var m3 = _pMessage = _pMessage.replace(/(<br[^>]*>)+/ig, '<br/>');
784                var m4 = _pMessage = _pMessage.replace(/^( )+|( )+$|^(<br\/>)|(<br\/>)$/g, '');
785
786                //_pMessage = _pMessage.replace(/( )+(<br[^>]*>)+/g, '<br/>');
787                //_pMessage = _pMessage.replace(/(<br[^>]*>)*( )+(<br[^>]*>)+/g, '');
788                //_pMessage = _pMessage.replace(/^(<br[^>]*>)*|(<br[^>]*>)*$/g, '');
789
790                if ( _pMessage != '' )
791                {
792                        _conn.go('$this.Ujabber.sendMessage', "to=" + _pJid + "&body=" + escape(_pMessage));
793
794                        if ( _pHistory.scrollHeight == (_pHistory.scrollTop + _pHistory.clientHeight) )
795                        {
796                                _pHistory.innerHTML += '<b>' + imGetLang('says') + ':</b><br/>' + _pMessage + '<br/><br/>';
797                            _pHistory.scrollTop = _pHistory.scrollHeight;
798                        }
799                        else
800                        // this "else" is to prevent the creation of a flag and the need to use another conditional
801                                _pHistory.innerHTML += '<b>' + imGetLang('says') + ':</b><br/>' + _pMessage + '<br/><br/>';
802                }
803        }
804
805        function _action(_pAction)
806        {
807                //alert ( typeof pAction + "\n\n" + pAction.nodeName )
808                if ( typeof _pAction == 'object' && _pAction.nodeName )
809                {
810                        switch ( _pAction.nodeName )
811                        {
812                                case 'iq' :
813                                        _readIq(_pAction);
814                                break;
815                                case 'message' :
816                                        _readMessage(_pAction);
817                                break;
818                                case 'presence' :
819                                        _readPresence(_pAction);
820                                break;
821                                //default : alert('action : ' + _pAction.nodeName);
822                        }
823                }
824        }
825
826        function Jabber()
827        {
828                _conn = arguments[0];
829                _xtools = arguments[1];
830                _window = arguments[2];
831                _ldap = arguments[3];
832                _menu = arguments[4];
833                _cookies = arguments[5];
834        }
835
836        Jabber.prototype.action = _action;
837        Jabber.prototype.setPresence = _setPresence;
838        window.Jabber = Jabber;
839        window.InstantMessengerPresence = _setPresence;
840}
841)();
Note: See TracBrowser for help on using the repository browser.