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