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 *
RevLine 
[55]1        function IM()
2        {
3           this.vcards      = false;
4           this.labelVcard  = [];
5           this.statusvcard = false;
6           this.UsersNot        = [];
7           this.userPrefe   = false;
[68]8           this.count_Vcard = 0;
[55]9        }
[64]10
[55]11        IM.prototype.load_im = function()
12        {
[68]13                this.listen();
14            this.requireContacts();
15            this.atalho();
[64]16
[55]17            var handler_Status = function(XmlData)
18            {
19                        var data = XmlData.getElementsByTagName('retorno').item(0);
20                        data = data.firstChild.nodeValue;
21                        if( data )
[57]22                        {
23                                statusFlag = data;
[55]24                                setTimeout('IM.ImgStatus("'+data+'")',4000);
[57]25                        }
[55]26            };
27            XMLTools.request('$this.Ujabber.MyPresence', 'GET', handler_Status);
28        };
[64]29
[55]30        IM.prototype.listen = function()
31        {
32           var _this = this;
[72]33           var handler = function(XMLdata)
[55]34           {
35              try
[44]36              {
[73]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                               
[55]51                                if( !_this.userPrefe )
52                                {
53                                        if(window.IM_Preferences)
54                                                IM_Preferences.GetYourPreferences();
55                                }
[64]56
[72]57                    _this.getContacts(XMLdata);
58                    _this.getPresence(XMLdata);
59                                _this.getComposing(XMLdata);
60                    _this.getMessages(XMLdata);
61                                _this.getVcard(XMLdata);
[64]62
[55]63                if(!_this.vcards)
64                {
[68]65                        _this.Vcard();
[55]66                        _this.vcards = true;
67                    }
[72]68
[65]69              }catch(e){}
70
[55]71              setTimeout('IM.listen()', 3000);
72           };
73           this._listen = false;
74           XMLTools.__RETURN_MODE__ = 'XML';
75           XMLTools.request('$this.Ujabber.listen', 'GET', handler);
76        };
[73]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        };
[20]104
[64]105   /*
[55]106        *  Contacts
[33]107        */
[64]108
[55]109        IM.prototype.requireContacts = function()
[33]110        {
[55]111           var handler = function(data)
112                {
113                };
114           XMLTools.request('$this.Ujabber.requireContacts', 'GET', handler);
115        };
[20]116
[55]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;
[20]126
[55]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")};
[20]133
[55]134                 var a = document.createElement('div');
135                 a.innerHTML = XMLTools.transform(node, xsl);
[64]136
[55]137                 div.innerHTML = '';
138                 div.appendChild(img);
139                 div.appendChild(document.createTextNode(this.get_lang('List of Contacts')));
140                 div.appendChild(a);
[64]141
[55]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;
[27]150
[55]151                                                func.insElB(img, func.byId(contact.id).firstChild);
152                                        }
[20]153
[55]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;
[64]160
[55]161                                                el_parent.insertBefore(img,el_parent.firstChild);
[64]162
[55]163                                        } catch(e){}
164                                        group = group.nextSibling;
165                 }
[68]166                         //this.atalho();
[55]167              }
[65]168           }catch(e){}
[64]169
[55]170        };
[33]171
[64]172   /*
[55]173        *  Visible / Unvisible
[20]174        */
175
176        IM.prototype.visible_group = function(el)
177        {
178                var _this = this;
[55]179                var divParent = document.getElementById(el);
180                divParent.style.display = "none";
[20]181                var img = document.getElementById("img_" + el);
182                img.onclick = function(){_this.unvisible_group(el)};
183                img.src = img_group_close.src;
184        }
[64]185
[20]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;
[55]194        }
[64]195
[20]196        /*
[55]197         * Presence
[20]198         */
[64]199
[55]200        IM.prototype.getPresence = function(data)
[20]201        {
[55]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                      }
[20]213
[55]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;
[20]220
[55]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;
[64]237                                        case 'unsubscribe' :
[55]238                                                Subscription.unsubscribe(from);
239                                                type = 'unavailable';
240                                                func.byId(from).firstChild.src = eval('img_' + type + '.src');
241                                                break;
[64]242                                        case 'unsubscribed' :
[55]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>";
[64]272                                                                        func.byId(from).appendChild(lbl);
[55]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();
[65]289           }catch(e){}
[55]290        };
[64]291
[55]292        /*
293         * Contatos - Offline
294         */
[64]295
[55]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'));
[67]303
[55]304                 var group = func.byId("all_groups").firstChild;
305                 while ( group )
306         {
[67]307                        var contact = group.firstChild;
308                        while ( contact )
[55]309                        {
[67]310                                if(contact.tagName == "DIV")
[55]311                                {
[67]312                                        var childF = contact.firstChild;
313                                        if( childF.src == img_unavailable.src && !offline)
[55]314                                                func.byId(contact.id).style.display = "none";
315                                        else
316                                                func.byId(contact.id).style.display = "block";
317                                }
[67]318                                contact = contact.nextSibling;
[55]319                        }
320                        group = group.nextSibling;
321         }
[20]322        }
[64]323
[55]324        /*
325         * Get / Send - Messages
326         */
[64]327
[55]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('/'))
[20]343
[55]344                       if( document.getElementById('vcard_' + from) != null)
345                       {
[57]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);
[68]350                                                    nickname = ( func.trim(nickname) != "" ) ? nickname : from ;
[55]351                                   }
[65]352                                   else
353                                      var nickname = from;
[64]354
[55]355                       var win = document.getElementById(from + '_chatMessages');
356                       if ( !win )
357                       {
358                          im_win.open_chat(from);
359                          win = document.getElementById(from + '_chatMessages');
360                       }
[64]361
[55]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;
[64]367
[55]368                          var label = document.createElement('strong');
[65]369                          label.appendChild(document.createTextNode(nickname));
370
[55]371                          win.appendChild(label);
372                          win.appendChild(document.createElement('br'));
[65]373                          var msg = XMLTools.transform(el, xsl);
374                          win.innerHTML += this.emotions_icons(msg);
[55]375                          win.appendChild(document.createElement('br'));
376                          win.appendChild(document.createElement('br'));
377                          win.scrollTop = win.scrollHeight;
378                                          im_win.newMessageNotification();
[64]379
[55]380                          el = next;
381                       }
382                    }
[20]383
[55]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              }
[65]391           }catch(e){}
[20]392        }
[64]393
[55]394        IM.prototype.sendMessage = function (pJID)
[20]395        {
[55]396           var _this = this;
397           var name_document = document.getElementById(pJID + '_edita');
398           var envio = name_document.contentWindow.document.getElementsByTagName('body').item(0);
[20]399
[65]400           var imgs = envio.getElementsByTagName('img');
401           var cod;
402           var emotion_regexp;
[20]403
[65]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);
[68]416           envio.innerHTML = envio.innerHTML.replace(/&nbsp;| +/gi, ' ');
417           envio.innerHTML = envio.innerHTML.replace(/<br[^>]*>/gi, '<br />');
[65]418
[55]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
[68]430                  message_text = message_text.replace(/&nbsp;| +/gi, ' ');
431                  message_text = message_text.replace(/<br[^>]*>/gi, '<br />');
432
[55]433              envio.innerHTML = '';
[64]434
[55]435              var message_element = document.getElementById(pJID + '_chatMessages');
[57]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);
[68]443                          nickname = (func.trim(nickname) != "") ? nickname : IM_Preferences.jid;       
[57]444                  }
[64]445
[57]446              message_element.innerHTML += '<strong>' + nickname + ' ';
[65]447              message_element.innerHTML += ' ' + _this.get_lang('speak') + ':</strong><br />';
448                  message_element.innerHTML += this.emotions_icons(message_text) + '<br />';
[55]449              message_element.scrollTop = message_element.scrollHeight;
[64]450
[55]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        };
[64]460
[55]461        IM.prototype.getComposing = function(data)
[20]462        {
[55]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';
[64]473
[55]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;
[20]480                        }
481                }
[55]482        };
[64]483
[20]484        /*
[55]485         * Get_lang
[20]486         */
[64]487
[55]488        IM.prototype.get_lang = function(_key, _arg1, _arg2, _arg3, _arg4)
[20]489        {
[55]490           var _value = "";
[64]491
[55]492           if ( !lang_im[_key.toLowerCase()] )
493              return _key + "*";
[64]494
[55]495           _value = lang_im[_key.toLowerCase()];
[64]496
[55]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           }
[64]506
[55]507           return _value;
508        };
[64]509
[55]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;
[64]518
[55]519           }catch(e){}
520        };
[64]521
[55]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        };
[64]531
[24]532   /*
[55]533        *  Smiles
534    */
[20]535
[55]536    IM.prototype.emotions_icons = function(pEmotion)
537    {
[65]538           var emotion_regexp;
539           for ( i in cod_emotions )
[55]540       {
[65]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                  }
[55]555       }
556       return pEmotion;
557    }
[64]558
[55]559        IM.prototype.atalho = function()
560        {
561           if ( (local = func.byId('user_info')) && !(func.byId('myStatus')) )
562           {
[20]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;
[55]587         aux['contacts_image']['id']      = 'myStatus';
588         aux['contacts_image']['src']     = eval('img_' + statusFlag + '.src');
[20]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);
[55]595           }
596           else
597              setTimeout('IM.atalho()', 5000);
598        };
[20]599
[55]600        /*
601         * Vcard
602         */
[64]603
[68]604        IM.prototype.Vcard = function()
[55]605        {
606                var _this = this;
[70]607                if( _this.count_Vcard < 4)
[55]608                {
[68]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                }
[64]624
[68]625        };
626
[55]627        IM.prototype.getVcard = function(data)
628        {
629                  var _this = this;
630                  try
[64]631                  {
[55]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;
[64]637
[55]638                                 div.innerHTML = "";
639                                 div.innerHTML += XMLTools.transform(data, xsl);
[68]640                                 IM_Preferences.vCardInit();                             
[55]641                                 }
[20]642
[68]643
[55]644                  }catch(e){}
645        };
[64]646
[55]647        IM.prototype.open_chat = function(pJID)
648        {
649           im_win.open_chat(pJID);
650        };
[64]651
[55]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);
[65]676                }catch(e){}
[55]677        };
[64]678
[55]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        };
[20]693
[55]694        /*
695         * Menu
[64]696         */
[20]697
[55]698        IM.prototype.menu_preferences = function()
699        {
700                  var posx = 0;
701                  var posy = 0;
702                  var pEv = arguments[0];
[64]703
[55]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                  }
[64]714
[55]715                  var p_element = document.getElementById(arguments[1]);
[64]716                  var _xmlDoc = "";
[55]717                  var _this = this;
[20]718
[64]719                  _xmlDoc = '<menu>' +
720                                                '<item function="IM_Preferences.Add_userLoad()" lang="'+IM.get_lang('Add Contact')+'"/>' +
[55]721                                                '<item function="IM_Preferences.Remove_userLoad()" lang="'+IM.get_lang('Remove Contact')+'"/>' +
[67]722                                                '<item function="IM_Preferences.vCard()" lang="'+IM.get_lang('Vcard')+'"/>' +
[55]723                                                '<item function="IM_Preferences.yourPreferences()" lang="'+IM.get_lang('preferences')+'"/>' +
724                                        '</menu>';
[64]725
[55]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;
[20]730
[55]731              _this.Load_Images_menu();
732        }
[64]733
[55]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;
[64]740
[55]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                        }
[65]747                }catch(e){}
[55]748        }
[64]749
[55]750   /*
751        *  Função Provisória - By AlC
752        */
[20]753
[55]754        function parse_XmlXsl(_xmlDoc, form_xsl)
755        {
[64]756                  var xslWin = false;
757
[55]758                  if ( !xslWin ) xslWin = XMLTools.load(im_path + 'xsl/' + form_xsl + '?' + Date.parse(new Date));
[64]759
[55]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);
[64]773
[55]774                  return a;
[64]775
[55]776        }
[20]777
[55]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');
[64]782
[55]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                 }
[64]790
[55]791                 var _img = func.newEl('img', 'img', 'img', 'img','img');
[64]792
[55]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                 }
[64]799
[55]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')};
[64]805
[55]806                 func.confEl(option1_image, 'src', img_available.src);
[63]807                 func.confEl(option1_image, 'style', 'width:16px;height:16px;cursor:pointer;');
[55]808                 func.confEl(option2_image, 'src', img_xa.src);
[63]809                 func.confEl(option2_image, 'style', 'width:16px;height:16px;cursor:pointer;');
[55]810                 func.confEl(option3_image, 'src', img_dnd.src);
[63]811                 func.confEl(option3_image, 'style', 'width:16px;height:16px;cursor:pointer;');
[55]812                 func.confEl(option4_image, 'src', img_unavailable.src);
[63]813                 func.confEl(option4_image, 'style', 'width:16px;height:16px;cursor:pointer;');
[55]814                 func.confEl(option5_image, 'src', img_edit.src);
[63]815                 func.confEl(option5_image, 'style', 'width:16px;height:16px;cursor:pointer;');
[64]816
[55]817                 func.insEl(option1_image, IM.get_lang('online'), option1_link);
[63]818                 func.confEl(option1_link, 'style','cursor:pointer;');
[55]819                 func.insEl(option1_link, option1);
[63]820
[55]821                 func.insEl(option2_image, IM.get_lang('away'), option2_link);
[63]822                 func.confEl(option2_link, 'style','cursor:pointer;');
[55]823                 func.insEl(option2_link, option2);
[63]824
[55]825                 func.insEl(option3_image, IM.get_lang('busy'), option3_link);
[63]826                 func.confEl(option3_link, 'style','cursor:pointer;');
[55]827                 func.insEl(option3_link, option3);
[63]828
[55]829                 func.insEl(option4_image, IM.get_lang('offline'), option4_link);
[63]830                 func.confEl(option4_link, 'style','cursor:pointer;');
[55]831                 func.insEl(option4_link, option4);
[63]832
[55]833                 func.insEl(option5_image, IM.get_lang('Custom message...'), option5_link);
[63]834                 func.confEl(option5_link, 'style','cursor:pointer;');
[55]835                 func.insEl(option5_link, option5);
[64]836
[55]837                 im_menu_action.menu('fast_menu_im', option1, option2, option3, option4, option5);
838   };
[20]839
[72]840        IM.prototype.setStatus = function(pStatus)
841        {
842                try
843                {
844                        var handler = function()
845                        {
846                        };
[20]847
[72]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        };
[64]879
[55]880   IM.prototype.ImgStatus = function(pStatus)
[20]881   {
[55]882                var myStatus;
883                if ( (myStatus = func.byId('myStatus')) )
884                        myStatus.src = eval('img_' + pStatus + '.src');
885   };
[20]886
[55]887   IM.prototype.setAway = function()
[20]888   {
[72]889      if ( statusFlag != 'available' || this._listen > 0 )
[55]890         return false;
891
892      if ( awayFlag )
[20]893      {
[55]894             this.setStatus('available');
895         awayFlag = false;
[20]896      }
[55]897      else
[20]898      {
[55]899         this.setStatus('xa');
900         awayFlag = true;
[20]901      }
[55]902   };
[64]903
[72]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        };
[20]935
[65]936var IM = new IM();
Note: See TracBrowser for help on using the repository browser.