source: trunk/instant_messenger/js/im_functions.js @ 64

Revision 64, 25.5 KB checked in by niltonneto, 17 years ago (diff)

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1        function IM()
2        {
3           this._listen     = true;
4           this.vcards      = false;
5           this.labelVcard  = [];
6           this.statusvcard = false;
7           this.UsersNot        = [];
8           this.userPrefe   = false;
9           this.im_time_        = false;
10        }
11
12        IM.prototype.load_im = function()
13        {
14                IM.listen();
15            IM.requireContacts();
16
17            var handler_Status = function(XmlData)
18            {
19                        var data = XmlData.getElementsByTagName('retorno').item(0);
20                        data = data.firstChild.nodeValue;
21                        if( data )
22                        {
23                                statusFlag = data;
24                                setTimeout('IM.ImgStatus("'+data+'")',4000);
25                        }
26            };
27            XMLTools.request('$this.Ujabber.MyPresence', 'GET', handler_Status);
28        };
29
30        IM.prototype.listen = function()
31        {
32           if ( !this._listen )
33              return false;
34
35           var _this = this;
36           var handler = function(data)
37           {
38              try
39              {
40                                if( !_this.userPrefe )
41                                {
42                                        if(window.IM_Preferences)
43                                                IM_Preferences.GetYourPreferences();
44                                }
45
46                    _this.getContacts(data);
47                    _this.getPresence(data);
48                                _this.getComposing(data);
49                    _this.getMessages(data);
50                                _this.getVcard(data);
51
52                if(!_this.vcards)
53                {
54                        _this.requireVcard();
55                        _this.vcards = true;
56                    }
57              }
58              catch(e)
59              {
60                                //alert("listen\n\n" + e + "\n\n" + e.description)
61              }
62              _this._listen = true;
63              setTimeout('IM.listen()', 3000);
64           };
65           this._listen = false;
66           XMLTools.__RETURN_MODE__ = 'XML';
67           XMLTools.request('$this.Ujabber.listen', 'GET', handler);
68        };
69
70   /*
71        *  Contacts
72        */
73
74        IM.prototype.requireContacts = function()
75        {
76           var handler = function(data)
77                {
78                };
79           XMLTools.request('$this.Ujabber.requireContacts', 'GET', handler);
80        };
81
82        IM.prototype.getContacts = function(data)
83        {
84           try
85           {
86              if ( data.getElementsByTagName('contacts').length > 0 )
87              {
88                 var node = data.documentElement.firstChild;
89                 while ( node.nodeName != 'contacts' )
90                        node = node.nextSibling;
91
92                 var div = document.getElementById("div_contacts");
93                 var xsl = XMLTools.load(im_path + 'xsl/contacts.xsl?' + Date.parse(new Date));
94                 var img = document.createElement('img');
95                 img.id  = 'img_all_groups';
96                 img.src = img_group_open.src;
97                 img.onclick = function(){IM.visible_group("all_groups")};
98
99                 var a = document.createElement('div');
100                 a.innerHTML = XMLTools.transform(node, xsl);
101
102                 div.innerHTML = '';
103                 div.appendChild(img);
104                 div.appendChild(document.createTextNode(this.get_lang('List of Contacts')));
105                 div.appendChild(a);
106
107                         var group = func.byId("all_groups").firstChild;
108                         while ( group )
109                 {
110                                        var contact = group.firstChild.nextSibling;
111                                        while ( contact = contact.nextSibling )
112                                        {
113                                                var img = func.newEl('img');
114                                                img.src = img_unavailable.src;
115
116                                                func.insElB(img, func.byId(contact.id).firstChild);
117                                        }
118
119                                        try
120                                        {
121                                                var img = document.createElement('img');
122                                                img.src = img_group_open.src;
123                                                img.id = "img_" + group.id;
124                                                var el_parent = group;
125
126                                                el_parent.insertBefore(img,el_parent.firstChild);
127
128                                        } catch(e){}
129                                        group = group.nextSibling;
130                 }
131                         this.atalho();
132              }
133           }
134           catch (e)
135           {
136              //alert('getContacts()' + e);
137           }
138
139        };
140
141   /*
142        *  Visible / Unvisible
143        */
144
145        IM.prototype.visible_group = function(el)
146        {
147                var _this = this;
148                var divParent = document.getElementById(el);
149                divParent.style.display = "none";
150                var img = document.getElementById("img_" + el);
151                img.onclick = function(){_this.unvisible_group(el)};
152                img.src = img_group_close.src;
153        }
154
155        IM.prototype.unvisible_group = function(el)
156        {
157                var _this = this;
158                var div = document.getElementById(el);
159                div.style.display = "";
160                var img = document.getElementById("img_" + el);
161                img.onclick = function(){_this.visible_group(el)};
162                img.src = img_group_open.src;
163        }
164
165        /*
166         * Presence
167         */
168
169        IM.prototype.getPresence = function(data)
170        {
171           try
172           {
173              var presence = data.documentElement.firstChild;
174                  var _this = this;
175              while ( presence )
176              {
177                      if ( presence.nodeName != 'presence' )
178                      {
179                 presence = presence.nextSibling;
180                         continue;
181                      }
182
183                                var from = presence.getAttribute('from');
184                                var type = presence.getAttribute('type');
185                                if ( presence.hasChildNodes() )
186                                        var status_message = presence.firstChild.nodeValue;
187                                else
188                                        var status_message = false;
189
190                                if( from )
191                                {
192                                 switch ( type )
193                                 {
194                                        case 'subscribe' :
195                                                if ( !func.byId(from) )
196                                                                _this.UsersNot[_this.UsersNot.length] = from;
197                                                        else
198                                                        {
199                                                                Subscription.subscribed(from);
200                                                                this.setStatus(statusFlag);
201                                                        }
202                                                break;
203                                        case 'subscribed' :
204                                                //
205                                        break;
206                                        case 'unsubscribe' :
207                                                Subscription.unsubscribe(from);
208                                                type = 'unavailable';
209                                                func.byId(from).firstChild.src = eval('img_' + type + '.src');
210                                                break;
211                                        case 'unsubscribed' :
212                                                Subscription.unsubscribed(from);
213                                                type = 'unavailable';
214                                                func.byId(from).firstChild.src = eval('img_' + type + '.src');
215                                                break;
216                                        default :
217                                                if ( func.byId(from) )
218                                                {
219                                                        func.byId(from).firstChild.src = eval('img_' + type + '.src');
220                                                        var status;
221
222                                                        if ( (status = func.byId(from + '_im_window')) )
223                                                        {
224                                                                status.firstChild.style.background = 'url('+func.byId(from).firstChild.src+')';
225                                                                        status = func.byId(from + '_im_window_message');
226                                                                if( status_message && status_message != "available" )
227                                                                        status.innerHTML = from.substr(0, from.indexOf('@')) + ' : ' + status_message;
228                                                                else
229                                                                        status.innerHTML = '';
230                                                        }
231
232                                                        if( document.getElementById('status_message_' + from) == null)
233                                                        {
234                                                                var lbl = document.createElement('label');
235                                                                lbl.id = 'status_message_' + from;
236                                                                if(!status_message)
237                                                                        lbl.innerHTML = "";
238                                                                else
239                                                                        if( status_message != "available" )
240                                                                                lbl.innerHTML = "<span style='margin-left:10px'><br/> ( " + status_message + " )</span>";
241                                                                        func.byId(from).appendChild(lbl);
242                                                        }else{
243                                                                        var lbl = document.getElementById('status_message_' + from);
244                                                                if(!status_message)
245                                                                        lbl.innerHTML = "";
246                                                                else
247                                                                        if( status_message != "available" )
248                                                                                lbl.innerHTML = "<span style='margin-left:10px'><br/> ( " + status_message + " )</span>";
249                                                        }
250                                                }
251                                 }
252                                 }
253                            if( _this.UsersNot.length > 0 )
254                                        Templates.Users_Not_Auth(_this.UsersNot);
255                 presence = presence.nextSibling;
256              }
257              _this.Contacts_Offline();
258           }
259           catch(e)
260           {
261           }
262        };
263
264        /*
265         * Contatos - Offline
266         */
267
268        IM.prototype.Contacts_Offline = function()
269        {
270                 var offline = true;
271                 if(IM.userPrefe)
272                        offline = eval(IM_Preferences.LoadPreferences('ch_offline'));
273                 else
274                        offline = eval(IM_Preferences.LoadPreferences('ch_offline'));
275                 var group = func.byId("all_groups").firstChild;
276                 while ( group )
277         {
278                        var contact = group.firstChild.nextSibling;
279                        while ( contact = contact.nextSibling )
280                        {
281                                if(func.byId(contact.id))
282                                {
283                                        var childF = func.byId(contact.id).firstChild;
284                                        if( childF.src == img_unavailable.src && !offline )
285                                                func.byId(contact.id).style.display = "none";
286                                        else
287                                                func.byId(contact.id).style.display = "block";
288                                }
289                        }
290                        group = group.nextSibling;
291         }
292        }
293
294        /*
295         * Get / Send - Messages
296         */
297
298        IM.prototype.getMessages = function(data)
299        {
300           try
301           {
302              data = data.documentElement;
303              if ( data.childNodes.length > 0 )
304              {
305                 var message = data.firstChild;
306                 while ( message )
307                 {
308                    if ( message.tagName == 'messages' )
309                    {
310                       var from = message.getAttribute('from');
311                       with ( from )
312                          from = substr(0, indexOf('/'))
313
314                       if( document.getElementById('vcard_' + from) != null)
315                       {
316                                                var vcards = IM_Preferences.vCardLoad(from);
317                                                var nickname = vcards.substr(vcards.indexOf('NICKNAME'),vcards.length);
318                                                    nickname = nickname.substr(0,nickname.indexOf('|'));
319                                                    nickname = nickname.substr(nickname.indexOf(':') + 1 , nickname.length);
320                                                    nickname = func.trim(nickname);
321                                   }
322
323                       var win = document.getElementById(from + '_chatMessages');
324                       if ( !win )
325                       {
326                          im_win.open_chat(from);
327                          win = document.getElementById(from + '_chatMessages');
328                       }
329
330                       var el = message.firstChild;
331                       while ( el )
332                       {
333                          var xsl = XMLTools.load(im_path + 'xsl/message.xsl?' + Date.parse(new Date));
334                          var next = el.nextSibling;
335
336                          var label = document.createElement('strong');
337                              if(nickname)
338                                  label.appendChild(document.createTextNode(nickname));
339                                          else
340                                  label.appendChild(document.createTextNode(from));
341                          win.appendChild(label);
342                          win.appendChild(document.createElement('br'));
343                          win.innerHTML += XMLTools.transform(el, xsl);
344                          win.innerHTML = this.emotions_icons(win.innerHTML);
345                          win.appendChild(document.createElement('br'));
346                          win.appendChild(document.createElement('br'));
347                          win.scrollTop = win.scrollHeight;
348                                          im_win.newMessageNotification();
349
350                          el = next;
351                       }
352                    }
353
354                                if ( (composing = func.byId(from + '_composing')) )
355                                        if ( composing.style.display = 'block' )
356                                                composing.style.display = 'none';
357
358                    message = message.nextSibling;
359                 }
360              }
361           }
362           catch (e)
363           {
364                        //alert(e.description)
365           }
366        }
367
368        IM.prototype.sendMessage = function (pJID)
369        {
370           var _this = this;
371           var name_document = document.getElementById(pJID + '_edita');
372           var envio = name_document.contentWindow.document.getElementsByTagName('body').item(0);
373
374           envio.innerHTML = func.trim(envio.innerHTML.replace(/^(&nbsp;|<br>| )*|(&nbsp;|<br>| )*$/g, ''));
375
376           if ( envio.innerHTML != "" )
377           {
378              var message_text  = "<div style='";
379              message_text += (envio.style.fontFamily != "") ? "font-family:"+envio.style.fontFamily+";" : "";
380              message_text += (envio.style.fontSize != "") ? "font-size:"+envio.style.fontSize+";" : "" ;
381              message_text += (envio.style.fontWeight != "") ? "font-weight:"+envio.style.fontWeight+";": "";
382              message_text += (envio.style.fontStyle != "" ) ? "font-style:"+envio.style.fontStyle+";" : "";
383              message_text += (envio.style.color != "") ? "color:"+envio.style.color+";" : "color:black";
384              message_text += "'>";
385              message_text += envio.innerHTML + "</div>";
386
387              envio.innerHTML = '';
388
389              var message_element = document.getElementById(pJID + '_chatMessages');
390              var nickname = "me ";
391                  if( IM_Preferences.jid )
392                  {
393                          var vcards = IM_Preferences.vCardLoad(IM_Preferences.jid);
394                          nickname = vcards.substr(vcards.indexOf('NICKNAME'),vcards.length);
395                          nickname = nickname.substr(0,nickname.indexOf('|'));
396                          nickname = nickname.substr(nickname.indexOf(':') + 1 , nickname.length);
397                  }
398
399              message_element.innerHTML += '<strong>' + nickname + ' ';
400              message_element.innerHTML += ' ' + _this.get_lang('speak') + ':</strong><br/>';
401                  message_element.innerHTML += message_text + '<br/>';
402              message_element.scrollTop = message_element.scrollHeight;
403
404              var handler_sendMessage = function(data)
405              {
406                         var data = func.interface(data);
407                 if(!data)
408                    alert(data);
409              }
410                  XMLTools.request('$this.Ujabber.SendMessage','POST',handler_sendMessage,"to="+pJID+"&body="+escape(message_text));
411           }
412        };
413
414        IM.prototype.getComposing = function(data)
415        {
416                if ( data.hasChildNodes() )
417                {
418                        var node = data.documentElement.firstChild;
419                        while ( node )
420                        {
421                                var composing;
422                                if ( node.nodeName == 'composing' )
423                                        if ( (composing = func.byId(node.getAttribute('from') + '_composing')) )
424                                                if ( composing.style.display = 'none' )
425                                                        composing.style.display = 'block';
426
427                                if ( node.nodeName == 'paused' )
428                                        if ( (composing = func.byId(node.getAttribute('from') + '_composing')) )
429                                                if ( composing.style.display = 'block' )
430                                                        composing.style.display = 'none';
431
432                                node = node.nextSibling;
433                        }
434                }
435        };
436
437        /*
438         * Get_lang
439         */
440
441        IM.prototype.get_lang = function(_key, _arg1, _arg2, _arg3, _arg4)
442        {
443           var _value = "";
444
445           if ( !lang_im[_key.toLowerCase()] )
446              return _key + "*";
447
448           _value = lang_im[_key.toLowerCase()];
449
450           if ( _arg1 || _arg2 ||_arg3 || _arg4 )
451           {
452              for (j = 1; j <= 4; j++ )
453                 if( eval("_arg"+j) )
454                 {
455                    var regExp = new RegExp("%" + j + "");
456                    _value = _value.replace(regExp, eval("_arg"+j));
457                 }
458           }
459
460           return _value;
461        };
462
463        IM.prototype.getWinContactsState = function()
464        {
465           try
466           {
467              var win_state = false;
468                  win_state = ( windowItems['contacts'].state == WINDOW_STATE_REGULAR ) ? true : false;
469                  win_state = ( win_state ) ? win_state : ( windowItems['contacts'].state == WINDOW_STATE_MAXIMIZED ) ? true : false;
470              return win_state;
471
472           }catch(e){}
473        };
474
475        IM.prototype.showContacts = function()
476        {
477           if ( this.getWinContactsState() )
478              im_win.windowClose('contacts_im');
479           else
480           {
481              im_win.windowMaximizeRestore('contacts_im');
482              //this.load_im();
483           }
484        };
485
486   /*
487        *  Smiles
488    */
489
490    IM.prototype.emotions_icons = function(pEmotion)
491    {
492       for ( i = 1; i < cod_emotions.length; i++ )
493       {
494          var image = eval('smile_' + i + '.src.substr(smile_' + i + '.src.indexOf(im_path))')
495          pEmotion  = pEmotion.replace(cod_emotions[i], '<img emotion="' + pEmotion + '" src="' + image + '">');
496       }
497
498       return pEmotion;
499    }
500
501        IM.prototype.atalho = function()
502        {
503           if ( (local = func.byId('user_info')) && !(func.byId('myStatus')) )
504           {
505         var aux  = new Array();
506         var _mix = func.newEl('a', 'a', 'img', 'img', 'dl');
507
508         var fast_menu_link  = _mix[0];
509         var contacts_link   = _mix[1];
510         var fast_menu_image = _mix[2];
511         var contacts_image  = _mix[3];
512         var im_fast_menu    = _mix[4];
513
514         fast_menu_link.onclick = function(){IM.showFastMenu();};
515         contacts_link.onclick  = function(){IM.showContacts();};
516
517         aux['fast_menu_image'] = new Array();
518         aux['fast_menu_image']['element'] = fast_menu_image;
519         aux['fast_menu_image']['style']   = 'width:9px;height:9px';
520         aux['fast_menu_image']['src']     = im_path + 'templates/default/images/menuarwopen.gif';
521
522         aux['im_fast_menu'] = new Array();
523         aux['im_fast_menu']['element'] = im_fast_menu;
524         aux['im_fast_menu']['id']      = 'fast_menu_im';
525         aux['im_fast_menu']['class']   = 'menu_im';
526
527         aux['contacts_image'] = new Array();
528         aux['contacts_image']['element'] = contacts_image;
529         aux['contacts_image']['id']      = 'myStatus';
530         aux['contacts_image']['src']     = eval('img_' + statusFlag + '.src');
531         aux['contacts_image']['style']   = 'width:15px;height:15px';
532         func.confEl(aux);
533
534         func.insEl(fast_menu_image, fast_menu_link);
535         func.insEl(contacts_image, contacts_link);
536         func.insElB(fast_menu_link, contacts_link, im_fast_menu, document.createTextNode(' '), local.firstChild);
537           }
538           else
539              setTimeout('IM.atalho()', 5000);
540        };
541
542        /*
543         * Vcard
544         */
545
546        IM.prototype.requireVcard = function()
547        {
548                var _this = this;
549                var handler_getVcard = function(_XMLdata)
550                {
551                        var data = _XMLdata.getElementsByTagName('retorno').item(0);
552                        data = eval(data.firstChild.nodeValue);
553                        if(!data)
554                                setTimeout("IM.requireVcard()",2000);
555                };
556                XMLTools.request('$this.Ujabber.requireVcard','GET',handler_getVcard);
557        }
558
559        IM.prototype.getVcard = function(data)
560        {
561                  var _this = this;
562                  try
563                  {
564                             if ( data.getElementsByTagName('vcard').length > 0  && !_this.statusvcard )
565                             {
566                                 var div = document.getElementById("im_vcard_contacts");
567                                 var xsl = XMLTools.load(im_path + 'xsl/vcard_contacts.xsl?' + Date.parse(new Date));
568                                 _this.statusvcard = true;
569
570                                 div.innerHTML = "";
571                                 div.innerHTML += XMLTools.transform(data, xsl);
572                                 IM_Preferences.vCardInit();
573                                 }
574
575                  }catch(e){}
576
577
578        };
579
580        IM.prototype.open_chat = function(pJID)
581        {
582           im_win.open_chat(pJID);
583        };
584
585        IM.prototype.action_button = function(pEv, pJid)
586        {
587                try
588                {
589                        if ( pEv.button > 1 )
590                        {
591                                var posx = 0;
592                                var posy = 0;
593                                if (pEv.pageX || pEv.pageY)
594                                {
595                                        posx = pEv.pageX;
596                                        posy = pEv.pageY;
597                                }
598                                else if (pEv.clientX || pEv.clientY)
599                                {
600                                        posx = pEv.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
601                                        posy = pEv.clientY + document.body.scrollTop + document.documentElement.scrollTop;
602                                }
603                                this.menu_button_right(pJid, posx, posy);
604                                document.oncontextmenu = new Function("return false");
605                        }
606                        else
607                                if ( func.byId(pJid).firstChild.src != img_unavailable.src )
608                                        this.open_chat(pJid);
609                }
610                catch(e)
611                {
612                        //alert("action_button\n\n" + e)
613                }
614        };
615
616        IM.prototype.menu_button_right = function(pElement, pX, pY)
617        {
618           var form_menu_button_right = '<dl style="z-index:99999">'+
619                                        '<dt><a href="javascript:void(0);" onclick="javascript:IM_Preferences.Update_NickName(\''+pElement+'\');"><img src="'+img_group_close.src+'">' + IM.get_lang('Nick') + '</a>'+
620                                        '<dt><a href="javascript:void(0);" onclick="javascript:IM_Preferences.SendFile(\''+pElement+'\');"><img src="'+img_group_close.src+'">' + IM.get_lang('Send File') + '</a>'+
621                                        '<dt><a href="javascript:void(0);" onclick="javascript:IM_Preferences.Update_Group(\''+pElement+'\');"><img src="'+img_group_close.src+'">' + IM.get_lang('Group') + '</a>'+
622                                        '<dt><a href="javascript:void(0);" onclick="javascript:IM_Preferences.RemoveContact(\''+pElement+'\');"><img src="'+img_group_close.src+'">' + IM.get_lang('Delete') + '</a>'+
623                                                                        '<dt><a href="javascript:void(0);" onclick="javascript:Subscription.RequestAutorization(\''+pElement+'\');"><img src="'+img_group_close.src+'">' + IM.get_lang('(Re)-requisitar Autorização') + '</a>' +                                       
624                                        '<dt><a href="javascript:void(0);" onclick="javascript:IM_Preferences.vCardLoad_Contact(\''+pElement+'\');"><img src="'+img_group_close.src+'">' + IM.get_lang('See Info') + '</a>'+
625                                        '</dl>';
626           im_menu_action.menu('menu_contato', form_menu_button_right);
627           func.byId('menu_contato').style.top = pY-10;
628           func.byId('menu_contato').style.left = pX-10;
629           func.byId('menu_contato').style.zIndex = zValue + 10;
630        };
631
632        /*
633         * Menu
634         */
635
636        IM.prototype.menu_preferences = function()
637        {
638                  var posx = 0;
639                  var posy = 0;
640                  var pEv = arguments[0];
641
642                  if (pEv.pageX || pEv.pageY)
643                  {
644                          posx = pEv.pageX;
645                          posy = pEv.pageY;
646                  }
647                  else if (pEv.clientX || pEv.clientY)
648                  {
649                          posx = pEv.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
650                          posy = pEv.clientY + document.body.scrollTop + document.documentElement.scrollTop;
651                  }
652
653                  var p_element = document.getElementById(arguments[1]);
654                  var _xmlDoc = "";
655                  var _this = this;
656
657                  _xmlDoc = '<menu>' +
658                                                '<item function="IM_Preferences.Add_userLoad()" lang="'+IM.get_lang('Add Contact')+'"/>' +
659                                                '<item function="IM_Preferences.Remove_userLoad()" lang="'+IM.get_lang('Remove Contact')+'"/>' +
660                                                '<item function="IM_Preferences.vCard()" lang="'+IM.get_lang('Information')+'"/>' +
661                                                '<item function="IM_Preferences.yourPreferences()" lang="'+IM.get_lang('preferences')+'"/>' +
662                                        '</menu>';
663
664              im_menu_action.menu(p_element.id,parse_XmlXsl(_xmlDoc,'menu_preferences.xsl'));
665              func.byId(p_element).style.top = posy;
666              func.byId(p_element).style.left = posx;
667              func.byId(p_element).style.zIndex = zValue + 10;
668
669              _this.Load_Images_menu();
670        }
671
672        IM.prototype.Load_Images_menu = function(Element)
673        {
674                try
675                {
676                        var group = document.getElementById("dl_im_menu_preferences");
677                        var Child =  group.childNodes;
678
679                        for(var i = 0; i < Child.length; i++)
680                        {
681                                var img = document.createElement('img');
682                                img.src = img_menu.src;
683                                Child[i].firstChild.insertBefore(img, Child[i].firstChild.firstChild);
684                        }
685                }catch (e){}
686        }
687
688   /*
689        *  Função Provisória - By AlC
690        */
691
692        function parse_XmlXsl(_xmlDoc, form_xsl)
693        {
694                  var xslWin = false;
695
696                  if ( !xslWin ) xslWin = XMLTools.load(im_path + 'xsl/' + form_xsl + '?' + Date.parse(new Date));
697
698                  a = document.createElement('div');
699                  if (window.ActiveXObject)
700                  {
701                     var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
702                     xmlDoc.async = "false";
703                     xmlDoc.loadXML(_xmlDoc);
704                  }
705                  else
706                  {
707                     var parser = new DOMParser();
708                     var xmlDoc = parser.parseFromString(_xmlDoc, "text/xml");
709                  }
710                  a.innerHTML = XMLTools.transform(xmlDoc, xslWin);
711
712                  return a;
713
714        }
715
716   IM.prototype.showFastMenu = function()
717   {
718                 var _dt = func.newEl('dt', 'dt', 'dt', 'dt', 'dt');
719                 var _a  = func.newEl('a', 'a', 'a', 'a', 'a');
720
721                 for ( var i in _dt )
722                 {
723                    if ( typeof _dt[i] == 'function' )
724                       continue;
725                    eval('var option' + (parseInt(i)+1) + ' = _dt[' + i + '];');
726                    eval('var option' + (parseInt(i)+1) + '_link = _a[' + i + '];');
727                 }
728
729                 var _img = func.newEl('img', 'img', 'img', 'img','img');
730
731                 for ( var i in _img )
732                 {
733                    if ( typeof _dt[i] == 'function' )
734                       continue;
735                    eval('var option' + (parseInt(i)+1) + '_image = _img[' + i + '];');
736                 }
737
738                 option1_link.onclick = function(){statusFlag = 'available'; IM.setStatus('available');};
739                 option2_link.onclick = function(){statusFlag = 'xa'; IM.setStatus('xa');};
740                 option3_link.onclick = function(){statusFlag = 'dnd'; IM.setStatus('dnd');};
741                 option4_link.onclick = function(){statusFlag = 'unavailable'; IM.setStatus('unavailable');};
742                 option5_link.onclick = function(){IM.setStatus('custom')};
743
744                 func.confEl(option1_image, 'src', img_available.src);
745                 func.confEl(option1_image, 'style', 'width:16px;height:16px;cursor:pointer;');
746                 func.confEl(option2_image, 'src', img_xa.src);
747                 func.confEl(option2_image, 'style', 'width:16px;height:16px;cursor:pointer;');
748                 func.confEl(option3_image, 'src', img_dnd.src);
749                 func.confEl(option3_image, 'style', 'width:16px;height:16px;cursor:pointer;');
750                 func.confEl(option4_image, 'src', img_unavailable.src);
751                 func.confEl(option4_image, 'style', 'width:16px;height:16px;cursor:pointer;');
752                 func.confEl(option5_image, 'src', img_edit.src);
753                 func.confEl(option5_image, 'style', 'width:16px;height:16px;cursor:pointer;');
754
755                 func.insEl(option1_image, IM.get_lang('online'), option1_link);
756                 func.confEl(option1_link, 'style','cursor:pointer;');
757                 func.insEl(option1_link, option1);
758
759                 func.insEl(option2_image, IM.get_lang('away'), option2_link);
760                 func.confEl(option2_link, 'style','cursor:pointer;');
761                 func.insEl(option2_link, option2);
762
763                 func.insEl(option3_image, IM.get_lang('busy'), option3_link);
764                 func.confEl(option3_link, 'style','cursor:pointer;');
765                 func.insEl(option3_link, option3);
766
767                 func.insEl(option4_image, IM.get_lang('offline'), option4_link);
768                 func.confEl(option4_link, 'style','cursor:pointer;');
769                 func.insEl(option4_link, option4);
770
771                 func.insEl(option5_image, IM.get_lang('Custom message...'), option5_link);
772                 func.confEl(option5_link, 'style','cursor:pointer;');
773                 func.insEl(option5_link, option5);
774
775                 im_menu_action.menu('fast_menu_im', option1, option2, option3, option4, option5);
776   };
777
778   IM.prototype.setStatus = function(pStatus)
779   {
780      try
781      {
782              var handler = function()
783              {
784              };
785              im_menu_action.menu('fast_menu_im', null);
786
787              if ( pStatus == 'custom' )
788              {
789                pStatus = prompt('Personalize seu Status : ');
790                pStatus = 'show=' + statusFlag + '&status=' + pStatus;
791              }
792              else
793              {
794                if ( pStatus == 'unavailable' )
795                {
796                                this.ImgStatus(pStatus);
797                        pStatus = 'type=' + pStatus;
798                }
799                else
800                {
801                 try
802                 {
803                                this.ImgStatus(pStatus);
804                                pStatus = 'show=' + pStatus;
805                 }
806                 catch(e){}
807                 }
808              }
809                  XMLTools.request('$this.Ujabber.setPresence', 'POST', handler, pStatus);
810          }
811          catch(e){}
812   };
813
814   IM.prototype.ImgStatus = function(pStatus)
815   {
816                var myStatus;
817                if ( (myStatus = func.byId('myStatus')) )
818                        myStatus.src = eval('img_' + pStatus + '.src');
819   };
820
821   IM.prototype.setAway = function()
822   {
823      if ( statusFlag != 'available' )
824         return false;
825
826      if ( awayFlag )
827      {
828             this.setStatus('available');
829         awayFlag = false;
830      }
831      else
832      {
833         this.setStatus('xa');
834         awayFlag = true;
835      }
836   };
837
838   IM.prototype.infoContact = function(pUid)
839   {
840      var info = false;
841      var div_allg = document.getElementById('all_groups');
842      var elements = div_allg.firstChild;
843      while ( elements )
844      {
845         var childs = elements.firstChild;
846         while( childs )
847         {
848            if(childs.tagName == "DIV" && childs.id.indexOf(pUid) === 0 )
849            {
850               info = {'jid':childs.id, 'src':childs.firstChild.src};
851               break;
852            }
853            childs = childs.nextSibling;
854         }
855         if ( !info )
856            elements = elements.nextSibling;
857         else
858            break;
859      }
860      return info;
861   };
862
863var IM = new IM();
Note: See TracBrowser for help on using the repository browser.