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

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