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

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