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