1 | // Instant Messenger |
---|
2 | // im_functions.js |
---|
3 | |
---|
4 | function IM() |
---|
5 | { |
---|
6 | this.array_lang_im = []; |
---|
7 | this.user_not_aut = []; |
---|
8 | this.vcard_contacts = []; |
---|
9 | this.vcard_user = []; |
---|
10 | this.load_photo = false; |
---|
11 | } |
---|
12 | |
---|
13 | /* |
---|
14 | * Load Contatos |
---|
15 | */ |
---|
16 | |
---|
17 | IM.prototype.load_im = function() |
---|
18 | { |
---|
19 | var force = ( arguments.length ) ? true : false; |
---|
20 | var _this = this; |
---|
21 | Sincro.count = 0; |
---|
22 | |
---|
23 | var handler_contacts = function(data) |
---|
24 | { |
---|
25 | if ( data[1] ) |
---|
26 | { |
---|
27 | _this.vcard_contacts.splice(0,_this.vcard_contacts.length); |
---|
28 | _this.vcard_user.splice(0,_this.vcard_user.length); |
---|
29 | _this.user_not_aut.splice(0,_this.user_not_aut.length); |
---|
30 | _this.mount_list(data); |
---|
31 | |
---|
32 | } |
---|
33 | _this.conf_VcardUser(data[0]); |
---|
34 | } |
---|
35 | |
---|
36 | if ( force || this.getWinContactsState() ) |
---|
37 | cIM.cExecute("$this.Ujabber.list_user",handler_contacts); |
---|
38 | } |
---|
39 | |
---|
40 | /* |
---|
41 | * Update Contatos |
---|
42 | */ |
---|
43 | |
---|
44 | IM.prototype.UpdateContacts = function() |
---|
45 | { |
---|
46 | var _this = this; |
---|
47 | _this.load_im(); |
---|
48 | } |
---|
49 | |
---|
50 | IM.prototype.showContacts = function() |
---|
51 | { |
---|
52 | if ( this.getWinContactsState() ) |
---|
53 | im_win.windowClose('contacts_im'); |
---|
54 | else |
---|
55 | { |
---|
56 | im_win.windowMaximizeRestore('contacts_im'); |
---|
57 | this.load_im(); |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | IM.prototype.getWinContactsState = function() |
---|
62 | { |
---|
63 | try |
---|
64 | { |
---|
65 | var win_state = false; |
---|
66 | win_state = ( windowItems['contacts'].state == WINDOW_STATE_REGULAR ) ? true : false; |
---|
67 | win_state = ( win_state ) ? win_state : ( windowItems['contacts'].state == WINDOW_STATE_MAXIMIZED ) ? true : false; |
---|
68 | return win_state; |
---|
69 | } |
---|
70 | catch(e) |
---|
71 | { |
---|
72 | return false; |
---|
73 | } |
---|
74 | } |
---|
75 | /* |
---|
76 | * Monta Lista de Contatos |
---|
77 | */ |
---|
78 | |
---|
79 | IM.prototype.mount_list = function(pList) |
---|
80 | { |
---|
81 | var _this = this; |
---|
82 | var div = document.getElementById("div_contacts"); |
---|
83 | div.innerHTML = ""; |
---|
84 | |
---|
85 | var groups = "<b>"+_this.get_lang("list of contacts")+" - 0 </b><br>"; |
---|
86 | |
---|
87 | if(pList.length > 0){ |
---|
88 | var name_group = ""; |
---|
89 | groups = "<img id='img_all_groups' src=" + img_group_open.src + " onclick=javascript:IM.visible_group('all_groups')>" + |
---|
90 | "<b>"+_this.get_lang("list of contacts")+" - " + ( pList.length - 1 ) + "</b><br>"+ |
---|
91 | "<div id='all_groups'>"; |
---|
92 | for(var i=1; i < pList.length; i++){ |
---|
93 | if( i == 1 ){ |
---|
94 | if(pList[i].group != "" && pList[i].name != ""){ |
---|
95 | name_group = pList[i].group; |
---|
96 | groups += '<img id="img_' + pList[i].group.rm_space() + '" src="' + img_group_open.src + '" onclick="javascript:IM.visible_group(\'' + pList[i].group.rm_space() + '\')" style="margin-left:16px;">'; |
---|
97 | groups += "<b>" + pList[i].group + "</b><br>"; |
---|
98 | groups += "<div id='" + pList[i].group.rm_space() + "'>"; |
---|
99 | if(pList[i].subscription == "both"){ |
---|
100 | groups += '<div id="' + pList[i].jid + '" nuncontact="'+ i +'" onmouseover="this.className=\'contato_hover\'" onmouseout="this.className=\'\'" onmousedown="javascript:IM.action_button(event, \''+pList[i].online + '\', \'' + pList[i].jid + '\');" style="cursor:pointer;padding-left:32px;"><img src="' + ((pList[i].online) == parseInt(1) ? img_online.src : img_offline.src) + '">' + pList[i].name + '</div><span id="_span_' + pList[i].jid + '" class="menu_im"></span>'; |
---|
101 | }else{ |
---|
102 | groups += _this.FromToNone(pList[i].jid,pList[i].subscription,pList[i].group,pList[i].name); |
---|
103 | } |
---|
104 | }else |
---|
105 | _this.user_not_aut[_this.user_not_aut.length] = pList[i].jid + ";" + i; |
---|
106 | }else{ |
---|
107 | if(pList[i].group != "" && pList[i].name != ""){ |
---|
108 | if(pList[i].group == name_group){ |
---|
109 | if(pList[i].subscription == "both"){ |
---|
110 | groups += '<div id="' + pList[i].jid + '" nuncontact="'+ i +'" onmouseover="this.className=\'contato_hover\'" onmouseout="this.className=\'\'" onmousedown="javascript:IM.action_button(event, \''+pList[i].online + '\', \'' + pList[i].jid + '\');" style="cursor:pointer;padding-left:32px;"><img src="' + ((pList[i].online) == parseInt(1) ? img_online.src : img_offline.src) + '">' + pList[i].name + '</div><span id="_span_' + pList[i].jid + '" class="menu_im"></span>'; |
---|
111 | }else{ |
---|
112 | groups += _this.FromToNone(pList[i].jid,pList[i].subscription,pList[i].group,pList[i].name); |
---|
113 | } |
---|
114 | name_group = pList[i].group; |
---|
115 | }else{ |
---|
116 | groups += "</div>"; |
---|
117 | groups += '<img id="img_' + pList[i].group.rm_space() + '" src="' + img_group_open.src + '" onclick="javascript:IM.visible_group(\'' + pList[i].group.rm_space() + '\')" style="margin-left:16px;">'; |
---|
118 | groups += "<b>" + pList[i].group + "</b><br>"; |
---|
119 | groups += "<div id='" + pList[i].group.rm_space() + "'>"; |
---|
120 | if(pList[i].subscription == "both"){ |
---|
121 | groups += '<div id="' + pList[i].jid + '" nuncontact="'+ i +'" onmouseover="this.className=\'contato_hover\'" onmouseout="this.className=\'\'" onmousedown="javascript:IM.action_button(event, \''+pList[i].online + '\', \'' + pList[i].jid + '\');" style="cursor:pointer;padding-left:32px;"><img src="' + ((pList[i].online) == parseInt(1) ? img_online.src : img_offline.src) + '">' + pList[i].name + '</div><span id="_span_' + pList[i].jid + '" class="menu_im"></span>'; |
---|
122 | }else{ |
---|
123 | groups += _this.FromToNone(pList[i].jid,pList[i].subscription,pList[i].group,pList[i].name); |
---|
124 | } |
---|
125 | name_group = pList[i].group; |
---|
126 | } |
---|
127 | }else{ |
---|
128 | _this.user_not_aut[_this.user_not_aut.length] = pList[i].jid + ";" + i; |
---|
129 | } |
---|
130 | } |
---|
131 | } |
---|
132 | groups += "</div><div id='out_list'></div></div>"; |
---|
133 | } |
---|
134 | |
---|
135 | // Vcard Contato; |
---|
136 | if(pList.length > 0) |
---|
137 | _this.vcard_contacts = pList; |
---|
138 | |
---|
139 | // Imprime valor de groups; |
---|
140 | div.innerHTML = groups; |
---|
141 | |
---|
142 | // Usuários sem grupo e nome; |
---|
143 | if(_this.user_not_aut.length > 0) |
---|
144 | _this.Group_Name(document.getElementById('out_list')); |
---|
145 | } |
---|
146 | |
---|
147 | /* |
---|
148 | * Define se From - To - None |
---|
149 | */ |
---|
150 | |
---|
151 | IM.prototype.FromToNone = function(pJid,pSubscription,pGroup,pName) |
---|
152 | { |
---|
153 | var n_groups = ""; |
---|
154 | var _this = this; |
---|
155 | if(pSubscription == "from") |
---|
156 | n_groups += "<div id='" + pJid + "' nucontact="+ i +" style='cursor:pointer;padding-left:32px;' onclick=javascript:IM.Authorization(\'"+pJid+"\',\'"+pSubscription+"\')><img src="+img_not_authorized.src+" title='Aguardando/Enviar Autorização'>"+pName+"</div>"; |
---|
157 | else if(pSubscription == "to") |
---|
158 | n_groups += "<div id='" + pJid + "' nucontact="+ i +" style='cursor:pointer;padding-left:32px;' onclick=javascript:IM.Authorization(\'"+pJid+"\',\'"+pSubscription+"\')><img src="+img_not_authorized.src+" title='Enviar Autorização'>"+pName+"</div>"; |
---|
159 | else if(pSubscription == "none"){ |
---|
160 | n_groups += "<div id='" + pJid + "' nucontact="+ i +" style='cursor:pointer;padding-left:32px;' onclick=javascript:IM.Authorization(\'"+pJid+"\',\'"+pSubscription+"\')><img src="+img_not_authorized.src+" title='Pedir Autorização'>"+pName+"</div>"; |
---|
161 | } |
---|
162 | return n_groups; |
---|
163 | } |
---|
164 | |
---|
165 | /* |
---|
166 | * Usuário sem grupo e nome |
---|
167 | */ |
---|
168 | |
---|
169 | IM.prototype.Group_Name = function(el) |
---|
170 | { |
---|
171 | var _this = this; |
---|
172 | var group_nt = ""; |
---|
173 | |
---|
174 | group_nt += '<img id="img_not_aut" src="' + img_group_open.src + '" onclick="javascript:IM.visible_group(\'not_aut\')" style="margin-left:16px;">'; |
---|
175 | group_nt += "<b>" + _this.get_lang("Sem Cadastro") + "</b><br>"; |
---|
176 | group_nt += "<div id='not_aut'>"; |
---|
177 | for(var i=0; i < _this.user_not_aut.length; i++){ |
---|
178 | var pos = _this.user_not_aut[i].indexOf("@"); |
---|
179 | var ind = _this.user_not_aut[i].substr((_this.user_not_aut[i].indexOf(";")+1),1); |
---|
180 | group_nt += '<div id="'+_this.user_not_aut[i]+'" onclick=Preferences.updateLoad("'+ind+'") style="cursor:pointer;padding-left:32px;">'+ |
---|
181 | '<img src="'+img_not_authorized.src+'">'+_this.user_not_aut[i].substr(0,pos)+'</div>'; |
---|
182 | } |
---|
183 | group_nt += "</div>"; |
---|
184 | el.innerHTML = group_nt; |
---|
185 | setTimeout("Templates.Users_Not_Auth()",2500); |
---|
186 | } |
---|
187 | |
---|
188 | /* |
---|
189 | * Requisitar autorização; |
---|
190 | */ |
---|
191 | |
---|
192 | IM.prototype.Authorization = function(pJid,pSubscription) |
---|
193 | { |
---|
194 | if(confirm("Enviar pedido?")){ |
---|
195 | var handler_accept_request = function(data){ |
---|
196 | if(!data) |
---|
197 | alert("Pedido já foi enviado!"); |
---|
198 | } |
---|
199 | cIM.cExecute("$this.Ujabber.AcceptRequest",handler_accept_request,"jid="+pJid+"&subscription="+pSubscription); |
---|
200 | } |
---|
201 | } |
---|
202 | |
---|
203 | /* |
---|
204 | * Grupos dos Contatos; |
---|
205 | */ |
---|
206 | |
---|
207 | IM.prototype.visible_group = function(el) |
---|
208 | { |
---|
209 | var _this = this; |
---|
210 | el = el.rm_space(); |
---|
211 | var div = document.getElementById(el); |
---|
212 | div.style.display = "none"; |
---|
213 | var img = document.getElementById("img_" + el); |
---|
214 | img.onclick = function(){_this.unvisible_group(el)}; |
---|
215 | img.src = img_group_close.src; |
---|
216 | |
---|
217 | } |
---|
218 | |
---|
219 | IM.prototype.unvisible_group = function(el) |
---|
220 | { |
---|
221 | var _this = this; |
---|
222 | el = el.rm_space(); |
---|
223 | var div = document.getElementById(el); |
---|
224 | div.style.display = ""; |
---|
225 | var img = document.getElementById("img_" + el); |
---|
226 | img.onclick = function(){_this.visible_group(el)}; |
---|
227 | img.src = img_group_open.src; |
---|
228 | |
---|
229 | } |
---|
230 | |
---|
231 | /* |
---|
232 | * Conf. Vcard |
---|
233 | */ |
---|
234 | |
---|
235 | IM.prototype.conf_VcardUser = function(data) |
---|
236 | { |
---|
237 | var _this = this; |
---|
238 | |
---|
239 | // Vcard pessoal; |
---|
240 | |
---|
241 | if ( !_this.load_photo ){ |
---|
242 | |
---|
243 | _this.vcard_user['VCARD_FN'] = decodeURI(data.VCARD_FN); |
---|
244 | _this.vcard_user['VCARD_NICKNAME'] = decodeURI(data.VCARD_NICKNAME); |
---|
245 | _this.vcard_user['VCARD_ORGNAME'] = decodeURI(data.VCARD_ORGNAME); |
---|
246 | _this.vcard_user['VCARD_ORGUNIT'] = decodeURI(data.VCARD_ORGUNIT); |
---|
247 | _this.vcard_user['VCARD_ROLE'] = decodeURI(data.VCARD_ROLE); |
---|
248 | _this.vcard_user['VCARD_BDAY'] = decodeURI(data.VCARD_BDAY); |
---|
249 | _this.vcard_user['VCARD_DESC'] = decodeURI(data.VCARD_DESC); |
---|
250 | _this.vcard_user['VCARD_JID'] = decodeURI(data.VCARD_JID); |
---|
251 | |
---|
252 | im_win.get_photo_ldap(_this.vcard_user['VCARD_JID']); |
---|
253 | _this.load_photo = true; |
---|
254 | } |
---|
255 | |
---|
256 | // NickName; |
---|
257 | if(_this.vcard_user['VCARD_NICKNAME'] != "") |
---|
258 | document.getElementById('span_nickname').innerHTML = "<b> " + _this.vcard_user['VCARD_NICKNAME'].substring(0,30) + "</b>"; |
---|
259 | else |
---|
260 | document.getElementById('span_nickname').innerHTML = "<b> " + IM.get_lang('your nickname') + "</b>"; |
---|
261 | |
---|
262 | // Custom Message; |
---|
263 | if(_this.vcard_user['VCARD_DESC'] != "") |
---|
264 | document.getElementById('span_message').innerHTML = "<b> " + _this.vcard_user['VCARD_DESC'].substring(0,30) + "</b>"; |
---|
265 | else |
---|
266 | document.getElementById('span_message').innerHTML = "<b> " + IM.get_lang('your message') + "</b>"; |
---|
267 | |
---|
268 | } |
---|
269 | |
---|
270 | /* |
---|
271 | * Menu |
---|
272 | */ |
---|
273 | |
---|
274 | IM.prototype.visible_box = function() |
---|
275 | { |
---|
276 | var _this = this; |
---|
277 | document.getElementById('list_users').style.display = ""; |
---|
278 | var img = document.getElementById('box_menu'); |
---|
279 | img.onclick = function(){_this.unvisible_box()}; |
---|
280 | img.src = img_open_box.src; |
---|
281 | } |
---|
282 | |
---|
283 | IM.prototype.unvisible_box = function() |
---|
284 | { |
---|
285 | var _this = this; |
---|
286 | document.getElementById('list_users').style.display = "none"; |
---|
287 | var img = document.getElementById('box_menu'); |
---|
288 | img.onclick = function(){_this.visible_box()}; |
---|
289 | img.src = img_close_box.src; |
---|
290 | } |
---|
291 | |
---|
292 | /* |
---|
293 | * Traduções |
---|
294 | */ |
---|
295 | |
---|
296 | // Translate words and phrases using user language from eGroupware. |
---|
297 | IM.prototype.get_lang = function(_key,_arg1,_arg2,_arg3,_arg4) |
---|
298 | { |
---|
299 | var _this = this; |
---|
300 | if(!_this.array_lang_im[0]){ |
---|
301 | return _key+"*"; |
---|
302 | } |
---|
303 | _value = ""; |
---|
304 | for(i = 0; i < _this.array_lang_im[0].length;i++){ |
---|
305 | if(_this.array_lang_im[0][i] == _key.toLowerCase()) { |
---|
306 | _value = _this.array_lang_im[1][i]; |
---|
307 | break; |
---|
308 | } |
---|
309 | } |
---|
310 | |
---|
311 | if(!_value) |
---|
312 | return _key+"*"; |
---|
313 | |
---|
314 | if(_arg1 || _arg2 ||_arg3 || _arg4) { |
---|
315 | for(j = 1; j <= 4; j++){ |
---|
316 | if(eval("_arg"+j)) { |
---|
317 | var regExp = new RegExp("%"+j+""); |
---|
318 | _value = _value.replace(regExp,eval("_arg"+j)); |
---|
319 | } |
---|
320 | } |
---|
321 | } |
---|
322 | |
---|
323 | return _value; |
---|
324 | } |
---|
325 | |
---|
326 | /* |
---|
327 | * Pega Mensagens |
---|
328 | */ |
---|
329 | |
---|
330 | IM.prototype.getMessage = function() |
---|
331 | { |
---|
332 | _this = this; |
---|
333 | var handler_message = function(data) |
---|
334 | { |
---|
335 | if(data.length > 0) |
---|
336 | { |
---|
337 | var aux = ""; |
---|
338 | var hora = new Date(); |
---|
339 | for(var i=0; i < data.length; i++) |
---|
340 | { |
---|
341 | mensagens = document.getElementById(data[i].from.substr(0, data[i].from.indexOf('/')) + '_chatMessages'); |
---|
342 | var nickname = data[i].from.substr(0, data[i].from.indexOf('/')); |
---|
343 | for(var j=1 ; j < _this.vcard_contacts.length ; j++) |
---|
344 | { |
---|
345 | if(data[i].from.substr(0, data[i].from.indexOf('/')) == _this.vcard_contacts[j].VCARD_JID) |
---|
346 | if(_this.vcard_contacts[j].VCARD_NICKNAME != "") |
---|
347 | nickname = _this.vcard_contacts[j].VCARD_NICKNAME; |
---|
348 | } |
---|
349 | |
---|
350 | minuto = ( hora.getMinutes() > 9 ) ? hora.getMinutes() : '0' + hora.getMinutes(); |
---|
351 | _hora = '[' + hora.getHours() + ':' + minuto + '] '; |
---|
352 | data[i].body = decodeURI(data[i].body).replace(/\\\'/g, '\''); |
---|
353 | |
---|
354 | if ( mensagens ) |
---|
355 | { |
---|
356 | mensagens.innerHTML += '<strong>' + _hora + nickname + ' fala:</strong><br/> ' + _this.emotions_icons(data[i].body) + '<br/>'; |
---|
357 | if ( windowItems[data[i].from.substr(0, data[i].from.indexOf('/'))].state != WINDOW_STATE_REGULAR && windowItems[data[i].from.substr(0, data[i].from.indexOf('/'))].state != WINDOW_STATE_MAXIMIZED ) |
---|
358 | im_win.showWindowItem(data[i].from.substr(0, data[i].from.indexOf('/'))); |
---|
359 | } |
---|
360 | else |
---|
361 | { |
---|
362 | im_win.open_chat(data[i].from.substr(0, data[i].from.indexOf('/'))); |
---|
363 | mensagens = document.getElementById(data[i].from.substr(0, data[i].from.indexOf('/')) + '_chatMessages'); |
---|
364 | mensagens.innerHTML += '<strong>' + _hora + nickname + ' fala:</strong><br/> ' + _this.emotions_icons(data[i].body) + '<br/>'; |
---|
365 | } |
---|
366 | } |
---|
367 | mensagens.scrollTop = mensagens.scrollHeight; |
---|
368 | im_win.newMessageNotification(); |
---|
369 | } |
---|
370 | } |
---|
371 | cIM.cExecute("$this.Ujabber.getMessages", handler_message); |
---|
372 | } |
---|
373 | |
---|
374 | /* |
---|
375 | * Envia Mensagens |
---|
376 | */ |
---|
377 | |
---|
378 | IM.prototype.sendMessage = function (pJID) |
---|
379 | { |
---|
380 | var _this = this; |
---|
381 | var name_document = document.getElementById(pJID + '_edita'); |
---|
382 | var envio = name_document.contentWindow.document.getElementsByTagName('body').item(0); |
---|
383 | |
---|
384 | envio.innerHTML = func.trim(envio.innerHTML.replace(/^( |<br>| )*|( |<br>| )*$/g, '')); |
---|
385 | |
---|
386 | if ( envio.innerHTML != "" ) |
---|
387 | { |
---|
388 | var message_text = "<div style='"; |
---|
389 | message_text += (envio.style.fontFamily != "") ? "font-family:"+envio.style.fontFamily+";" : ""; |
---|
390 | message_text += (envio.style.fontSize != "") ? "font-size:"+envio.style.fontSize+";" : "" ; |
---|
391 | message_text += (envio.style.fontWeight != "") ? "font-weight:"+envio.style.fontWeight+";": ""; |
---|
392 | message_text += (envio.style.fontStyle != "" ) ? "font-style:"+envio.style.fontStyle+";" : ""; |
---|
393 | message_text += (envio.style.color != "") ? "color:"+envio.style.color+";" : "color:black"; |
---|
394 | message_text += "'>"; |
---|
395 | message_text += envio.innerHTML + "</div>"; |
---|
396 | |
---|
397 | envio.innerHTML = ''; |
---|
398 | |
---|
399 | var message_element = document.getElementById(pJID + '_chatMessages'); |
---|
400 | message_element.innerHTML += '<strong>' + ((_this.vcard_user['VCARD_NICKNAME'] != "") ? _this.vcard_user['VCARD_NICKNAME'] : _this.vcard_user['VCARD_JID'] ); |
---|
401 | message_element.innerHTML += ' ' + _this.get_lang('speak') + ':</strong><br/>'; |
---|
402 | message_element.innerHTML += _this.emotions_icons(message_text.replace(/^( |<br>| )*|( |<br>| )*$/g, '')) + '<br/>'; |
---|
403 | |
---|
404 | message_element.scrollTop = message_element.scrollHeight; |
---|
405 | |
---|
406 | var handler_sendMessage = function(data) |
---|
407 | { |
---|
408 | if(!data) |
---|
409 | alert(data); |
---|
410 | } |
---|
411 | cIM.cExecute("$this.Ujabber.SendMessage",handler_sendMessage,"to="+pJID+"&body="+url_encode(encodeURI(message_text))); |
---|
412 | } |
---|
413 | } |
---|
414 | |
---|
415 | /* |
---|
416 | * Smiles |
---|
417 | */ |
---|
418 | |
---|
419 | IM.prototype.emotions_icons = function(pMessage) |
---|
420 | { |
---|
421 | for ( i = 1; i < cod_emotions.length; i++ ) |
---|
422 | { |
---|
423 | var image = eval('smile_' + i + '.src.substr(smile_' + i + '.src.indexOf(im_path))') |
---|
424 | pMessage = pMessage.replace(cod_emotions[i], '<img src="' + image + '">'); |
---|
425 | } |
---|
426 | return pMessage; |
---|
427 | } |
---|
428 | |
---|
429 | IM.prototype.atalho = function() |
---|
430 | { |
---|
431 | if ( local = func.byId('user_info') ) |
---|
432 | { |
---|
433 | var aux = new Array(); |
---|
434 | var _mix = func.newEl('a', 'a', 'img', 'img', 'dl'); |
---|
435 | |
---|
436 | var fast_menu_link = _mix[0]; |
---|
437 | var contacts_link = _mix[1]; |
---|
438 | var fast_menu_image = _mix[2]; |
---|
439 | var contacts_image = _mix[3]; |
---|
440 | var im_fast_menu = _mix[4]; |
---|
441 | |
---|
442 | fast_menu_link.onclick = function(){IM.showFastMenu();}; |
---|
443 | contacts_link.onclick = function(){IM.showContacts();}; |
---|
444 | |
---|
445 | aux['fast_menu_image'] = new Array(); |
---|
446 | aux['fast_menu_image']['element'] = fast_menu_image; |
---|
447 | aux['fast_menu_image']['style'] = 'width:9px;height:9px'; |
---|
448 | aux['fast_menu_image']['src'] = im_path + 'templates/default/images/menuarwopen.gif'; |
---|
449 | |
---|
450 | aux['im_fast_menu'] = new Array(); |
---|
451 | aux['im_fast_menu']['element'] = im_fast_menu; |
---|
452 | aux['im_fast_menu']['id'] = 'fast_menu_im'; |
---|
453 | aux['im_fast_menu']['class'] = 'menu_im'; |
---|
454 | |
---|
455 | aux['contacts_image'] = new Array(); |
---|
456 | aux['contacts_image']['element'] = contacts_image; |
---|
457 | aux['contacts_image']['id'] = 'chat_bubble'; |
---|
458 | aux['contacts_image']['src'] = im_path + 'templates/default/images/navbar.png'; |
---|
459 | aux['contacts_image']['style'] = 'width:15px;height:15px'; |
---|
460 | func.confEl(aux); |
---|
461 | |
---|
462 | func.insEl(fast_menu_image, fast_menu_link); |
---|
463 | func.insEl(contacts_image, contacts_link); |
---|
464 | func.insElB(fast_menu_link, contacts_link, im_fast_menu, document.createTextNode(' '), local.firstChild); |
---|
465 | } |
---|
466 | else |
---|
467 | setTimeout('IM.atalho()', 5000); |
---|
468 | } |
---|
469 | |
---|
470 | IM.prototype.showFastMenu = function() |
---|
471 | { |
---|
472 | if ( !messages_timeout ) |
---|
473 | { |
---|
474 | var option = func.newEl('dt'); |
---|
475 | var option_link = func.newEl('a'); |
---|
476 | var option_image = func.newEl('img'); |
---|
477 | |
---|
478 | option_link.onclick = function(){IM.login();}; |
---|
479 | |
---|
480 | func.confEl(option_image, 'src', img_online.src); |
---|
481 | func.confEl(option_image, 'style', 'width:16px;height:16px;'); |
---|
482 | |
---|
483 | func.insEl(option_image, IM.get_lang('login'), option_link); |
---|
484 | func.insEl(option_link, option); |
---|
485 | |
---|
486 | im_menu_action.menu('fast_menu_im', option); |
---|
487 | } |
---|
488 | else |
---|
489 | { |
---|
490 | var _dt = func.newEl('dt', 'dt', 'dt', 'dt', 'dt'); |
---|
491 | var _a = func.newEl('a', 'a', 'a', 'a', 'a'); |
---|
492 | |
---|
493 | for ( var i in _dt ) |
---|
494 | { |
---|
495 | if ( typeof _dt[i] == 'function' ) |
---|
496 | continue; |
---|
497 | eval('var option' + (parseInt(i)+1) + ' = _dt[' + i + '];'); |
---|
498 | eval('var option' + (parseInt(i)+1) + '_link = _a[' + i + '];'); |
---|
499 | } |
---|
500 | |
---|
501 | var _img = func.newEl('img', 'img', 'img', 'img'); |
---|
502 | |
---|
503 | for ( var i in _img ) |
---|
504 | { |
---|
505 | if ( typeof _dt[i] == 'function' ) |
---|
506 | continue; |
---|
507 | eval('var option' + (parseInt(i)+1) + '_image = _img[' + i + '];'); |
---|
508 | } |
---|
509 | |
---|
510 | option1_link.onclick = function(){IM.setStatus('online');}; |
---|
511 | option2_link.onclick = function(){IM.setStatus('idle');}; |
---|
512 | option3_link.onclick = function(){IM.setStatus('busy');}; |
---|
513 | option4_link.onclick = function(){IM.logout();}; |
---|
514 | option5_link.onclick = function(){IM.setStatus('custom')}; |
---|
515 | |
---|
516 | func.confEl(option1_image, 'src', img_online.src); |
---|
517 | func.confEl(option1_image, 'style', 'width:16px;height:16px;'); |
---|
518 | func.confEl(option2_image, 'src', img_idle.src); |
---|
519 | func.confEl(option2_image, 'style', 'width:16px;height:16px;'); |
---|
520 | func.confEl(option3_image, 'src', img_busy.src); |
---|
521 | func.confEl(option3_image, 'style', 'width:16px;height:16px;'); |
---|
522 | func.confEl(option4_image, 'src', img_offline.src); |
---|
523 | func.confEl(option4_image, 'style', 'width:16px;height:16px;'); |
---|
524 | |
---|
525 | func.insEl(option1_image, IM.get_lang('online'), option1_link); |
---|
526 | func.insEl(option1_link, option1); |
---|
527 | func.insEl(option2_image, IM.get_lang('????'), option2_link); |
---|
528 | func.insEl(option2_link, option2); |
---|
529 | func.insEl(option3_image, IM.get_lang('busy'), option3_link); |
---|
530 | func.insEl(option3_link, option3); |
---|
531 | func.insEl(option4_image, IM.get_lang('offline'), option4_link); |
---|
532 | func.insEl(option4_link, option4); |
---|
533 | func.insEl(IM.get_lang('Custom message...'), option5_link); |
---|
534 | func.insEl(option5_link, option5); |
---|
535 | |
---|
536 | im_menu_action.menu('fast_menu_im', option1, option2, option3, option4, option5); |
---|
537 | } |
---|
538 | } |
---|
539 | |
---|
540 | IM.prototype.setStatus = function(pStatus) |
---|
541 | { |
---|
542 | im_menu_action.menu('fast_menu_im', null); |
---|
543 | } |
---|
544 | |
---|
545 | IM.prototype.getStatus = function() |
---|
546 | { |
---|
547 | } |
---|
548 | |
---|
549 | IM.prototype.login = function() |
---|
550 | { |
---|
551 | try |
---|
552 | { |
---|
553 | im_menu_action.menu('fast_menu_im', null); |
---|
554 | Sincro.get_list(); |
---|
555 | Sincro.get_Message(); |
---|
556 | var contacts_image = func.byId('chat_bubble'); |
---|
557 | contacts_image.parentNode.onclick = function(){IM.showContacts()}; |
---|
558 | func.confEl(contacts_image, 'src', im_path + 'templates/default/images/navbar.png'); |
---|
559 | } |
---|
560 | catch (e) |
---|
561 | { |
---|
562 | } |
---|
563 | } |
---|
564 | |
---|
565 | IM.prototype.logout = function() |
---|
566 | { |
---|
567 | im_menu_action.menu('fast_menu_im', null); |
---|
568 | clearTimeout(messages_timeout); |
---|
569 | clearTimeout(contacts_timeout); |
---|
570 | messages_timeout = false; |
---|
571 | contacts_timeout = false; |
---|
572 | var contacts_image = func.byId('chat_bubble'); |
---|
573 | contacts_image.parentNode.onclick = function(){IM.showFastMenu()}; |
---|
574 | func.confEl(contacts_image, 'src', img_chat_bubble.src); |
---|
575 | } |
---|
576 | |
---|
577 | IM.prototype.menu_preferences = function(pElement) |
---|
578 | { |
---|
579 | if ( document.getElementById(pElement).innerHTML == "" ) |
---|
580 | { |
---|
581 | var form_pref = "<dl>"; |
---|
582 | form_pref += "<dt><a href='javascript:void(0)' onclick='javascript:Preferences.Add_userLoad()'>"; |
---|
583 | form_pref += "<img src="+img_menu.src+"> "+IM.get_lang('Add Contact')+"</a></dt>"; |
---|
584 | form_pref += "<dt><a href='javascript:void(0)' onclick='javascript:Preferences.Remove_userLoad()'>"; |
---|
585 | form_pref += "<img src="+img_menu.src+"> "+IM.get_lang('Remove Contact')+"</a></dt>"; |
---|
586 | form_pref += "<dt><a href='javascript:void(0)' onclick='javascript:Preferences.vCardLoad()'>"; |
---|
587 | form_pref += "<img src="+img_menu.src+"> "+IM.get_lang('Information')+"</a></dt>"; |
---|
588 | form_pref += "</dl>"; |
---|
589 | im_menu_action.menu(pElement, form_pref); |
---|
590 | } |
---|
591 | } |
---|
592 | |
---|
593 | IM.prototype.menu_button_right = function(pElement) |
---|
594 | { |
---|
595 | var form_menu_button_right = '<dl>'+ |
---|
596 | '<dt><a href="javascript:void(0);" onclick="javascript:Preferences.Update_NickName(\''+pElement+'\');"><img src="'+img_group_close.src+'">' + IM.get_lang('Nick') + '</a>'+ |
---|
597 | '<dt><a href="javascript:void(0);" onclick="javascript:Preferences.SendFile(\''+pElement+'\');"><img src="'+img_group_close.src+'">' + IM.get_lang('Send File') + '</a>'+ |
---|
598 | '<dt><a href="javascript:void(0);" onclick="javascript:Preferences.Update_Group(\''+pElement+'\');"><img src="'+img_group_close.src+'">' + IM.get_lang('Group') + '</a>'+ |
---|
599 | '<dt><a href="javascript:void(0);" onclick="javascript:Preferences.Remove_Contact(\''+pElement+'\');"><img src="'+img_group_close.src+'">' + IM.get_lang('Delete') + '</a>'+ |
---|
600 | '<dt><a href="javascript:void(0);" onclick="javascript:Preferences.vCardLoad_Contact(\''+pElement+'\');"><img src="'+img_group_close.src+'">' + IM.get_lang('See Info') + '</a>'+ |
---|
601 | '</dl>'; |
---|
602 | im_menu_action.menu("_span_" + pElement, form_menu_button_right); |
---|
603 | } |
---|
604 | |
---|
605 | /* |
---|
606 | * url_encode |
---|
607 | */ |
---|
608 | |
---|
609 | function url_encode(str) |
---|
610 | { |
---|
611 | var hex_chars = "0123456789ABCDEF"; |
---|
612 | var noEncode = /^([a-zA-Z0-9\_\-\.])$/; |
---|
613 | var n, strCode, hex1, hex2, strEncode = ""; |
---|
614 | |
---|
615 | for( n = 0; n < str.length; n++ ) |
---|
616 | { |
---|
617 | if ( noEncode.test(str.charAt(n)) ) |
---|
618 | { |
---|
619 | strEncode += str.charAt(n); |
---|
620 | } |
---|
621 | else |
---|
622 | { |
---|
623 | strCode = str.charCodeAt(n); |
---|
624 | hex1 = hex_chars.charAt(Math.floor(strCode / 16)); |
---|
625 | hex2 = hex_chars.charAt(strCode % 16); |
---|
626 | strEncode += "%" + (hex1 + hex2); |
---|
627 | } |
---|
628 | } |
---|
629 | return strEncode; |
---|
630 | } |
---|
631 | |
---|
632 | /* |
---|
633 | * Ação do botão onclick da lista de contatos; |
---|
634 | */ |
---|
635 | |
---|
636 | IM.prototype.action_button = function(pEv,pStatus,pJid) |
---|
637 | { |
---|
638 | var _this = this; |
---|
639 | if(pEv.button > 1){ |
---|
640 | _this.menu_button_right(pJid); |
---|
641 | document.oncontextmenu = new Function("return false"); |
---|
642 | }else{ |
---|
643 | if(pStatus == parseInt(1)) |
---|
644 | _this.open_chat(pJid); |
---|
645 | } |
---|
646 | } |
---|
647 | |
---|
648 | /* |
---|
649 | * Abre Conversa |
---|
650 | */ |
---|
651 | |
---|
652 | IM.prototype.open_chat = function(pJID) |
---|
653 | { |
---|
654 | func.byId(pJID).firstChild.src = img_chat_bubble.src; |
---|
655 | im_win.open_chat(pJID); |
---|
656 | } |
---|
657 | |
---|
658 | |
---|
659 | String.prototype.rm_space = function() |
---|
660 | { |
---|
661 | return this.replace(/( *)/g,""); |
---|
662 | } |
---|
663 | |
---|
664 | IM.prototype.LTrim = function(value) |
---|
665 | { |
---|
666 | var w_space = String.fromCharCode(32); |
---|
667 | var strTemp = ""; |
---|
668 | var iTemp = 0; |
---|
669 | |
---|
670 | if(v_length < 1) return ""; |
---|
671 | |
---|
672 | var v_length = value ? value.length : 0; |
---|
673 | |
---|
674 | while ( iTemp < v_length ) |
---|
675 | { |
---|
676 | if ( value && value.charAt(iTemp) != w_space ) |
---|
677 | { |
---|
678 | strTemp = value.substring(iTemp,v_length); |
---|
679 | break; |
---|
680 | } |
---|
681 | iTemp++; |
---|
682 | } |
---|
683 | return strTemp; |
---|
684 | } |
---|
685 | |
---|
686 | function teste(pJID) |
---|
687 | { |
---|
688 | document.getElementById(pJID + '_edita').onkeydown = function (e){ |
---|
689 | if (is_ie) |
---|
690 | { |
---|
691 | if ((window.event.keyCode) == 13) |
---|
692 | send(pJID); |
---|
693 | } |
---|
694 | else |
---|
695 | { |
---|
696 | if ((e.keyCode) == 13) |
---|
697 | { |
---|
698 | send(pJID); |
---|
699 | return false; |
---|
700 | } |
---|
701 | } |
---|
702 | } |
---|
703 | } |
---|
704 | |
---|
705 | // Build Object |
---|
706 | var IM = new IM(); |
---|