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

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