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

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