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