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

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