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