source: trunk/instant_messenger/js/jabber.js @ 321

Revision 321, 21.3 KB checked in by niltonneto, 16 years ago (diff)

Correçoes

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