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

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