[2397] | 1 | /** |
---|
| 2 | * This program is distributed under the terms of the MIT license. |
---|
| 3 | * Please see the LICENSE file for details. |
---|
| 4 | * |
---|
| 5 | * Copyright 2008 Michael Garvin |
---|
| 6 | */ |
---|
| 7 | |
---|
[2437] | 8 | var TROPHYIM_BOSH_SERVICE = "/proxy/ejabberd"; //Change to suit |
---|
[2397] | 9 | |
---|
| 10 | var TROPHYIM_LOG_LINES = 200; |
---|
| 11 | |
---|
| 12 | var TROPHYIM_LOGLEVEL = 0; //0=debug, 1=info, 2=warn, 3=error, 4=fatal |
---|
| 13 | |
---|
| 14 | var TROPHYIM_VERSION = "0.3"; |
---|
| 15 | |
---|
| 16 | var TROPHYIM_RESOURCE = "/JABBERITWEB"; |
---|
| 17 | |
---|
| 18 | //Uncomment to make session reattachment work |
---|
| 19 | //var TROPHYIM_JSON_STORE = "json_store.php"; |
---|
| 20 | |
---|
| 21 | /** Object: DOMObjects |
---|
| 22 | * This class contains builders for all the DOM objects needed by TrophyIM |
---|
| 23 | */ |
---|
| 24 | DOMObjects = { |
---|
| 25 | /** Function: xmlParse |
---|
| 26 | * Cross-browser alternative to using innerHTML |
---|
| 27 | * Parses given string, returns valid DOM HTML object |
---|
| 28 | * |
---|
| 29 | * Parameters: |
---|
| 30 | * (String) xml - the xml string to parse |
---|
| 31 | */ |
---|
| 32 | xmlParse : function(xmlString) { |
---|
| 33 | var xmlObj = this.xmlRender(xmlString); |
---|
| 34 | if(xmlObj) { |
---|
| 35 | try { //Firefox, Gecko, etc |
---|
| 36 | if (this.processor == undefined) { |
---|
| 37 | this.processor = new XSLTProcessor(); |
---|
| 38 | this.processor.importStylesheet(this.xmlRender( |
---|
| 39 | '<xsl:stylesheet version="1.0"\ |
---|
| 40 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform">\ |
---|
| 41 | <xsl:output method="html" indent="yes"/><xsl:template\ |
---|
| 42 | match="@*|node()"><xsl:copy><xsl:copy-of\ |
---|
| 43 | select="@*|node()"/></xsl:copy></xsl:template>\ |
---|
| 44 | </xsl:stylesheet>')); |
---|
| 45 | } |
---|
| 46 | var htmlObj = |
---|
| 47 | this.processor.transformToDocument(xmlObj).documentElement; |
---|
| 48 | //Safari has a quirk where it wraps dom elements in <html><body> |
---|
| 49 | if (htmlObj.tagName.toLowerCase() == 'html') { |
---|
| 50 | htmlObj = htmlObj.firstChild.firstChild; |
---|
| 51 | } |
---|
| 52 | return document.importNode(htmlObj, true); |
---|
| 53 | } catch(e) { |
---|
| 54 | try { //IE is so very very special |
---|
| 55 | var htmlObj = document.importNode(xmlObj.documentElement, true); |
---|
| 56 | if (htmlObj.tagName.toLowerCase() == "div") { |
---|
| 57 | var div_wrapper = document.createElement('div'); |
---|
| 58 | div_wrapper.appendChild(htmlObj); |
---|
| 59 | if(div_wrapper.innerHTML) { |
---|
| 60 | div_wrapper.innerHTML = div_wrapper.innerHTML; |
---|
| 61 | } |
---|
| 62 | htmlObj = div_wrapper.firstChild; |
---|
| 63 | } |
---|
| 64 | return htmlObj; |
---|
| 65 | } catch(e) { |
---|
[2670] | 66 | alert("TrophyIM Error: Cannot add html to page " + e.message); |
---|
[2397] | 67 | } |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | }, |
---|
| 71 | /** Function: xmlRender |
---|
| 72 | * Uses browser-specific methods to turn given string into xml object |
---|
| 73 | * |
---|
| 74 | * Parameters: |
---|
| 75 | * (String) xml - the xml string to parse |
---|
| 76 | */ |
---|
| 77 | xmlRender : function(xmlString) { |
---|
| 78 | try {//IE |
---|
| 79 | var renderObj = new ActiveXObject("Microsoft.XMLDOM"); |
---|
| 80 | renderObj.async="false"; |
---|
| 81 | if(xmlString) { |
---|
| 82 | renderObj.loadXML(xmlString); |
---|
| 83 | } |
---|
| 84 | } catch (e) { |
---|
| 85 | try { //Firefox, Gecko, etc |
---|
| 86 | if (this.parser == undefined) { |
---|
| 87 | this.parser = new DOMParser(); |
---|
| 88 | } |
---|
| 89 | var renderObj = this.parser.parseFromString(xmlString, |
---|
| 90 | "application/xml"); |
---|
| 91 | } catch(e) { |
---|
| 92 | alert("TrophyIM Error: Cannot create new html for page"); |
---|
| 93 | } |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | return renderObj; |
---|
| 97 | }, |
---|
| 98 | /** Function: getHTML |
---|
| 99 | * Returns named HTML snippet as DOM object |
---|
| 100 | * |
---|
| 101 | * Parameters: |
---|
| 102 | * (String) name - name of HTML snippet to retrieve (see HTMLSnippets |
---|
| 103 | * object) |
---|
| 104 | */ |
---|
| 105 | getHTML : function(page) |
---|
| 106 | { |
---|
| 107 | return this.xmlParse(HTMLSnippets[page]); |
---|
| 108 | }, |
---|
| 109 | |
---|
| 110 | /** Function: getScript |
---|
| 111 | * Returns script object with src to given script |
---|
| 112 | * |
---|
| 113 | * Parameters: |
---|
| 114 | * (String) script - name of script to put in src attribute of script |
---|
| 115 | * element |
---|
| 116 | */ |
---|
| 117 | getScript : function(script) |
---|
| 118 | { |
---|
| 119 | var newscript = document.createElement('script'); |
---|
| 120 | newscript.setAttribute('src', script); |
---|
| 121 | newscript.setAttribute('type', 'text/javascript'); |
---|
| 122 | return newscript; |
---|
| 123 | } |
---|
| 124 | }; |
---|
| 125 | |
---|
| 126 | /** Object: TrophyIM |
---|
| 127 | * |
---|
| 128 | * This is the actual TrophyIM application. It searches for the |
---|
| 129 | * 'trophyimclient' element and inserts itself into that. |
---|
| 130 | */ |
---|
| 131 | TrophyIM = { |
---|
| 132 | |
---|
[2641] | 133 | /** AutoConnection |
---|
| 134 | * |
---|
| 135 | */ |
---|
| 136 | |
---|
| 137 | autoConnection : { connect : true }, |
---|
[2647] | 138 | |
---|
| 139 | /** Object: chatHistory |
---|
| 140 | * |
---|
| 141 | * Stores chat history (last 10 message) and current presence of active |
---|
| 142 | * chat tabs. Indexed by jid. |
---|
| 143 | */ |
---|
| 144 | |
---|
| 145 | chatHistory : {}, |
---|
| 146 | |
---|
| 147 | /** Constants: |
---|
| 148 | * |
---|
| 149 | * (Boolean) stale_roster - roster is stale and needs to be rewritten. |
---|
| 150 | */ |
---|
| 151 | |
---|
| 152 | constants : {stale_roster: false}, |
---|
| 153 | |
---|
[2641] | 154 | /** PosWindow |
---|
| 155 | * |
---|
| 156 | */ |
---|
[2599] | 157 | posWindow : { left : 400, top : 100 }, |
---|
| 158 | |
---|
[2641] | 159 | /** StatusConnection |
---|
| 160 | * |
---|
| 161 | */ |
---|
| 162 | |
---|
[2397] | 163 | statusConn : { connected : false }, |
---|
| 164 | |
---|
[2647] | 165 | /** TimeOut Render Roster |
---|
| 166 | * |
---|
| 167 | * |
---|
| 168 | */ |
---|
| 169 | |
---|
| 170 | _timeOut : { renderRoster : null }, |
---|
| 171 | |
---|
[2397] | 172 | /** Function: setCookie |
---|
| 173 | * |
---|
| 174 | * Sets cookie name/value pair. Date and path are auto-selected. |
---|
| 175 | * |
---|
| 176 | * Parameters: |
---|
| 177 | * (String) name - the name of the cookie variable |
---|
| 178 | * (String) value - the value of the cookie variable |
---|
| 179 | */ |
---|
| 180 | |
---|
| 181 | setCookie : function(name, value) |
---|
| 182 | { |
---|
| 183 | var expire = new Date(); |
---|
| 184 | expire.setDate(expire.getDate() + 365); |
---|
| 185 | document.cookie = name + "=" + value + "; expires=" + expire.toGMTString(); |
---|
| 186 | }, |
---|
| 187 | |
---|
| 188 | /** Function: delCookie |
---|
| 189 | * |
---|
| 190 | * Deletes cookie |
---|
| 191 | * |
---|
| 192 | * Parameters: |
---|
| 193 | * (String) name) - the name of the cookie to delete |
---|
| 194 | */ |
---|
| 195 | |
---|
| 196 | delCookie : function(name) |
---|
| 197 | { |
---|
| 198 | var expire = new Date(); |
---|
| 199 | expire.setDate(expire.getDate() - 365); |
---|
| 200 | document.cookie = name + "= ; expires=" + expire.toGMTString(); |
---|
| 201 | delete TrophyIM.cookies[name]; |
---|
| 202 | }, |
---|
| 203 | |
---|
| 204 | /** Function: getCookies |
---|
| 205 | * |
---|
| 206 | * Retrieves all trophyim cookies into an indexed object. Inteneded to be |
---|
| 207 | * called once, at which time the app refers to the returned object instead |
---|
| 208 | * of re-parsing the cookie string every time. |
---|
| 209 | * |
---|
| 210 | * Each cookie is also re-applied so as to refresh the expiry date. |
---|
| 211 | */ |
---|
| 212 | |
---|
| 213 | getCookies : function() |
---|
| 214 | { |
---|
| 215 | var cObj = {}; |
---|
| 216 | var cookies = document.cookie.split(';'); |
---|
[2647] | 217 | |
---|
| 218 | for(var i = 0 ; i < cookies.length; i++ ) |
---|
[2471] | 219 | { |
---|
[2647] | 220 | while ( cookies[i].charAt(0) == ' ') |
---|
[2471] | 221 | { |
---|
[2647] | 222 | cookies[i] = cookies[i].substring(1,cookies[i].length); |
---|
[2397] | 223 | } |
---|
[2647] | 224 | |
---|
| 225 | if (cookies[i].substr(0, 8) == "trophyim") |
---|
[2471] | 226 | { |
---|
[2647] | 227 | var nvpair = cookies[i].split("=", 2); |
---|
[2397] | 228 | cObj[nvpair[0]] = nvpair[1]; |
---|
| 229 | TrophyIM.setCookie(nvpair[0], nvpair[1]); |
---|
| 230 | } |
---|
| 231 | } |
---|
[2471] | 232 | |
---|
[2397] | 233 | return cObj; |
---|
| 234 | }, |
---|
| 235 | |
---|
| 236 | /** Function: load |
---|
| 237 | * |
---|
| 238 | * This function searches for the trophyimclient div and loads the client |
---|
| 239 | * into it. |
---|
| 240 | */ |
---|
| 241 | |
---|
| 242 | load : function() |
---|
| 243 | { |
---|
[2670] | 244 | loadscript.setUserCurrent(); |
---|
[2607] | 245 | |
---|
| 246 | if (!TrophyIM.statusConn.connected) |
---|
[2397] | 247 | { |
---|
| 248 | TrophyIM.cookies = TrophyIM.getCookies(); |
---|
| 249 | |
---|
| 250 | //Load other .js scripts needed |
---|
[2647] | 251 | //document.getElementsByTagName('head')[0].appendChild(DOMObjects.getScript(path_jabberit + 'js/strophe.min.js')); |
---|
| 252 | document.getElementsByTagName('head')[0].appendChild(DOMObjects.getScript(path_jabberit + 'js/strophe.js')); |
---|
[2397] | 253 | document.getElementsByTagName('head')[0].appendChild(DOMObjects.getScript(path_jabberit + 'js/json2.js')); //Keep this script last |
---|
| 254 | //Wait a second to give scripts time to load |
---|
| 255 | setTimeout("TrophyIM.showLogin()", 500); |
---|
| 256 | } |
---|
| 257 | else |
---|
| 258 | { |
---|
[2670] | 259 | loadscript.rosterDiv(); |
---|
[2397] | 260 | } |
---|
| 261 | }, |
---|
| 262 | |
---|
| 263 | /** Function: storeData |
---|
| 264 | * |
---|
| 265 | * Store all our data in the JSONStore, if it is active |
---|
| 266 | */ |
---|
[2471] | 267 | |
---|
[2397] | 268 | storeData : function() |
---|
| 269 | { |
---|
| 270 | if ( TrophyIM.connection && TrophyIM.connection.connected ) |
---|
| 271 | { |
---|
| 272 | TrophyIM.setCookie('trophyim_bosh_xid', TrophyIM.connection.jid + "|" + |
---|
| 273 | TrophyIM.connection.sid + "|" + TrophyIM.connection.rid); |
---|
| 274 | TrophyIM.rosterObj.save(); |
---|
| 275 | } |
---|
| 276 | }, |
---|
[2471] | 277 | |
---|
[2397] | 278 | /** Function: showlogin |
---|
| 279 | * |
---|
| 280 | * This function clears out the IM box and either redisplays the login |
---|
| 281 | * page, or re-attaches to Strophe, preserving the logging div if it |
---|
| 282 | * exists, or creating a new one of we are re-attaching. |
---|
| 283 | */ |
---|
[2471] | 284 | |
---|
[2397] | 285 | showLogin : function() |
---|
| 286 | { |
---|
| 287 | //JSON is the last script to load, so we wait on it |
---|
| 288 | //Added Strophe check too because of bug where it's sometimes missing |
---|
| 289 | if (typeof(JSON) != undefined && typeof(Strophe) != undefined) |
---|
| 290 | { |
---|
| 291 | TrophyIM.JSONStore = new TrophyIMJSONStore(); |
---|
| 292 | |
---|
| 293 | if ( TrophyIM.JSONStore.store_working && TrophyIM.cookies['trophyim_bosh_xid'] ) |
---|
| 294 | { |
---|
| 295 | var xids = TrophyIM.cookies['trophyim_bosh_xid'].split("|"); |
---|
| 296 | TrophyIM.delCookie('trophyim_bosh_xid'); |
---|
| 297 | TrophyIM.constants.stale_roster = true; |
---|
| 298 | |
---|
| 299 | TrophyIM.connection = new Strophe.Connection(TROPHYIM_BOSH_SERVICE); |
---|
| 300 | TrophyIM.connection.rawInput = TrophyIM.rawInput; |
---|
| 301 | TrophyIM.connection.rawOutput = TrophyIM.rawOutput; |
---|
| 302 | Strophe.log = TrophyIM.log; |
---|
| 303 | Strophe.info('Attempting Strophe attach.'); |
---|
| 304 | TrophyIM.connection.attach(xids[0], xids[1], xids[2], TrophyIM.onConnect); |
---|
| 305 | TrophyIM.onConnect(Strophe.Status.CONNECTED); |
---|
| 306 | } |
---|
| 307 | else |
---|
| 308 | { |
---|
[2607] | 309 | // List Contact |
---|
[2670] | 310 | loadscript.rosterDiv(); |
---|
[2397] | 311 | |
---|
[2670] | 312 | if ( loadscript.getUserCurrent() != null ) |
---|
[2397] | 313 | { |
---|
[2670] | 314 | TrophyIM.login( Base64.decode(loadscript.getUserCurrent().jid), Base64.decode(loadscript.getUserCurrent().password)); |
---|
[2397] | 315 | } |
---|
| 316 | else |
---|
| 317 | { |
---|
[2670] | 318 | loadscript.loginPage(); |
---|
[2397] | 319 | } |
---|
| 320 | } |
---|
| 321 | } |
---|
| 322 | else |
---|
| 323 | { |
---|
| 324 | setTimeout("TrophyIM.showLogin()", 500); |
---|
| 325 | } |
---|
| 326 | }, |
---|
| 327 | |
---|
| 328 | /** Function: log |
---|
| 329 | * |
---|
| 330 | * This function logs the given message in the trophyimlog div |
---|
| 331 | * |
---|
| 332 | * Parameter: (String) msg - the message to log |
---|
| 333 | */ |
---|
| 334 | |
---|
| 335 | log : function(level, msg) |
---|
| 336 | { |
---|
| 337 | if (TrophyIM.logging_div && level >= TROPHYIM_LOGLEVEL) { |
---|
| 338 | while(TrophyIM.logging_div.childNodes.length > TROPHYIM_LOG_LINES) { |
---|
| 339 | TrophyIM.logging_div.removeChild( |
---|
| 340 | TrophyIM.logging_div.firstChild); |
---|
| 341 | } |
---|
| 342 | var msg_div = document.createElement('div'); |
---|
| 343 | msg_div.className = 'trophyimlogitem'; |
---|
| 344 | msg_div.appendChild(document.createTextNode(msg)); |
---|
| 345 | TrophyIM.logging_div.appendChild(msg_div); |
---|
| 346 | TrophyIM.logging_div.scrollTop = TrophyIM.logging_div.scrollHeight; |
---|
| 347 | } |
---|
| 348 | }, |
---|
| 349 | |
---|
| 350 | /** Function: rawInput |
---|
| 351 | * |
---|
| 352 | * This logs the packets actually recieved by strophe at the debug level |
---|
| 353 | */ |
---|
| 354 | rawInput : function (data) |
---|
| 355 | { |
---|
| 356 | Strophe.debug("RECV: " + data); |
---|
| 357 | }, |
---|
| 358 | |
---|
| 359 | /** Function: rawInput |
---|
| 360 | * |
---|
| 361 | * This logs the packets actually recieved by strophe at the debug level |
---|
| 362 | */ |
---|
| 363 | rawOutput : function (data) |
---|
| 364 | { |
---|
| 365 | Strophe.debug("SEND: " + data); |
---|
| 366 | }, |
---|
| 367 | |
---|
| 368 | /** Function: login |
---|
| 369 | * |
---|
| 370 | * This function logs into server using information given on login page. |
---|
| 371 | * Since the login page is where the logging checkbox is, it makes or |
---|
| 372 | * removes the logging div and cookie accordingly. |
---|
| 373 | * |
---|
| 374 | */ |
---|
| 375 | login : function() |
---|
| 376 | { |
---|
| 377 | if (TrophyIM.JSONStore.store_working) |
---|
| 378 | { |
---|
| 379 | //In case they never logged out |
---|
| 380 | TrophyIM.JSONStore.delData(['groups','roster', 'active_chat', 'chat_history']); |
---|
| 381 | } |
---|
| 382 | |
---|
| 383 | TrophyIM.connection = new Strophe.Connection(TROPHYIM_BOSH_SERVICE); |
---|
| 384 | TrophyIM.connection.rawInput = TrophyIM.rawInput; |
---|
| 385 | TrophyIM.connection.rawOutput = TrophyIM.rawOutput; |
---|
| 386 | Strophe.log = TrophyIM.log; |
---|
| 387 | |
---|
| 388 | if ( arguments.length > 0 ) |
---|
| 389 | { |
---|
| 390 | var barejid = arguments[0]; |
---|
| 391 | var password = arguments[1]; |
---|
| 392 | |
---|
[2584] | 393 | TrophyIM.connection.connect( barejid + TROPHYIM_RESOURCE, password, TrophyIM.onConnect ); |
---|
[2397] | 394 | } |
---|
| 395 | else |
---|
| 396 | { |
---|
| 397 | var barejid = document.getElementById('trophyimjid').value |
---|
| 398 | var fulljid = barejid + TROPHYIM_RESOURCE; |
---|
| 399 | var password = document.getElementById('trophyimpass').value; |
---|
| 400 | var button = document.getElementById('trophyimconnect'); |
---|
| 401 | |
---|
[2670] | 402 | loadscript.setUserCurrent( barejid, password); |
---|
[2397] | 403 | |
---|
| 404 | if ( button.value == 'connect' ) |
---|
| 405 | { |
---|
| 406 | button.value = 'disconnect'; |
---|
| 407 | TrophyIM.connection.connect(fulljid, password, TrophyIM.onConnect); |
---|
| 408 | } |
---|
| 409 | else |
---|
| 410 | { |
---|
| 411 | button.value = 'connect'; |
---|
| 412 | TrophyIM.connection.disconnect(); |
---|
| 413 | } |
---|
| 414 | } |
---|
| 415 | |
---|
| 416 | TrophyIM.setCookie('trophyimjid', barejid); |
---|
| 417 | }, |
---|
| 418 | |
---|
| 419 | /** Function: logout |
---|
| 420 | * |
---|
| 421 | * Logs into fresh session through Strophe, purging any old data. |
---|
| 422 | */ |
---|
| 423 | logout : function() |
---|
| 424 | { |
---|
[2641] | 425 | TrophyIM.autoConnection.connect = false; |
---|
| 426 | |
---|
| 427 | TrophyIM.delCookie('trophyim_bosh_xid'); |
---|
[2584] | 428 | |
---|
[2397] | 429 | delete TrophyIM['cookies']['trophyim_bosh_xid']; |
---|
| 430 | |
---|
| 431 | TrophyIM.connection.disconnect(); |
---|
| 432 | }, |
---|
| 433 | |
---|
| 434 | /** Function onConnect |
---|
| 435 | * |
---|
| 436 | * Callback given to Strophe upon connection to BOSH proxy. |
---|
| 437 | */ |
---|
| 438 | onConnect : function(status) |
---|
| 439 | { |
---|
[2647] | 440 | var loading_gif = document.getElementById("JabberIMRosterLoadingGif"); |
---|
[2629] | 441 | |
---|
| 442 | if( status == Strophe.Status.CONNECTING ) |
---|
[2397] | 443 | { |
---|
[2647] | 444 | loading_gif.style.display = "block"; |
---|
| 445 | Strophe.info('Strophe is connecting.'); |
---|
[2397] | 446 | } |
---|
| 447 | |
---|
[2584] | 448 | if( status == Strophe.Status.CONNFAIL ) |
---|
[2397] | 449 | { |
---|
[2629] | 450 | TrophyIM.delCookie('trophyim_bosh_xid'); |
---|
[2620] | 451 | TrophyIM.statusConn.connected = false; |
---|
[2647] | 452 | loading_gif.style.display = "block"; |
---|
[2397] | 453 | } |
---|
| 454 | |
---|
[2584] | 455 | if( status == Strophe.Status.DISCONNECTING ) |
---|
[2397] | 456 | { |
---|
[2620] | 457 | TrophyIM.statusConn.connected = false; |
---|
[2397] | 458 | } |
---|
| 459 | |
---|
[2584] | 460 | if( status == Strophe.Status.DISCONNECTED ) |
---|
[2397] | 461 | { |
---|
[2641] | 462 | if( TrophyIM.autoConnection.connect ) |
---|
[2620] | 463 | { |
---|
[2647] | 464 | loading_gif.style.display = "block"; |
---|
| 465 | |
---|
[2641] | 466 | TrophyIM.delCookie('trophyim_bosh_xid'); |
---|
[2620] | 467 | |
---|
[2641] | 468 | TrophyIM.statusConn.connected = false; |
---|
| 469 | |
---|
| 470 | setTimeout(function() |
---|
| 471 | { |
---|
| 472 | TrophyIM.showLogin(); |
---|
| 473 | |
---|
| 474 | },10000); |
---|
| 475 | |
---|
[2670] | 476 | loadscript.clrAllContacts(); |
---|
[2641] | 477 | |
---|
[2670] | 478 | loadscript.setStatusJabber("Desconectado","unavailable"); |
---|
[2641] | 479 | |
---|
| 480 | delete TrophyIM.rosterObj.roster; |
---|
| 481 | delete TrophyIM.rosterObj.groups; |
---|
| 482 | } |
---|
[2397] | 483 | } |
---|
| 484 | |
---|
[2584] | 485 | if( status == Strophe.Status.CONNECTED ) |
---|
[2397] | 486 | { |
---|
[2670] | 487 | loadscript.setStatusJabber('Disponível','available'); |
---|
[2397] | 488 | TrophyIM.statusConn.connected = true; |
---|
| 489 | TrophyIM.showClient(); |
---|
| 490 | } |
---|
| 491 | }, |
---|
| 492 | |
---|
| 493 | /** Function: showClient |
---|
| 494 | * |
---|
| 495 | * This clears out the main div and puts in the main client. It also |
---|
| 496 | * registers all the handlers for Strophe to call in the client. |
---|
| 497 | */ |
---|
| 498 | showClient : function() |
---|
| 499 | { |
---|
| 500 | TrophyIM.setCookie('trophyim_bosh_xid', TrophyIM.connection.jid + "|" + |
---|
| 501 | TrophyIM.connection.sid + "|" + TrophyIM.connection.rid); |
---|
| 502 | |
---|
| 503 | TrophyIM.rosterObj = new TrophyIMRoster(); |
---|
| 504 | TrophyIM.connection.addHandler(TrophyIM.onVersion, Strophe.NS.VERSION, 'iq', null, null, null); |
---|
| 505 | TrophyIM.connection.addHandler(TrophyIM.onRoster, Strophe.NS.ROSTER, 'iq', null, null, null); |
---|
| 506 | TrophyIM.connection.addHandler(TrophyIM.onPresence, null, 'presence', null, null, null); |
---|
| 507 | TrophyIM.connection.addHandler(TrophyIM.onMessage, null, 'message', null, null, null); |
---|
| 508 | |
---|
| 509 | //Get roster then announce presence. |
---|
| 510 | TrophyIM.connection.send($iq({type: 'get', xmlns: Strophe.NS.CLIENT}).c('query', {xmlns: Strophe.NS.ROSTER}).tree()); |
---|
| 511 | TrophyIM.connection.send($pres().tree()); |
---|
[2670] | 512 | setTimeout( TrophyIM.renderRoster, 1000); |
---|
[2397] | 513 | }, |
---|
| 514 | |
---|
| 515 | /** Function: clearClient |
---|
| 516 | * |
---|
| 517 | * Clears out client div, preserving and returning existing logging_div if |
---|
| 518 | * one exists |
---|
| 519 | */ |
---|
[2471] | 520 | |
---|
| 521 | clearClient : function() |
---|
| 522 | { |
---|
| 523 | if(TrophyIM.logging_div) |
---|
| 524 | { |
---|
| 525 | var logging_div = TrophyIM.client_div.removeChild(document.getElementById('trophyimlog')); |
---|
| 526 | } |
---|
| 527 | else |
---|
| 528 | { |
---|
[2397] | 529 | var logging_div = null; |
---|
| 530 | } |
---|
[2471] | 531 | |
---|
| 532 | while(TrophyIM.client_div.childNodes.length > 0) |
---|
| 533 | { |
---|
[2397] | 534 | TrophyIM.client_div.removeChild(TrophyIM.client_div.firstChild); |
---|
| 535 | } |
---|
[2471] | 536 | |
---|
[2397] | 537 | return logging_div; |
---|
| 538 | }, |
---|
[2471] | 539 | |
---|
[2397] | 540 | /** Function: onVersion |
---|
| 541 | * |
---|
| 542 | * jabber:iq:version query handler |
---|
| 543 | */ |
---|
[2471] | 544 | |
---|
| 545 | onVersion : function(msg) |
---|
| 546 | { |
---|
[2397] | 547 | Strophe.debug("Version handler"); |
---|
[2471] | 548 | if (msg.getAttribute('type') == 'get') |
---|
| 549 | { |
---|
[2397] | 550 | var from = msg.getAttribute('from'); |
---|
| 551 | var to = msg.getAttribute('to'); |
---|
| 552 | var id = msg.getAttribute('id'); |
---|
| 553 | var reply = $iq({type: 'result', to: from, from: to, id: id}).c('query', |
---|
| 554 | {name: "TrophyIM", version: TROPHYIM_VERSION, os: |
---|
| 555 | "Javascript-capable browser"}); |
---|
| 556 | TrophyIM.connection.send(reply.tree()); |
---|
| 557 | } |
---|
| 558 | return true; |
---|
| 559 | }, |
---|
[2471] | 560 | |
---|
[2397] | 561 | /** Function: onRoster |
---|
| 562 | * |
---|
| 563 | * Roster iq handler |
---|
| 564 | */ |
---|
[2471] | 565 | |
---|
[2397] | 566 | onRoster : function(msg) |
---|
| 567 | { |
---|
[2471] | 568 | var roster_items = msg.firstChild.getElementsByTagName('item'); |
---|
[2397] | 569 | |
---|
| 570 | for (var i = 0; i < roster_items.length; i++) |
---|
| 571 | { |
---|
[2471] | 572 | with(roster_items[i]) |
---|
| 573 | { |
---|
| 574 | var groups = getElementsByTagName('group'); |
---|
| 575 | var group_array = []; |
---|
| 576 | |
---|
| 577 | for( var g = 0 ; g < groups.length; g++ ) |
---|
| 578 | { |
---|
| 579 | if( groups[g].hasChildNodes() ) |
---|
| 580 | group_array[group_array.length] = groups[g].firstChild.nodeValue; |
---|
| 581 | } |
---|
| 582 | |
---|
[2577] | 583 | if( getAttribute('ask') ) |
---|
| 584 | TrophyIM.rosterObj.addContact(getAttribute('jid'), getAttribute('ask'), getAttribute('name'), group_array); |
---|
| 585 | else |
---|
| 586 | TrophyIM.rosterObj.addContact(getAttribute('jid'), getAttribute('subscription'), getAttribute('name'), group_array); |
---|
[2471] | 587 | } |
---|
[2397] | 588 | } |
---|
[2471] | 589 | |
---|
[2397] | 590 | if ( msg.getAttribute('type') == 'set' ) |
---|
| 591 | { |
---|
[2471] | 592 | var _iq = $iq({type: 'reply', id: msg.getAttribute('id'), to: msg.getAttribute('from')}); |
---|
| 593 | TrophyIM.connection.send( _iq.tree()); |
---|
[2397] | 594 | } |
---|
| 595 | |
---|
| 596 | return true; |
---|
| 597 | }, |
---|
| 598 | /** Function: onPresence |
---|
| 599 | * |
---|
| 600 | * Presence handler |
---|
| 601 | */ |
---|
| 602 | onPresence : function(msg) |
---|
| 603 | { |
---|
| 604 | Strophe.debug("Presence handler"); |
---|
[2471] | 605 | var type = msg.getAttribute('type') ? msg.getAttribute('type') : 'available'; |
---|
| 606 | var show = msg.getElementsByTagName('show').length ? Strophe.getText(msg.getElementsByTagName('show')[0]) : type; |
---|
| 607 | var status = msg.getElementsByTagName('status').length ? Strophe.getText(msg.getElementsByTagName('status')[0]) : ''; |
---|
| 608 | var priority = msg.getElementsByTagName('priority').length ? parseInt(Strophe.getText(msg.getElementsByTagName('priority')[0])) : 0; |
---|
| 609 | |
---|
| 610 | TrophyIM.rosterObj.setPresence(msg.getAttribute('from'), priority, show, status); |
---|
[2397] | 611 | |
---|
| 612 | return true; |
---|
| 613 | }, |
---|
| 614 | /** Function: onMessage |
---|
| 615 | * |
---|
| 616 | * Message handler |
---|
| 617 | */ |
---|
| 618 | onMessage : function(msg) |
---|
| 619 | { |
---|
[2713] | 620 | var checkTime = function(i) |
---|
| 621 | { |
---|
| 622 | if ( i < 10 ) i= "0" + i; |
---|
| 623 | |
---|
| 624 | return i; |
---|
| 625 | }; |
---|
| 626 | |
---|
| 627 | var data = new Date(); |
---|
| 628 | var dtNow = checkTime(data.getHours()) + ":" + checkTime(data.getMinutes()) + ":" + checkTime(data.getSeconds()); |
---|
| 629 | |
---|
| 630 | var from = msg.getAttribute('from'); |
---|
| 631 | var type = msg.getAttribute('type'); |
---|
| 632 | var elems = msg.getElementsByTagName('body'); |
---|
| 633 | var delay = ( msg.getElementsByTagName('delay') ) ? msg.getElementsByTagName('delay') : null; |
---|
| 634 | var stamp = ( delay[0] != null ) ? delay[0].getAttribute('stamp') : dtNow; |
---|
[2397] | 635 | |
---|
| 636 | if ( (type == 'chat' || type == 'normal') && elems.length > 0 ) |
---|
| 637 | { |
---|
| 638 | var barejid = Strophe.getBareJidFromJid(from); |
---|
| 639 | var jid_lower = barejid.toLowerCase(); |
---|
[2471] | 640 | var contact = ""; |
---|
[2491] | 641 | contact = barejid.toLowerCase(); |
---|
| 642 | contact = contact.substring(0, contact.indexOf('@')); |
---|
| 643 | |
---|
[2471] | 644 | if( TrophyIM.rosterObj.roster[barejid] ) |
---|
[2397] | 645 | { |
---|
[2471] | 646 | if( TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name'] ) |
---|
| 647 | { |
---|
| 648 | contact = TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name']; |
---|
| 649 | } |
---|
[2397] | 650 | } |
---|
[2491] | 651 | |
---|
[2670] | 652 | var _message = document.createElement("div"); |
---|
| 653 | _message.innerHTML = Strophe.getText(elems[0]); |
---|
[2397] | 654 | |
---|
[2670] | 655 | var scripts = _message.getElementsByTagName( 'script' ); |
---|
| 656 | |
---|
| 657 | for ( var i = 0; i < scripts.length; i++ ) |
---|
| 658 | _message.removeChild( scripts[ i-- ] ); |
---|
| 659 | |
---|
[2678] | 660 | _message.innerHTML = _message.innerHTML.replace(/^\s+|\s+$|^\n|\n$/g,""); |
---|
[2670] | 661 | |
---|
| 662 | if ( _message.hasChildNodes( ) ) |
---|
| 663 | { |
---|
| 664 | var message = |
---|
| 665 | { |
---|
[2713] | 666 | contact : "[" + stamp + "] <font style='font-weight:bold; color:black;'>" + contact + "</font>", |
---|
[2670] | 667 | msg : _message.innerHTML |
---|
| 668 | }; |
---|
| 669 | |
---|
| 670 | TrophyIM.makeChat(from); //Make sure we have a chat window |
---|
| 671 | TrophyIM.addMessage(message, jid_lower); |
---|
| 672 | } |
---|
[2397] | 673 | } |
---|
[2471] | 674 | |
---|
[2397] | 675 | return true; |
---|
| 676 | }, |
---|
[2471] | 677 | |
---|
[2397] | 678 | /** Function: makeChat |
---|
| 679 | * |
---|
| 680 | * Make sure chat window to given fulljid exists, switching chat context to |
---|
| 681 | * given resource |
---|
| 682 | */ |
---|
[2471] | 683 | |
---|
[2397] | 684 | makeChat : function(fulljid) |
---|
| 685 | { |
---|
[2471] | 686 | var barejid = Strophe.getBareJidFromJid(fulljid); |
---|
| 687 | var titleWindow = ""; |
---|
[2397] | 688 | |
---|
| 689 | var paramsChatBox = |
---|
| 690 | { |
---|
[2471] | 691 | 'idChatBox' : barejid + "__chatBox", |
---|
| 692 | 'jidTo' : barejid, |
---|
[2397] | 693 | 'path_jabberit' : path_jabberit |
---|
| 694 | }; |
---|
[2511] | 695 | |
---|
| 696 | titleWindow = barejid.toLowerCase(); |
---|
| 697 | titleWindow = titleWindow.substring(0, titleWindow.indexOf('@')); |
---|
| 698 | |
---|
[2471] | 699 | if( TrophyIM.rosterObj.roster[barejid] ) |
---|
| 700 | { |
---|
| 701 | if( TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name'] ) |
---|
| 702 | { |
---|
| 703 | titleWindow = TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name']; |
---|
| 704 | } |
---|
| 705 | } |
---|
| 706 | |
---|
[2631] | 707 | // Position Top |
---|
| 708 | TrophyIM.posWindow.top = TrophyIM.posWindow.top + 10; |
---|
| 709 | if( TrophyIM.posWindow.top > 200 ) |
---|
| 710 | TrophyIM.posWindow.top = 100; |
---|
| 711 | |
---|
| 712 | // Position Left |
---|
| 713 | TrophyIM.posWindow.left = TrophyIM.posWindow.left + 5; |
---|
| 714 | if( TrophyIM.posWindow.left > 455 ) |
---|
| 715 | TrophyIM.posWindow.left = 400; |
---|
| 716 | |
---|
[2397] | 717 | var winChatBox = |
---|
| 718 | { |
---|
[2471] | 719 | id_window : "window_chat_area_" + barejid, |
---|
[2397] | 720 | width : 387, |
---|
| 721 | height : 365, |
---|
[2631] | 722 | top : TrophyIM.posWindow.top, |
---|
| 723 | left : TrophyIM.posWindow.left, |
---|
[2397] | 724 | draggable : true, |
---|
| 725 | visible : "display", |
---|
| 726 | resizable : true, |
---|
[2670] | 727 | zindex : loadscript.getZIndex(), |
---|
[2471] | 728 | title : titleWindow, |
---|
[2397] | 729 | closeAction : "hidden", |
---|
[2670] | 730 | content : loadscript.parse("chat_box","chatBox.xsl", paramsChatBox) |
---|
[2397] | 731 | } |
---|
| 732 | |
---|
[2471] | 733 | _winBuild(winChatBox); |
---|
[2511] | 734 | |
---|
[2599] | 735 | // Notification New Message |
---|
[2670] | 736 | loadscript.notification(); |
---|
[2599] | 737 | |
---|
[2511] | 738 | // Photo User; |
---|
[2670] | 739 | loadscript.getPhotoUser(barejid); |
---|
[2397] | 740 | |
---|
[2670] | 741 | loadscript.configEvents( document.getElementById( barejid + '__sendBox'), |
---|
[2397] | 742 | 'onkeyup', function(e) |
---|
| 743 | { |
---|
| 744 | if( e.keyCode == 13 ) |
---|
| 745 | { |
---|
[2471] | 746 | TrophyIM.sendMessage( barejid ); |
---|
| 747 | document.getElementById( barejid + '__sendBox').value = ''; |
---|
[2397] | 748 | return false; |
---|
| 749 | } |
---|
| 750 | } |
---|
| 751 | ); |
---|
| 752 | }, |
---|
| 753 | |
---|
| 754 | /** Function addContacts |
---|
| 755 | * |
---|
| 756 | * Parameters: |
---|
[2437] | 757 | * (string) jidFrom |
---|
| 758 | * (string) jidTo |
---|
[2397] | 759 | * (string) name |
---|
| 760 | * (string) group |
---|
| 761 | */ |
---|
| 762 | |
---|
[2584] | 763 | addContact : function( jidTo, name, group ) |
---|
[2397] | 764 | { |
---|
[2577] | 765 | // Add Contact |
---|
[2491] | 766 | var _id = TrophyIM.connection.getUniqueId('add'); |
---|
[2471] | 767 | var newContact = $iq({type: 'set', id: _id }); |
---|
[2397] | 768 | newContact = newContact.c('query').attrs({xmlns : 'jabber:iq:roster'}); |
---|
[2471] | 769 | newContact = newContact.c('item').attrs({jid: jidTo, name:name }); |
---|
[2397] | 770 | newContact = newContact.c('group').t(group).tree(); |
---|
| 771 | |
---|
| 772 | TrophyIM.connection.send(newContact); |
---|
| 773 | }, |
---|
| 774 | |
---|
| 775 | /** Function: addMessage |
---|
| 776 | * |
---|
| 777 | * Parameters: |
---|
| 778 | * (string) msg - the message to add |
---|
| 779 | * (string) jid - the jid of chat box to add the message to. |
---|
| 780 | */ |
---|
| 781 | |
---|
| 782 | addMessage : function(msg, jid) |
---|
| 783 | { |
---|
| 784 | var chatBox = document.getElementById(jid + "__chatBox"); |
---|
| 785 | var messageDiv = document.createElement("div"); |
---|
| 786 | |
---|
| 787 | messageDiv.style.margin = "3px 0px 3px 3px"; |
---|
| 788 | messageDiv.innerHTML = msg.contact + " : " + msg.msg ; |
---|
| 789 | |
---|
| 790 | chatBox.appendChild(messageDiv); |
---|
| 791 | chatBox.scrollTop = chatBox.scrollHeight; |
---|
| 792 | }, |
---|
| 793 | |
---|
[2584] | 794 | /** Function : renameContact |
---|
| 795 | * |
---|
| 796 | * |
---|
| 797 | */ |
---|
| 798 | |
---|
| 799 | renameContact : function( jid, index ) |
---|
| 800 | { |
---|
| 801 | // Name |
---|
| 802 | var name = TrophyIM.rosterObj.roster[jid].contact.name; |
---|
| 803 | |
---|
| 804 | if(( name = prompt("Informe um novo nome para " + name + "!", name ))) |
---|
| 805 | if(( name = name.replace(/^\s+|\s+$|^\n|\n$/g,"")) == "" ) |
---|
| 806 | name = ""; |
---|
| 807 | |
---|
| 808 | if( name == null || name == "") |
---|
| 809 | name = ""; |
---|
| 810 | |
---|
| 811 | var jidTo = jid |
---|
| 812 | var name = ( name ) ? name : TrophyIM.rosterObj.roster[jid].contact.name; |
---|
| 813 | var group = TrophyIM.rosterObj.roster[jid].contact.groups[0]; |
---|
| 814 | |
---|
| 815 | TrophyIM.addContact( jidTo, name, group ); |
---|
| 816 | |
---|
| 817 | document.getElementById('itenContact_' + jid + '_' + index).innerHTML = name; |
---|
| 818 | }, |
---|
| 819 | |
---|
| 820 | /** Function : renameGroup |
---|
| 821 | * |
---|
| 822 | * |
---|
| 823 | */ |
---|
| 824 | |
---|
| 825 | renameGroup : function( jid, index) |
---|
| 826 | { |
---|
| 827 | var group = TrophyIM.rosterObj.roster[jid].contact.groups[0]; |
---|
| 828 | var presence = TrophyIM.rosterObj.roster[jid].presence; |
---|
| 829 | |
---|
| 830 | // Group |
---|
| 831 | if(( group = prompt("Informe um novo grupo ou deixe em branco", group ))) |
---|
| 832 | if(( group = group.replace(/^\s+|\s+$|^\n|\n$/g,"")) == "" ) |
---|
| 833 | group = ""; |
---|
| 834 | |
---|
| 835 | if( group == null || group == "") |
---|
| 836 | group = ""; |
---|
| 837 | |
---|
| 838 | var jidTo = TrophyIM.rosterObj.roster[jid].contact.jid; |
---|
| 839 | var name = TrophyIM.rosterObj.roster[jid].contact.name; |
---|
| 840 | var group = ( group ) ? group : TrophyIM.rosterObj.roster[jid].contact.groups[0]; |
---|
| 841 | |
---|
| 842 | TrophyIM.rosterObj.removeContact( jid ); |
---|
| 843 | |
---|
| 844 | TrophyIM.addContact( jidTo, name, group ); |
---|
| 845 | |
---|
| 846 | document.getElementById("JabberIMRoster").innerHTML = ""; |
---|
| 847 | |
---|
| 848 | TrophyIM.renderRoster(); |
---|
| 849 | |
---|
| 850 | setTimeout(function() |
---|
| 851 | { |
---|
| 852 | for( var i in presence ) |
---|
[2670] | 853 | { |
---|
| 854 | if ( presence[ i ].constructor == Function ) |
---|
| 855 | continue; |
---|
| 856 | |
---|
[2584] | 857 | TrophyIM.rosterObj.setPresence( jid, presence[i].priority, presence[i].show, presence[i].status); |
---|
[2670] | 858 | } |
---|
[2584] | 859 | },500); |
---|
| 860 | }, |
---|
| 861 | |
---|
[2437] | 862 | /** Function: removeContact |
---|
| 863 | * |
---|
| 864 | * Parameters: |
---|
| 865 | * (string) jidTo |
---|
| 866 | */ |
---|
| 867 | |
---|
[2491] | 868 | removeContact : function(jidTo, indexTo) |
---|
[2437] | 869 | { |
---|
[2491] | 870 | var divItenContact = null; |
---|
| 871 | var spanShow = null; |
---|
[2437] | 872 | |
---|
[2491] | 873 | if( ( divItenContact = document.getElementById('itenContact_' + jidTo + '_' + indexTo ))) |
---|
[2437] | 874 | { |
---|
[2491] | 875 | spanShow = document.getElementById('span_show_itenContact_' + jidTo + '_' + indexTo ) |
---|
| 876 | |
---|
| 877 | spanShow.parentNode.removeChild(spanShow); |
---|
| 878 | |
---|
[2670] | 879 | loadscript.removeGroup( divItenContact.parentNode ); |
---|
[2471] | 880 | |
---|
[2437] | 881 | divItenContact.parentNode.removeChild(divItenContact); |
---|
[2577] | 882 | |
---|
[2437] | 883 | // Remove Contact |
---|
[2577] | 884 | var _id = TrophyIM.connection.getUniqueId(); |
---|
[2471] | 885 | var delContact = $iq({type: 'set', id: _id}) |
---|
[2437] | 886 | delContact = delContact.c('query').attrs({xmlns : 'jabber:iq:roster'}); |
---|
[2471] | 887 | delContact = delContact.c('item').attrs({jid: jidTo, subscription:'remove'}).tree(); |
---|
[2577] | 888 | |
---|
| 889 | TrophyIM.connection.send( delContact ); |
---|
| 890 | |
---|
| 891 | // Remove Contact |
---|
| 892 | var _id = TrophyIM.connection.getUniqueId(); |
---|
| 893 | var _delContact_ = $iq({type: 'set', id: _id}) |
---|
| 894 | _delContact_ = _delContact_.c('query').attrs({xmlns : 'jabber:iq:private'}); |
---|
| 895 | _delContact_ = _delContact_.c('storage').attrs({xmlns : 'storage:metacontacts'}).tree(); |
---|
| 896 | |
---|
| 897 | TrophyIM.connection.send( _delContact_ ); |
---|
[2437] | 898 | } |
---|
| 899 | }, |
---|
| 900 | |
---|
[2397] | 901 | /** Function: renderRoster |
---|
| 902 | * |
---|
| 903 | * Renders roster, looking only for jids flagged by setPresence as having |
---|
| 904 | * changed. |
---|
| 905 | */ |
---|
| 906 | |
---|
| 907 | renderRoster : function() |
---|
| 908 | { |
---|
[2471] | 909 | var roster_div = document.getElementById('JabberIMRoster'); |
---|
| 910 | |
---|
| 911 | if( roster_div ) |
---|
[2397] | 912 | { |
---|
[2471] | 913 | var users = new Array(); |
---|
[2397] | 914 | |
---|
[2629] | 915 | var loading_gif = document.getElementById("JabberIMRosterLoadingGif"); |
---|
| 916 | |
---|
| 917 | if( loading_gif.style.display == "block" ) |
---|
| 918 | loading_gif.style.display = "none"; |
---|
| 919 | |
---|
[2471] | 920 | for( var user in TrophyIM.rosterObj.roster ) |
---|
[2397] | 921 | { |
---|
[2670] | 922 | if ( TrophyIM.rosterObj.roster[ user ].constructor == Function ) |
---|
| 923 | continue; |
---|
| 924 | |
---|
[2471] | 925 | users[users.length] = TrophyIM.rosterObj.roster[user].contact.jid; |
---|
| 926 | } |
---|
| 927 | |
---|
| 928 | users.sort(); |
---|
| 929 | |
---|
| 930 | var groups = new Array(); |
---|
| 931 | var flagGeral = false; |
---|
| 932 | |
---|
| 933 | for (var group in TrophyIM.rosterObj.groups) |
---|
| 934 | { |
---|
[2670] | 935 | if ( TrophyIM.rosterObj.groups[ group ].constructor == Function ) |
---|
| 936 | continue; |
---|
| 937 | |
---|
[2471] | 938 | if( group ) |
---|
| 939 | groups[groups.length] = group; |
---|
[2397] | 940 | |
---|
[2471] | 941 | if( group == "Geral" ) |
---|
| 942 | flagGeral = true; |
---|
| 943 | } |
---|
| 944 | |
---|
[2491] | 945 | if( !flagGeral && users.length > 0 ) |
---|
[2471] | 946 | groups[groups.length] = "Geral"; |
---|
[2397] | 947 | |
---|
[2471] | 948 | groups.sort(); |
---|
| 949 | |
---|
| 950 | for ( var i = 0; i < groups.length; i++ ) |
---|
| 951 | { |
---|
| 952 | TrophyIM.renderGroups( groups[i] , roster_div ); |
---|
[2397] | 953 | } |
---|
[2471] | 954 | |
---|
| 955 | TrophyIM.renderItensGroup( users, roster_div ); |
---|
[2397] | 956 | } |
---|
| 957 | |
---|
[2647] | 958 | TrophyIM._timeOut.renderRoster = setTimeout("TrophyIM.renderRoster()", 1000 ); |
---|
[2397] | 959 | }, |
---|
| 960 | |
---|
| 961 | /** Function: renderGroups |
---|
| 962 | * |
---|
| 963 | * |
---|
| 964 | */ |
---|
| 965 | |
---|
| 966 | renderGroups: function( nameGroup, element ) |
---|
| 967 | { |
---|
| 968 | var _addGroup = function() |
---|
| 969 | { |
---|
[2471] | 970 | var _nameGroup = nameGroup; |
---|
| 971 | var _element = element; |
---|
| 972 | |
---|
[2397] | 973 | var paramsGroup = |
---|
| 974 | { |
---|
[2471] | 975 | 'nameGroup' : _nameGroup, |
---|
[2397] | 976 | 'path_jabberit' : path_jabberit |
---|
| 977 | } |
---|
| 978 | |
---|
[2670] | 979 | _element.innerHTML += loadscript.parse("group","groups.xsl", paramsGroup); |
---|
[2397] | 980 | } |
---|
| 981 | |
---|
| 982 | if( !element.hasChildNodes() ) |
---|
| 983 | { |
---|
[2471] | 984 | _addGroup(); |
---|
[2397] | 985 | } |
---|
| 986 | else |
---|
| 987 | { |
---|
[2471] | 988 | var _NodeChild = element.firstChild; |
---|
| 989 | var flagAdd = false; |
---|
[2397] | 990 | |
---|
[2471] | 991 | while( _NodeChild ) |
---|
[2397] | 992 | { |
---|
[2471] | 993 | if( _NodeChild.childNodes[0].nodeName.toLowerCase() === "span" ) |
---|
[2397] | 994 | { |
---|
[2471] | 995 | if( _NodeChild.childNodes[0].childNodes[0].nodeValue === nameGroup ) |
---|
| 996 | { |
---|
| 997 | flagAdd = true; |
---|
| 998 | } |
---|
[2397] | 999 | } |
---|
| 1000 | |
---|
[2471] | 1001 | _NodeChild = _NodeChild.nextSibling; |
---|
[2397] | 1002 | } |
---|
[2471] | 1003 | |
---|
| 1004 | if( !flagAdd ) |
---|
| 1005 | { |
---|
| 1006 | _addGroup(); |
---|
| 1007 | } |
---|
[2397] | 1008 | } |
---|
| 1009 | }, |
---|
| 1010 | |
---|
| 1011 | /** Function: renderItensGroup |
---|
| 1012 | * |
---|
| 1013 | * |
---|
| 1014 | */ |
---|
| 1015 | |
---|
| 1016 | renderItensGroup : function( users, element ) |
---|
| 1017 | { |
---|
[2471] | 1018 | var addItem = function() |
---|
[2397] | 1019 | { |
---|
| 1020 | if( arguments.length > 0 ) |
---|
| 1021 | { |
---|
| 1022 | var objContact = arguments[0]; |
---|
[2471] | 1023 | var group = arguments[1]; |
---|
| 1024 | var element = arguments[2]; |
---|
| 1025 | var index = arguments[3]; |
---|
[2706] | 1026 | var showOffline = loadscript.getShowContactsOffline(); |
---|
| 1027 | |
---|
[2471] | 1028 | var itensJid = document.getElementById( 'itenContact_' + objContact.contact.jid + '_' + index ); |
---|
[2670] | 1029 | |
---|
[2397] | 1030 | if( itensJid == null ) |
---|
| 1031 | { |
---|
| 1032 | // Name |
---|
| 1033 | var nameContact = ""; |
---|
| 1034 | |
---|
| 1035 | if ( objContact.contact.name ) |
---|
| 1036 | nameContact = objContact.contact.name; |
---|
| 1037 | else |
---|
| 1038 | { |
---|
| 1039 | nameContact = objContact.contact.jid; |
---|
| 1040 | nameContact = nameContact.substring(0, nameContact.indexOf('@')); |
---|
| 1041 | } |
---|
| 1042 | |
---|
| 1043 | // Presence e Status |
---|
| 1044 | var presence = "unavailable"; |
---|
| 1045 | var status = ""; |
---|
| 1046 | var statusDisplay = "none"; |
---|
| 1047 | |
---|
| 1048 | if (objContact.presence) |
---|
| 1049 | { |
---|
| 1050 | for (var resource in objContact.presence) |
---|
| 1051 | { |
---|
[2670] | 1052 | if ( objContact.presence[resource].constructor == Function ) |
---|
| 1053 | continue; |
---|
| 1054 | |
---|
[2471] | 1055 | if( objContact.presence[resource].show != 'invisible' ) |
---|
| 1056 | presence = objContact.presence[resource].show; |
---|
| 1057 | |
---|
[2577] | 1058 | if( objContact.contact.subscription != "both") |
---|
| 1059 | presence = 'subscription'; |
---|
| 1060 | |
---|
[2397] | 1061 | if( objContact.presence[resource].status ) |
---|
| 1062 | { |
---|
[2577] | 1063 | status = " ( " + objContact.presence[resource].status + " ) "; |
---|
[2397] | 1064 | statusDisplay = "block"; |
---|
| 1065 | } |
---|
| 1066 | } |
---|
| 1067 | } |
---|
| 1068 | |
---|
| 1069 | var paramsContact = |
---|
| 1070 | { |
---|
[2706] | 1071 | divDisplay : "block", |
---|
[2577] | 1072 | id : 'itenContact_' + objContact.contact.jid + '_' + index , |
---|
[2670] | 1073 | index : ((index == 0 ) ? "0" : index), |
---|
[2706] | 1074 | jid : objContact.contact.jid, |
---|
| 1075 | nameContact : nameContact, |
---|
[2577] | 1076 | path_jabberit : path_jabberit, |
---|
| 1077 | presence : presence, |
---|
[2706] | 1078 | spanDisplay : statusDisplay, |
---|
[2577] | 1079 | status : status, |
---|
| 1080 | statusColor : "black", |
---|
| 1081 | subscription : objContact.contact.subscription |
---|
[2397] | 1082 | } |
---|
| 1083 | |
---|
[2577] | 1084 | // Authorization |
---|
| 1085 | if( objContact.contact.subscription != "both" ) |
---|
| 1086 | { |
---|
| 1087 | |
---|
| 1088 | switch(objContact.contact.subscription) |
---|
| 1089 | { |
---|
| 1090 | case "none" : |
---|
| 1091 | |
---|
| 1092 | paramsContact.status = " (( PEDIR AUTORIZAÇAO ! )) "; |
---|
| 1093 | paramsContact.statusColor = "red"; |
---|
| 1094 | break; |
---|
| 1095 | |
---|
| 1096 | case "to" : |
---|
| 1097 | |
---|
| 1098 | paramsContact.status = " (( CONTATO PEDE AUTORIZAÇÃO ! )) "; |
---|
| 1099 | paramsContact.statusColor = "orange"; |
---|
| 1100 | break; |
---|
| 1101 | |
---|
| 1102 | case "from" : |
---|
| 1103 | |
---|
| 1104 | paramsContact.status = " (( AUTORIZAR ? )) "; |
---|
| 1105 | paramsContact.statusColor = "green"; |
---|
| 1106 | break; |
---|
| 1107 | |
---|
| 1108 | case "subscribe" : |
---|
| 1109 | |
---|
| 1110 | paramsContact.status = " (( AUTORIZAÇÃO ENVIADA ! )) "; |
---|
| 1111 | paramsContact.statusColor = "red"; |
---|
| 1112 | break; |
---|
| 1113 | |
---|
| 1114 | case "not-in-roster" : |
---|
| 1115 | |
---|
| 1116 | paramsContact.status = " (( QUERO ADICIONÁ-LO(A) ! POSSO ? )) "; |
---|
| 1117 | paramsContact.statusColor = "orange"; |
---|
| 1118 | break; |
---|
| 1119 | |
---|
| 1120 | default: |
---|
| 1121 | paramsContact.status = " ( " + objContact.contact.subscription + " ) "; |
---|
| 1122 | } |
---|
| 1123 | } |
---|
| 1124 | |
---|
[2471] | 1125 | if( group != "") |
---|
[2397] | 1126 | { |
---|
[2471] | 1127 | var _NodeChild = element.firstChild; |
---|
| 1128 | |
---|
| 1129 | while( _NodeChild ) |
---|
[2397] | 1130 | { |
---|
[2471] | 1131 | if( _NodeChild.childNodes[0].nodeName.toLowerCase() === "span" ) |
---|
| 1132 | { |
---|
| 1133 | if( _NodeChild.childNodes[0].childNodes[0].nodeValue === group ) |
---|
| 1134 | { |
---|
[2670] | 1135 | _NodeChild.innerHTML += loadscript.parse("itens_group", "itensGroup.xsl", paramsContact); |
---|
[2471] | 1136 | } |
---|
| 1137 | } |
---|
[2397] | 1138 | |
---|
[2471] | 1139 | _NodeChild = _NodeChild.nextSibling; |
---|
[2397] | 1140 | } |
---|
[2471] | 1141 | } |
---|
[2397] | 1142 | } |
---|
| 1143 | else |
---|
| 1144 | { |
---|
[2577] | 1145 | |
---|
[2397] | 1146 | // Presence e Status |
---|
| 1147 | var presence = "unavailable"; |
---|
| 1148 | var status = ""; |
---|
[2577] | 1149 | var statusColor = "black"; |
---|
[2397] | 1150 | var statusDisplay = "none"; |
---|
| 1151 | |
---|
[2584] | 1152 | if ( objContact.presence ) |
---|
[2397] | 1153 | { |
---|
[2471] | 1154 | for ( var resource in objContact.presence ) |
---|
[2397] | 1155 | { |
---|
[2670] | 1156 | if ( objContact.presence[resource].constructor == Function ) |
---|
| 1157 | continue; |
---|
| 1158 | |
---|
[2491] | 1159 | if( objContact.presence[resource].show != 'invisible' ) |
---|
| 1160 | presence = objContact.presence[resource].show; |
---|
| 1161 | |
---|
[2577] | 1162 | if( objContact.contact.subscription != "both") |
---|
| 1163 | presence = 'subscription'; |
---|
| 1164 | |
---|
[2397] | 1165 | if( objContact.presence[resource].status ) |
---|
| 1166 | { |
---|
[2577] | 1167 | status = " ( " + objContact.presence[resource].status + " ) "; |
---|
[2397] | 1168 | statusDisplay = "block"; |
---|
| 1169 | } |
---|
[2471] | 1170 | } |
---|
| 1171 | } |
---|
| 1172 | |
---|
| 1173 | var is_open = itensJid.parentNode.childNodes[0].style.backgroundImage; |
---|
| 1174 | is_open = is_open.indexOf("arrow_down.gif"); |
---|
| 1175 | |
---|
[2577] | 1176 | // Authorization |
---|
| 1177 | if( objContact.contact.subscription != "both" ) |
---|
| 1178 | { |
---|
| 1179 | switch(objContact.contact.subscription) |
---|
| 1180 | { |
---|
| 1181 | case "none" : |
---|
| 1182 | |
---|
| 1183 | status = " (( PEDIR AUTORIZAÇAO ! )) "; |
---|
| 1184 | statusColor = "red"; |
---|
| 1185 | break; |
---|
| 1186 | |
---|
| 1187 | case "to" : |
---|
| 1188 | |
---|
| 1189 | status = " (( CONTATO PEDE AUTORIZAÇÃO ! )) "; |
---|
| 1190 | statusColor = "orange"; |
---|
| 1191 | break; |
---|
| 1192 | |
---|
| 1193 | case "from" : |
---|
| 1194 | |
---|
| 1195 | status = " (( AUTORIZAR ? )) "; |
---|
| 1196 | statusColor = "green"; |
---|
| 1197 | break; |
---|
| 1198 | |
---|
| 1199 | case "subscribe" : |
---|
| 1200 | |
---|
| 1201 | status = " (( AUTORIZAÇÃO ENVIADA ! )) "; |
---|
| 1202 | statusColor = "red"; |
---|
| 1203 | break; |
---|
| 1204 | |
---|
| 1205 | case "not-in-roster" : |
---|
| 1206 | |
---|
| 1207 | status = " (( QUERO ADICIONÁ-LO(A) ! POSSO ? )) "; |
---|
| 1208 | statusColor = "orange"; |
---|
| 1209 | break; |
---|
| 1210 | |
---|
| 1211 | default: |
---|
| 1212 | status = " ( " + objContact.contact.subscription + " ) "; |
---|
| 1213 | } |
---|
| 1214 | |
---|
| 1215 | statusDisplay = "block"; |
---|
| 1216 | } |
---|
| 1217 | |
---|
[2471] | 1218 | with ( document.getElementById('span_show_' + 'itenContact_' + objContact.contact.jid + '_' + index ) ) |
---|
| 1219 | { |
---|
[2706] | 1220 | /*if( is_open > 0 ) |
---|
[2471] | 1221 | { |
---|
| 1222 | style.display = statusDisplay; |
---|
[2577] | 1223 | style.color = statusColor; |
---|
[2471] | 1224 | innerHTML = status; |
---|
[2706] | 1225 | }*/ |
---|
| 1226 | |
---|
| 1227 | if( presence == "unavailable" && !showOffline ) |
---|
| 1228 | { |
---|
| 1229 | style.display = "none"; |
---|
[2397] | 1230 | } |
---|
[2706] | 1231 | else |
---|
| 1232 | { |
---|
| 1233 | if( is_open > 0 ) |
---|
| 1234 | { |
---|
| 1235 | style.display = statusDisplay; |
---|
| 1236 | style.color = statusColor; |
---|
| 1237 | innerHTML = status; |
---|
| 1238 | } |
---|
| 1239 | } |
---|
[2397] | 1240 | } |
---|
[2471] | 1241 | |
---|
[2706] | 1242 | if( presence == "unavailable" && !showOffline ) |
---|
| 1243 | itensJid.style.display = "none"; |
---|
| 1244 | else |
---|
| 1245 | { |
---|
| 1246 | if( is_open > 0 ) |
---|
| 1247 | { |
---|
| 1248 | itensJid.style.display = "block"; |
---|
| 1249 | } |
---|
| 1250 | } |
---|
| 1251 | |
---|
[2626] | 1252 | itensJid.style.background = "url('"+path_jabberit+"templates/default/images/" + presence + ".gif') no-repeat center left"; |
---|
[2397] | 1253 | } |
---|
[2706] | 1254 | |
---|
| 1255 | // Contact OffLine |
---|
| 1256 | if( !objContact.presence && !showOffline ) |
---|
| 1257 | { |
---|
| 1258 | with ( document.getElementById('span_show_' + 'itenContact_' + objContact.contact.jid + '_' + index )) |
---|
| 1259 | { |
---|
| 1260 | style.display = "none"; |
---|
| 1261 | } |
---|
| 1262 | |
---|
| 1263 | with ( document.getElementById('itenContact_' + objContact.contact.jid + '_' + index ) ) |
---|
| 1264 | { |
---|
| 1265 | style.display = "none"; |
---|
| 1266 | } |
---|
| 1267 | } |
---|
[2397] | 1268 | } |
---|
| 1269 | } |
---|
| 1270 | |
---|
| 1271 | for( var i = 0 ; i < users.length; i++ ) |
---|
| 1272 | { |
---|
[2670] | 1273 | if( TrophyIM.rosterObj.roster[users[i]].contact.jid != Base64.decode(loadscript.getUserCurrent().jid) ) |
---|
[2471] | 1274 | { |
---|
[2511] | 1275 | if( TrophyIM.rosterObj.roster[users[i]].contact.groups ) |
---|
[2471] | 1276 | { |
---|
[2511] | 1277 | var groups = TrophyIM.rosterObj.roster[users[i]].contact.groups; |
---|
| 1278 | |
---|
| 1279 | if( groups.length > 0 ) |
---|
| 1280 | { |
---|
| 1281 | for( var j = 0; j < groups.length; j++ ) |
---|
[2670] | 1282 | { |
---|
[2511] | 1283 | addItem( TrophyIM.rosterObj.roster[users[i]], groups[j], element, j ); |
---|
[2670] | 1284 | } |
---|
[2511] | 1285 | } |
---|
| 1286 | else |
---|
| 1287 | { |
---|
| 1288 | addItem( TrophyIM.rosterObj.roster[users[i]], "Geral", element, 0 ); |
---|
| 1289 | } |
---|
[2471] | 1290 | } |
---|
[2397] | 1291 | else |
---|
[2471] | 1292 | { |
---|
| 1293 | addItem( TrophyIM.rosterObj.roster[users[i]], "Geral", element, 0 ); |
---|
| 1294 | } |
---|
| 1295 | } |
---|
[2397] | 1296 | } |
---|
| 1297 | }, |
---|
| 1298 | |
---|
| 1299 | /** Function: rosterClick |
---|
| 1300 | * |
---|
| 1301 | * Handles actions when a roster item is clicked |
---|
| 1302 | */ |
---|
| 1303 | |
---|
| 1304 | rosterClick : function(fulljid) |
---|
| 1305 | { |
---|
| 1306 | TrophyIM.makeChat(fulljid); |
---|
| 1307 | }, |
---|
| 1308 | |
---|
| 1309 | |
---|
| 1310 | /** Function SetAutorization |
---|
| 1311 | * |
---|
| 1312 | */ |
---|
| 1313 | |
---|
[2491] | 1314 | setAutorization : function( jidTo, jidFrom, _typeSubscription ) |
---|
[2397] | 1315 | { |
---|
[2491] | 1316 | var _id = TrophyIM.connection.getUniqueId(); |
---|
| 1317 | |
---|
| 1318 | TrophyIM.connection.send($pres( ).attrs( {to: jidTo, from: jidFrom, type: _typeSubscription, id: _id}).tree()); |
---|
[2397] | 1319 | }, |
---|
| 1320 | |
---|
| 1321 | /** Function: setPresence |
---|
| 1322 | * |
---|
| 1323 | */ |
---|
| 1324 | |
---|
[2647] | 1325 | setPresence : function( _type ) |
---|
[2397] | 1326 | { |
---|
[2647] | 1327 | if( _type != 'status') |
---|
[2511] | 1328 | { |
---|
[2647] | 1329 | if( _type == "unavailable") |
---|
[2641] | 1330 | { |
---|
[2647] | 1331 | var loading_gif = document.getElementById("JabberIMRosterLoadingGif"); |
---|
| 1332 | |
---|
| 1333 | if( TrophyIM._timeOut.renderRoster != null ) |
---|
| 1334 | clearTimeout(TrophyIM._timeOut.renderRoster); |
---|
| 1335 | |
---|
| 1336 | TrophyIM.connection.send($pres({type : _type}).tree()); |
---|
| 1337 | |
---|
| 1338 | for( var i = 0; i < TrophyIM.connection._requests.length; i++ ) |
---|
| 1339 | { |
---|
| 1340 | if( TrophyIM.connection._requests[i] ) |
---|
| 1341 | TrophyIM.connection._removeRequest(TrophyIM.connection._requests[i]); |
---|
| 1342 | } |
---|
| 1343 | |
---|
| 1344 | TrophyIM.logout(); |
---|
| 1345 | |
---|
[2670] | 1346 | loadscript.clrAllContacts(); |
---|
[2647] | 1347 | |
---|
| 1348 | delete TrophyIM.rosterObj.roster; |
---|
| 1349 | delete TrophyIM.rosterObj.groups; |
---|
| 1350 | |
---|
| 1351 | setTimeout(function() |
---|
| 1352 | { |
---|
| 1353 | if( loading_gif.style.display == "block" ) |
---|
| 1354 | loading_gif.style.display = "none"; |
---|
| 1355 | }, 1000); |
---|
[2641] | 1356 | } |
---|
| 1357 | else |
---|
| 1358 | { |
---|
| 1359 | if( !TrophyIM.autoConnection.connect ) |
---|
| 1360 | { |
---|
| 1361 | TrophyIM.autoConnection.connect = true; |
---|
| 1362 | TrophyIM.load(); |
---|
| 1363 | } |
---|
| 1364 | else |
---|
[2711] | 1365 | { |
---|
| 1366 | if( loadscript.getStatusMessage() != "" ) |
---|
| 1367 | { |
---|
| 1368 | var _presence = $pres( ); |
---|
| 1369 | _presence.node.appendChild( Strophe.xmlElement( 'show' ) ).appendChild( Strophe.xmlTextNode( _type ) ); |
---|
| 1370 | _presence.node.appendChild( Strophe.xmlElement( 'status' ) ).appendChild( Strophe.xmlTextNode( loadscript.getStatusMessage() )); |
---|
| 1371 | |
---|
| 1372 | TrophyIM.connection.send( _presence.tree() ); |
---|
| 1373 | } |
---|
| 1374 | else |
---|
| 1375 | { |
---|
| 1376 | TrophyIM.connection.send($pres( ).c('show').t(_type).tree()); |
---|
| 1377 | } |
---|
| 1378 | } |
---|
[2641] | 1379 | } |
---|
[2511] | 1380 | } |
---|
| 1381 | else |
---|
| 1382 | { |
---|
| 1383 | var _show = "available"; |
---|
| 1384 | var _status = ""; |
---|
| 1385 | |
---|
[2711] | 1386 | if( arguments.length < 2 ) |
---|
[2511] | 1387 | { |
---|
[2711] | 1388 | if( loadscript.getStatusMessage() != "" ) |
---|
| 1389 | _status = prompt("Digite sua mensagem !!!", loadscript.getStatusMessage()); |
---|
| 1390 | else |
---|
| 1391 | _status = prompt("Digite sua mensagem !!!"); |
---|
[2511] | 1392 | |
---|
[2711] | 1393 | var _divStatus = document.getElementById("JabberIMStatusMessage"); |
---|
| 1394 | |
---|
| 1395 | if( ( _status = _status.replace(/^\s+|\s+$|^\n|\n$/g,"") ) != "") |
---|
| 1396 | _divStatus.firstChild.innerHTML = "( " + _status + " )"; |
---|
| 1397 | } |
---|
| 1398 | else |
---|
| 1399 | { |
---|
| 1400 | _status = arguments[1]; |
---|
[2511] | 1401 | } |
---|
[2711] | 1402 | |
---|
| 1403 | for(var resource in TrophyIM.rosterObj.roster[Base64.decode(loadscript.getUserCurrent().jid)].presence ) |
---|
| 1404 | { |
---|
| 1405 | if ( TrophyIM.rosterObj.roster[Base64.decode(loadscript.getUserCurrent().jid)].presence[ resource ].constructor == Function ) |
---|
| 1406 | continue; |
---|
| 1407 | |
---|
| 1408 | if ( TROPHYIM_RESOURCE === ("/" + resource) ) |
---|
| 1409 | _show = TrophyIM.rosterObj.roster[Base64.decode(loadscript.getUserCurrent().jid)].presence[resource].show; |
---|
| 1410 | } |
---|
| 1411 | |
---|
| 1412 | var _presence = $pres( ); |
---|
| 1413 | _presence.node.appendChild( Strophe.xmlElement( 'show' ) ).appendChild( Strophe.xmlTextNode( _show ) ); |
---|
| 1414 | _presence.node.appendChild( Strophe.xmlElement( 'status' ) ).appendChild( Strophe.xmlTextNode( _status ) ); |
---|
| 1415 | |
---|
| 1416 | TrophyIM.connection.send( _presence.tree() ); |
---|
[2511] | 1417 | } |
---|
[2397] | 1418 | }, |
---|
| 1419 | |
---|
| 1420 | /** Function: sendMessage |
---|
| 1421 | * |
---|
| 1422 | * Send message from chat input to user |
---|
| 1423 | */ |
---|
| 1424 | |
---|
| 1425 | sendMessage : function() |
---|
| 1426 | { |
---|
| 1427 | |
---|
| 1428 | if( arguments.length > 0 ) |
---|
| 1429 | { |
---|
| 1430 | var jidTo = arguments[0]; |
---|
| 1431 | var message_input = document.getElementById(jidTo + "__sendBox").value; |
---|
| 1432 | |
---|
| 1433 | if( ( message_input = message_input.replace(/^\s+|\s+$|^\n|\n$/g,"") ) != "" ) |
---|
| 1434 | { |
---|
| 1435 | // Send Message |
---|
| 1436 | TrophyIM.connection.send($msg({to: jidTo, from: TrophyIM.connection.jid, type: 'chat'}).c('body').t(message_input).tree()); |
---|
| 1437 | |
---|
| 1438 | var message = |
---|
| 1439 | { |
---|
| 1440 | contact : "<font style='font-weight:bold; color:red;'>" + "Eu" + "</font>", |
---|
| 1441 | msg : message_input |
---|
| 1442 | } |
---|
| 1443 | |
---|
| 1444 | // Add Message in chatBox; |
---|
| 1445 | TrophyIM.addMessage( message, jidTo); |
---|
| 1446 | document.getElementById(jidTo + "__sendBox").value = ""; |
---|
| 1447 | document.getElementById(jidTo + "__sendBox").focus(); |
---|
| 1448 | } |
---|
| 1449 | } |
---|
| 1450 | } |
---|
| 1451 | }; |
---|
| 1452 | |
---|
| 1453 | /** Class: TrophyIMRoster |
---|
| 1454 | * |
---|
| 1455 | * |
---|
| 1456 | * This object stores the roster and presence info for the TrophyIMClient |
---|
| 1457 | * |
---|
| 1458 | * roster[jid_lower]['contact'] |
---|
| 1459 | * roster[jid_lower]['presence'][resource] |
---|
| 1460 | */ |
---|
| 1461 | function TrophyIMRoster() |
---|
| 1462 | { |
---|
| 1463 | /** Constants: internal arrays |
---|
| 1464 | * (Object) roster - the actual roster/presence information |
---|
| 1465 | * (Object) groups - list of current groups in the roster |
---|
| 1466 | * (Array) changes - array of jids with presence changes |
---|
| 1467 | */ |
---|
| 1468 | if (TrophyIM.JSONStore.store_working) |
---|
| 1469 | { |
---|
| 1470 | var data = TrophyIM.JSONStore.getData(['roster', 'groups']); |
---|
| 1471 | this.roster = (data['roster'] != null) ? data['roster'] : {}; |
---|
| 1472 | this.groups = (data['groups'] != null) ? data['groups'] : {}; |
---|
| 1473 | } |
---|
| 1474 | else |
---|
| 1475 | { |
---|
| 1476 | this.roster = {}; |
---|
| 1477 | this.groups = {}; |
---|
| 1478 | } |
---|
| 1479 | this.changes = new Array(); |
---|
| 1480 | |
---|
| 1481 | if (TrophyIM.constants.stale_roster) |
---|
| 1482 | { |
---|
| 1483 | for (var jid in this.roster) |
---|
| 1484 | { |
---|
| 1485 | this.changes[this.changes.length] = jid; |
---|
| 1486 | } |
---|
| 1487 | } |
---|
[2471] | 1488 | |
---|
| 1489 | /** Function: addChange |
---|
| 1490 | * |
---|
| 1491 | * Adds given jid to this.changes, keeping this.changes sorted and |
---|
| 1492 | * preventing duplicates. |
---|
| 1493 | * |
---|
| 1494 | * Parameters |
---|
| 1495 | * (String) jid : jid to add to this.changes |
---|
| 1496 | */ |
---|
| 1497 | |
---|
| 1498 | this.addChange = function(jid) |
---|
| 1499 | { |
---|
| 1500 | for (var c = 0; c < this.changes.length; c++) |
---|
| 1501 | { |
---|
| 1502 | if (this.changes[c] == jid) |
---|
| 1503 | { |
---|
| 1504 | return; |
---|
| 1505 | } |
---|
| 1506 | } |
---|
| 1507 | |
---|
| 1508 | this.changes[this.changes.length] = jid; |
---|
| 1509 | |
---|
| 1510 | this.changes.sort(); |
---|
| 1511 | } |
---|
[2397] | 1512 | |
---|
| 1513 | /** Function: addContact |
---|
| 1514 | * |
---|
| 1515 | * Adds given contact to roster |
---|
| 1516 | * |
---|
| 1517 | * Parameters: |
---|
| 1518 | * (String) jid - bare jid |
---|
| 1519 | * (String) subscription - subscription attribute for contact |
---|
| 1520 | * (String) name - name attribute for contact |
---|
[2471] | 1521 | * (Array) groups - array of groups contact is member of |
---|
[2397] | 1522 | */ |
---|
| 1523 | |
---|
[2471] | 1524 | this.addContact = function(jid, subscription, name, groups ) |
---|
[2397] | 1525 | { |
---|
[2584] | 1526 | if( subscription !== "remove" ) |
---|
[2511] | 1527 | { |
---|
[2584] | 1528 | var contact = { jid:jid, subscription:subscription, name:name, groups:groups } |
---|
[2511] | 1529 | var jid_lower = jid.toLowerCase(); |
---|
| 1530 | |
---|
| 1531 | if ( this.roster[jid_lower] ) |
---|
| 1532 | { |
---|
| 1533 | this.roster[jid_lower]['contact'] = contact; |
---|
| 1534 | } |
---|
| 1535 | else |
---|
| 1536 | { |
---|
| 1537 | this.roster[jid_lower] = {contact:contact}; |
---|
| 1538 | } |
---|
[2584] | 1539 | |
---|
[2511] | 1540 | groups = groups ? groups : ['']; |
---|
| 1541 | |
---|
| 1542 | for ( var g = 0; g < groups.length; g++ ) |
---|
| 1543 | { |
---|
| 1544 | if ( !this.groups[groups[g]] ) |
---|
[2471] | 1545 | { |
---|
[2511] | 1546 | this.groups[groups[g]] = {}; |
---|
| 1547 | } |
---|
| 1548 | |
---|
| 1549 | this.groups[groups[g]][jid_lower] = jid_lower; |
---|
[2471] | 1550 | } |
---|
[2511] | 1551 | } |
---|
[2584] | 1552 | else |
---|
[2511] | 1553 | { |
---|
| 1554 | this.removeContact(jid); |
---|
[2471] | 1555 | } |
---|
[2397] | 1556 | } |
---|
[2471] | 1557 | |
---|
[2397] | 1558 | /** Function: getContact |
---|
| 1559 | * |
---|
| 1560 | * Returns contact entry for given jid |
---|
| 1561 | * |
---|
| 1562 | * Parameter: (String) jid - jid to return |
---|
| 1563 | */ |
---|
[2471] | 1564 | |
---|
[2397] | 1565 | this.getContact = function(jid) |
---|
| 1566 | { |
---|
| 1567 | if (this.roster[jid.toLowerCase()]) |
---|
| 1568 | { |
---|
| 1569 | return this.roster[jid.toLowerCase()]['contact']; |
---|
| 1570 | } |
---|
| 1571 | } |
---|
[2471] | 1572 | |
---|
| 1573 | /** Function: getPresence |
---|
| 1574 | * |
---|
| 1575 | * Returns best presence for given jid as Array(resource, priority, show, |
---|
| 1576 | * status) |
---|
| 1577 | * |
---|
| 1578 | * Parameter: (String) fulljid - jid to return best presence for |
---|
| 1579 | */ |
---|
| 1580 | |
---|
| 1581 | this.getPresence = function(fulljid) |
---|
| 1582 | { |
---|
| 1583 | var jid = Strophe.getBareJidFromJid(fulljid); |
---|
| 1584 | var current = null; |
---|
| 1585 | |
---|
| 1586 | if (this.roster[jid.toLowerCase()] && this.roster[jid.toLowerCase()]['presence']) |
---|
| 1587 | { |
---|
| 1588 | for (var resource in this.roster[jid.toLowerCase()]['presence']) |
---|
| 1589 | { |
---|
[2670] | 1590 | if ( this.roster[jid.toLowerCase()]['presence'][ resource ].constructor == Function ) |
---|
| 1591 | continue; |
---|
| 1592 | |
---|
[2471] | 1593 | var presence = this.roster[jid.toLowerCase()]['presence'][resource]; |
---|
| 1594 | if (current == null) |
---|
| 1595 | { |
---|
| 1596 | current = presence |
---|
| 1597 | } |
---|
| 1598 | else |
---|
| 1599 | { |
---|
| 1600 | if(presence['priority'] > current['priority'] && ((presence['show'] == "chat" |
---|
| 1601 | || presence['show'] == "available") || (current['show'] != "chat" || |
---|
| 1602 | current['show'] != "available"))) |
---|
| 1603 | { |
---|
| 1604 | current = presence |
---|
| 1605 | } |
---|
| 1606 | } |
---|
| 1607 | } |
---|
| 1608 | } |
---|
| 1609 | return current; |
---|
| 1610 | } |
---|
| 1611 | |
---|
| 1612 | /** Function: groupHasChanges |
---|
| 1613 | * |
---|
| 1614 | * Returns true if current group has members in this.changes |
---|
| 1615 | * |
---|
| 1616 | * Parameters: |
---|
| 1617 | * (String) group - name of group to check |
---|
| 1618 | */ |
---|
| 1619 | |
---|
| 1620 | this.groupHasChanges = function(group) |
---|
| 1621 | { |
---|
| 1622 | for (var c = 0; c < this.changes.length; c++) |
---|
| 1623 | { |
---|
| 1624 | if (this.groups[group][this.changes[c]]) |
---|
| 1625 | { |
---|
| 1626 | return true; |
---|
| 1627 | } |
---|
| 1628 | } |
---|
| 1629 | return false; |
---|
| 1630 | } |
---|
| 1631 | |
---|
| 1632 | /** Function removeContact |
---|
| 1633 | * |
---|
| 1634 | * Parameters |
---|
| 1635 | * (String) jid |
---|
| 1636 | */ |
---|
| 1637 | |
---|
| 1638 | this.removeContact = function(jid) |
---|
| 1639 | { |
---|
[2577] | 1640 | if( this.roster[ jid ] ) |
---|
| 1641 | { |
---|
| 1642 | var groups = this.roster[ jid ].contact.groups; |
---|
[2491] | 1643 | |
---|
[2577] | 1644 | if( groups ) |
---|
[2491] | 1645 | { |
---|
[2577] | 1646 | for ( var i = 0; i < groups.length; i++ ) |
---|
| 1647 | { |
---|
| 1648 | delete this.groups[ groups[ i ] ][ jid ]; |
---|
| 1649 | } |
---|
| 1650 | |
---|
| 1651 | for ( var i = 0; i < groups.length; i++ ) |
---|
| 1652 | { |
---|
| 1653 | var contacts = 0; |
---|
| 1654 | for ( var contact in this.groups[ groups[ i ] ] ) |
---|
[2670] | 1655 | { |
---|
| 1656 | if ( this.groups[ groups[ i ] ][ contact ].constructor == Function ) |
---|
| 1657 | continue; |
---|
| 1658 | |
---|
[2577] | 1659 | contacts++; |
---|
[2670] | 1660 | } |
---|
[2577] | 1661 | |
---|
| 1662 | if ( ! contacts ) |
---|
| 1663 | delete this.groups[ groups[ i ] ]; |
---|
| 1664 | } |
---|
[2491] | 1665 | } |
---|
| 1666 | |
---|
[2577] | 1667 | // Delete Object roster |
---|
| 1668 | if( this.roster[jid] ) |
---|
| 1669 | delete this.roster[jid]; |
---|
[2471] | 1670 | } |
---|
| 1671 | } |
---|
| 1672 | |
---|
[2397] | 1673 | /** Function: setPresence |
---|
| 1674 | * |
---|
| 1675 | * Sets presence |
---|
| 1676 | * |
---|
| 1677 | * Parameters: |
---|
| 1678 | * (String) fulljid: full jid with presence |
---|
| 1679 | * (Integer) priority: priority attribute from presence |
---|
| 1680 | * (String) show: show attribute from presence |
---|
| 1681 | * (String) status: status attribute from presence |
---|
| 1682 | */ |
---|
| 1683 | |
---|
| 1684 | this.setPresence = function(fulljid, priority, show, status) |
---|
| 1685 | { |
---|
[2577] | 1686 | var barejid = Strophe.getBareJidFromJid(fulljid); |
---|
| 1687 | var resource = Strophe.getResourceFromJid(fulljid); |
---|
| 1688 | var jid_lower = barejid.toLowerCase(); |
---|
[2397] | 1689 | |
---|
[2511] | 1690 | if( show != 'unavailable') |
---|
| 1691 | { |
---|
| 1692 | if (!this.roster[jid_lower]) |
---|
[2397] | 1693 | { |
---|
[2511] | 1694 | this.addContact(barejid, 'not-in-roster'); |
---|
| 1695 | } |
---|
| 1696 | var presence = |
---|
[2397] | 1697 | { |
---|
[2511] | 1698 | resource:resource, priority:priority, show:show, status:status |
---|
| 1699 | } |
---|
| 1700 | |
---|
| 1701 | if (!this.roster[jid_lower]['presence']) |
---|
[2397] | 1702 | { |
---|
[2584] | 1703 | this.roster[jid_lower]['presence'] = {}; |
---|
[2511] | 1704 | } |
---|
[2584] | 1705 | this.roster[jid_lower]['presence'][resource] = presence; |
---|
[2397] | 1706 | } |
---|
[2511] | 1707 | else if (this.roster[jid_lower] && this.roster[jid_lower]['presence'] && this.roster[jid_lower]['presence'][resource]) |
---|
| 1708 | { |
---|
| 1709 | delete this.roster[jid_lower]['presence'][resource]; |
---|
| 1710 | } |
---|
| 1711 | |
---|
| 1712 | this.addChange(jid_lower); |
---|
[2471] | 1713 | } |
---|
| 1714 | |
---|
| 1715 | /** Fuction: save |
---|
| 1716 | * |
---|
| 1717 | * Saves roster data to JSON store |
---|
| 1718 | */ |
---|
| 1719 | |
---|
| 1720 | this.save = function() |
---|
| 1721 | { |
---|
| 1722 | if (TrophyIM.JSONStore.store_working) |
---|
[2397] | 1723 | { |
---|
[2471] | 1724 | TrophyIM.JSONStore.setData({roster:this.roster, |
---|
| 1725 | groups:this.groups, active_chat:TrophyIM.activeChats['current'], |
---|
| 1726 | chat_history:TrophyIM.chatHistory}); |
---|
| 1727 | } |
---|
| 1728 | } |
---|
| 1729 | |
---|
[2397] | 1730 | } |
---|
| 1731 | /** Class: TrophyIMJSONStore |
---|
| 1732 | * |
---|
| 1733 | * |
---|
| 1734 | * This object is the mechanism by which TrophyIM stores and retrieves its |
---|
| 1735 | * variables from the url provided by TROPHYIM_JSON_STORE |
---|
| 1736 | * |
---|
| 1737 | */ |
---|
| 1738 | function TrophyIMJSONStore() { |
---|
| 1739 | this.store_working = false; |
---|
| 1740 | /** Function _newXHR |
---|
| 1741 | * |
---|
| 1742 | * Set up new cross-browser xmlhttprequest object |
---|
| 1743 | * |
---|
| 1744 | * Parameters: |
---|
| 1745 | * (function) handler = what to set onreadystatechange to |
---|
| 1746 | */ |
---|
| 1747 | this._newXHR = function (handler) { |
---|
| 1748 | var xhr = null; |
---|
| 1749 | if (window.XMLHttpRequest) { |
---|
| 1750 | xhr = new XMLHttpRequest(); |
---|
| 1751 | if (xhr.overrideMimeType) { |
---|
| 1752 | xhr.overrideMimeType("text/xml"); |
---|
| 1753 | } |
---|
| 1754 | } else if (window.ActiveXObject) { |
---|
| 1755 | xhr = new ActiveXObject("Microsoft.XMLHTTP"); |
---|
| 1756 | } |
---|
| 1757 | return xhr; |
---|
| 1758 | } |
---|
| 1759 | /** Function getData |
---|
| 1760 | * Gets data from JSONStore |
---|
| 1761 | * |
---|
| 1762 | * Parameters: |
---|
| 1763 | * (Array) vars = Variables to get from JSON store |
---|
| 1764 | * |
---|
| 1765 | * Returns: |
---|
| 1766 | * Object with variables indexed by names given in parameter 'vars' |
---|
| 1767 | */ |
---|
| 1768 | this.getData = function(vars) { |
---|
| 1769 | if (typeof(TROPHYIM_JSON_STORE) != undefined) { |
---|
| 1770 | Strophe.debug("Retrieving JSONStore data"); |
---|
| 1771 | var xhr = this._newXHR(); |
---|
| 1772 | var getdata = "get=" + vars.join(","); |
---|
| 1773 | try { |
---|
| 1774 | xhr.open("POST", TROPHYIM_JSON_STORE, false); |
---|
| 1775 | } catch (e) { |
---|
| 1776 | Strophe.error("JSONStore open failed."); |
---|
| 1777 | return false; |
---|
| 1778 | } |
---|
| 1779 | xhr.setRequestHeader('Content-type', |
---|
| 1780 | 'application/x-www-form-urlencoded'); |
---|
| 1781 | xhr.setRequestHeader('Content-length', getdata.length); |
---|
| 1782 | xhr.send(getdata); |
---|
| 1783 | if (xhr.readyState == 4 && xhr.status == 200) { |
---|
| 1784 | try { |
---|
| 1785 | var dataObj = JSON.parse(xhr.responseText); |
---|
| 1786 | return this.emptyFix(dataObj); |
---|
| 1787 | } catch(e) { |
---|
| 1788 | Strophe.error("Could not parse JSONStore response" + |
---|
| 1789 | xhr.responseText); |
---|
| 1790 | return false; |
---|
| 1791 | } |
---|
| 1792 | } else { |
---|
| 1793 | Strophe.error("JSONStore open failed. Status: " + xhr.status); |
---|
| 1794 | return false; |
---|
| 1795 | } |
---|
| 1796 | } |
---|
| 1797 | } |
---|
| 1798 | /** Function emptyFix |
---|
| 1799 | * Fix for bugs in external JSON implementations such as |
---|
| 1800 | * http://bugs.php.net/bug.php?id=41504. |
---|
| 1801 | * A.K.A. Don't use PHP, people. |
---|
| 1802 | */ |
---|
| 1803 | this.emptyFix = function(obj) { |
---|
| 1804 | if (typeof(obj) == "object") { |
---|
| 1805 | for (var i in obj) { |
---|
[2670] | 1806 | if ( obj[i].constructor == Function ) |
---|
| 1807 | continue; |
---|
| 1808 | |
---|
[2397] | 1809 | if (i == '_empty_') { |
---|
| 1810 | obj[""] = this.emptyFix(obj['_empty_']); |
---|
| 1811 | delete obj['_empty_']; |
---|
| 1812 | } else { |
---|
| 1813 | obj[i] = this.emptyFix(obj[i]); |
---|
| 1814 | } |
---|
| 1815 | } |
---|
| 1816 | } |
---|
| 1817 | return obj |
---|
| 1818 | } |
---|
| 1819 | /** Function delData |
---|
| 1820 | * Deletes data from JSONStore |
---|
| 1821 | * |
---|
| 1822 | * Parameters: |
---|
| 1823 | * (Array) vars = Variables to delete from JSON store |
---|
| 1824 | * |
---|
| 1825 | * Returns: |
---|
| 1826 | * Status of delete attempt. |
---|
| 1827 | */ |
---|
| 1828 | this.delData = function(vars) { |
---|
| 1829 | if (typeof(TROPHYIM_JSON_STORE) != undefined) { |
---|
| 1830 | Strophe.debug("Retrieving JSONStore data"); |
---|
| 1831 | var xhr = this._newXHR(); |
---|
| 1832 | var deldata = "del=" + vars.join(","); |
---|
| 1833 | try { |
---|
| 1834 | xhr.open("POST", TROPHYIM_JSON_STORE, false); |
---|
| 1835 | } catch (e) { |
---|
| 1836 | Strophe.error("JSONStore open failed."); |
---|
| 1837 | return false; |
---|
| 1838 | } |
---|
| 1839 | xhr.setRequestHeader('Content-type', |
---|
| 1840 | 'application/x-www-form-urlencoded'); |
---|
| 1841 | xhr.setRequestHeader('Content-length', deldata.length); |
---|
| 1842 | xhr.send(deldata); |
---|
| 1843 | if (xhr.readyState == 4 && xhr.status == 200) { |
---|
| 1844 | try { |
---|
| 1845 | var dataObj = JSON.parse(xhr.responseText); |
---|
| 1846 | return dataObj; |
---|
| 1847 | } catch(e) { |
---|
| 1848 | Strophe.error("Could not parse JSONStore response"); |
---|
| 1849 | return false; |
---|
| 1850 | } |
---|
| 1851 | } else { |
---|
| 1852 | Strophe.error("JSONStore open failed. Status: " + xhr.status); |
---|
| 1853 | return false; |
---|
| 1854 | } |
---|
| 1855 | } |
---|
| 1856 | } |
---|
| 1857 | /** Function setData |
---|
| 1858 | * Stores data in JSONStore, overwriting values if they exist |
---|
| 1859 | * |
---|
| 1860 | * Parameters: |
---|
| 1861 | * (Object) vars : Object containing named vars to store ({name: value, |
---|
| 1862 | * othername: othervalue}) |
---|
| 1863 | * |
---|
| 1864 | * Returns: |
---|
| 1865 | * Status of storage attempt |
---|
| 1866 | */ |
---|
| 1867 | this.setData = function(vars) { |
---|
| 1868 | if (typeof(TROPHYIM_JSON_STORE) != undefined) { |
---|
| 1869 | Strophe.debug("Storing JSONStore data"); |
---|
| 1870 | var senddata = "set=" + JSON.stringify(vars); |
---|
| 1871 | var xhr = this._newXHR(); |
---|
| 1872 | try { |
---|
| 1873 | xhr.open("POST", TROPHYIM_JSON_STORE, false); |
---|
| 1874 | } catch (e) { |
---|
| 1875 | Strophe.error("JSONStore open failed."); |
---|
| 1876 | return false; |
---|
| 1877 | } |
---|
| 1878 | xhr.setRequestHeader('Content-type', |
---|
| 1879 | 'application/x-www-form-urlencoded'); |
---|
| 1880 | xhr.setRequestHeader('Content-length', senddata.length); |
---|
| 1881 | xhr.send(senddata); |
---|
| 1882 | if (xhr.readyState == 4 && xhr.status == 200 && xhr.responseText == |
---|
| 1883 | "OK") { |
---|
| 1884 | return true; |
---|
| 1885 | } else { |
---|
| 1886 | Strophe.error("JSONStore open failed. Status: " + xhr.status); |
---|
| 1887 | return false; |
---|
| 1888 | } |
---|
| 1889 | } |
---|
| 1890 | } |
---|
| 1891 | var testData = true; |
---|
| 1892 | if (this.setData({testData:testData})) { |
---|
| 1893 | var testResult = this.getData(['testData']); |
---|
| 1894 | if (testResult && testResult['testData'] == true) { |
---|
| 1895 | this.store_working = true; |
---|
| 1896 | } |
---|
| 1897 | } |
---|
| 1898 | } |
---|
| 1899 | /** Constants: Node types |
---|
| 1900 | * |
---|
| 1901 | * Implementations of constants that IE doesn't have, but we need. |
---|
| 1902 | */ |
---|
| 1903 | if (document.ELEMENT_NODE == null) { |
---|
| 1904 | document.ELEMENT_NODE = 1; |
---|
| 1905 | document.ATTRIBUTE_NODE = 2; |
---|
| 1906 | document.TEXT_NODE = 3; |
---|
| 1907 | document.CDATA_SECTION_NODE = 4; |
---|
| 1908 | document.ENTITY_REFERENCE_NODE = 5; |
---|
| 1909 | document.ENTITY_NODE = 6; |
---|
| 1910 | document.PROCESSING_INSTRUCTION_NODE = 7; |
---|
| 1911 | document.COMMENT_NODE = 8; |
---|
| 1912 | document.DOCUMENT_NODE = 9; |
---|
| 1913 | document.DOCUMENT_TYPE_NODE = 10; |
---|
| 1914 | document.DOCUMENT_FRAGMENT_NODE = 11; |
---|
| 1915 | document.NOTATION_NODE = 12; |
---|
| 1916 | } |
---|
| 1917 | |
---|
| 1918 | /** Function: importNode |
---|
| 1919 | * |
---|
| 1920 | * document.importNode implementation for IE, which doesn't have importNode |
---|
| 1921 | * |
---|
| 1922 | * Parameters: |
---|
| 1923 | * (Object) node - dom object |
---|
| 1924 | * (Boolean) allChildren - import node's children too |
---|
| 1925 | */ |
---|
| 1926 | if (!document.importNode) { |
---|
| 1927 | document.importNode = function(node, allChildren) { |
---|
| 1928 | switch (node.nodeType) { |
---|
| 1929 | case document.ELEMENT_NODE: |
---|
| 1930 | var newNode = document.createElement(node.nodeName); |
---|
| 1931 | if (node.attributes && node.attributes.length > 0) { |
---|
| 1932 | for(var i = 0; i < node.attributes.length; i++) { |
---|
| 1933 | newNode.setAttribute(node.attributes[i].nodeName, |
---|
| 1934 | node.getAttribute(node.attributes[i].nodeName)); |
---|
| 1935 | } |
---|
| 1936 | } |
---|
| 1937 | if (allChildren && node.childNodes && |
---|
| 1938 | node.childNodes.length > 0) { |
---|
| 1939 | for (var i = 0; i < node.childNodes.length; i++) { |
---|
| 1940 | newNode.appendChild(document.importNode( |
---|
| 1941 | node.childNodes[i], allChildren)); |
---|
| 1942 | } |
---|
| 1943 | } |
---|
| 1944 | return newNode; |
---|
| 1945 | break; |
---|
| 1946 | case document.TEXT_NODE: |
---|
| 1947 | case document.CDATA_SECTION_NODE: |
---|
| 1948 | case document.COMMENT_NODE: |
---|
| 1949 | return document.createTextNode(node.nodeValue); |
---|
| 1950 | break; |
---|
| 1951 | } |
---|
| 1952 | }; |
---|
| 1953 | } |
---|
| 1954 | |
---|
| 1955 | /** |
---|
| 1956 | * |
---|
| 1957 | * Bootstrap self into window.onload and window.onunload |
---|
| 1958 | */ |
---|
| 1959 | |
---|
[2584] | 1960 | var oldonunload = window.onunload; |
---|
[2397] | 1961 | |
---|
| 1962 | window.onunload = function() |
---|
| 1963 | { |
---|
[2584] | 1964 | if( oldonunload ) |
---|
[2397] | 1965 | { |
---|
| 1966 | oldonunload(); |
---|
| 1967 | } |
---|
[2584] | 1968 | |
---|
[2672] | 1969 | TrophyIM.setPresence('unavailable'); |
---|
[2397] | 1970 | } |
---|