| | 1 | |
|---|
| | 2 | if (!window.console || !console.firebug) { |
|---|
| | 3 | (function() |
|---|
| | 4 | { |
|---|
| | 5 | window.console = |
|---|
| | 6 | { |
|---|
| | 7 | log: function() |
|---|
| | 8 | { |
|---|
| | 9 | logFormatted(arguments, ""); |
|---|
| | 10 | }, |
|---|
| | 11 | |
|---|
| | 12 | debug: function() |
|---|
| | 13 | { |
|---|
| | 14 | logFormatted(arguments, "debug"); |
|---|
| | 15 | }, |
|---|
| | 16 | |
|---|
| | 17 | info: function() |
|---|
| | 18 | { |
|---|
| | 19 | logFormatted(arguments, "info"); |
|---|
| | 20 | }, |
|---|
| | 21 | |
|---|
| | 22 | warn: function() |
|---|
| | 23 | { |
|---|
| | 24 | logFormatted(arguments, "warning"); |
|---|
| | 25 | }, |
|---|
| | 26 | |
|---|
| | 27 | error: function() |
|---|
| | 28 | { |
|---|
| | 29 | logFormatted(arguments, "error"); |
|---|
| | 30 | }, |
|---|
| | 31 | |
|---|
| | 32 | assert: function(truth, message) |
|---|
| | 33 | { |
|---|
| | 34 | if (!truth) |
|---|
| | 35 | { |
|---|
| | 36 | var args = []; |
|---|
| | 37 | for (var i = 1; i < arguments.length; ++i) |
|---|
| | 38 | args.push(arguments[i]); |
|---|
| | 39 | |
|---|
| | 40 | logFormatted(args.length ? args : ["Assertion Failure"], "error"); |
|---|
| | 41 | throw message ? message : "Assertion Failure"; |
|---|
| | 42 | } |
|---|
| | 43 | }, |
|---|
| | 44 | |
|---|
| | 45 | dir: function(object) |
|---|
| | 46 | { |
|---|
| | 47 | var html = []; |
|---|
| | 48 | |
|---|
| | 49 | var pairs = []; |
|---|
| | 50 | for (var name in object) |
|---|
| | 51 | { |
|---|
| | 52 | try |
|---|
| | 53 | { |
|---|
| | 54 | pairs.push([name, object[name]]); |
|---|
| | 55 | } |
|---|
| | 56 | catch (exc) |
|---|
| | 57 | { |
|---|
| | 58 | } |
|---|
| | 59 | } |
|---|
| | 60 | |
|---|
| | 61 | pairs.sort(function(a, b) { return a[0] < b[0] ? -1 : 1; }); |
|---|
| | 62 | |
|---|
| | 63 | html.push('<table>'); |
|---|
| | 64 | for (var i = 0; i < pairs.length; ++i) |
|---|
| | 65 | { |
|---|
| | 66 | var name = pairs[i][0], value = pairs[i][1]; |
|---|
| | 67 | |
|---|
| | 68 | html.push('<tr>', |
|---|
| | 69 | '<td class="propertyNameCell"><span class="propertyName">', |
|---|
| | 70 | escapeHTML(name), '</span></td>', '<td><span class="propertyValue">'); |
|---|
| | 71 | appendObject(value, html); |
|---|
| | 72 | html.push('</span></td></tr>'); |
|---|
| | 73 | } |
|---|
| | 74 | html.push('</table>'); |
|---|
| | 75 | |
|---|
| | 76 | logRow(html, "dir"); |
|---|
| | 77 | }, |
|---|
| | 78 | |
|---|
| | 79 | dirxml: function(node) |
|---|
| | 80 | { |
|---|
| | 81 | var html = []; |
|---|
| | 82 | |
|---|
| | 83 | appendNode(node, html); |
|---|
| | 84 | logRow(html, "dirxml"); |
|---|
| | 85 | }, |
|---|
| | 86 | |
|---|
| | 87 | group: function() |
|---|
| | 88 | { |
|---|
| | 89 | logRow(arguments, "group", pushGroup); |
|---|
| | 90 | }, |
|---|
| | 91 | |
|---|
| | 92 | groupEnd: function() |
|---|
| | 93 | { |
|---|
| | 94 | logRow(arguments, "", popGroup); |
|---|
| | 95 | }, |
|---|
| | 96 | |
|---|
| | 97 | time: function(name) |
|---|
| | 98 | { |
|---|
| | 99 | timeMap[name] = (new Date()).getTime(); |
|---|
| | 100 | }, |
|---|
| | 101 | |
|---|
| | 102 | timeEnd: function(name) |
|---|
| | 103 | { |
|---|
| | 104 | if (name in timeMap) |
|---|
| | 105 | { |
|---|
| | 106 | var delta = (new Date()).getTime() - timeMap[name]; |
|---|
| | 107 | logFormatted([name+ ":", delta+"ms"]); |
|---|
| | 108 | delete timeMap[name]; |
|---|
| | 109 | } |
|---|
| | 110 | }, |
|---|
| | 111 | |
|---|
| | 112 | count: function() |
|---|
| | 113 | { |
|---|
| | 114 | this.warn(["count() not supported."]); |
|---|
| | 115 | }, |
|---|
| | 116 | |
|---|
| | 117 | trace: function() |
|---|
| | 118 | { |
|---|
| | 119 | this.warn(["trace() not supported."]); |
|---|
| | 120 | }, |
|---|
| | 121 | |
|---|
| | 122 | profile: function() |
|---|
| | 123 | { |
|---|
| | 124 | this.warn(["profile() not supported."]); |
|---|
| | 125 | }, |
|---|
| | 126 | |
|---|
| | 127 | profileEnd: function() |
|---|
| | 128 | { |
|---|
| | 129 | }, |
|---|
| | 130 | |
|---|
| | 131 | clear: function() |
|---|
| | 132 | { |
|---|
| | 133 | consoleBody.innerHTML = ""; |
|---|
| | 134 | }, |
|---|
| | 135 | |
|---|
| | 136 | open: function() |
|---|
| | 137 | { |
|---|
| | 138 | toggleConsole(true); |
|---|
| | 139 | }, |
|---|
| | 140 | |
|---|
| | 141 | close: function() |
|---|
| | 142 | { |
|---|
| | 143 | if (frameVisible) |
|---|
| | 144 | toggleConsole(); |
|---|
| | 145 | } |
|---|
| | 146 | }; |
|---|
| | 147 | |
|---|
| | 148 | // ******************************************************************************************** |
|---|
| | 149 | |
|---|
| | 150 | var consoleFrame = null; |
|---|
| | 151 | var consoleBody = null; |
|---|
| | 152 | var commandLine = null; |
|---|
| | 153 | |
|---|
| | 154 | var frameVisible = false; |
|---|
| | 155 | var messageQueue = []; |
|---|
| | 156 | var groupStack = []; |
|---|
| | 157 | var timeMap = {}; |
|---|
| | 158 | |
|---|
| | 159 | var clPrefix = ">>> "; |
|---|
| | 160 | |
|---|
| | 161 | var isFirefox = navigator.userAgent.indexOf("Firefox") != -1; |
|---|
| | 162 | var isIE = navigator.userAgent.indexOf("MSIE") != -1; |
|---|
| | 163 | var isOpera = navigator.userAgent.indexOf("Opera") != -1; |
|---|
| | 164 | var isSafari = navigator.userAgent.indexOf("AppleWebKit") != -1; |
|---|
| | 165 | |
|---|
| | 166 | // ******************************************************************************************** |
|---|
| | 167 | |
|---|
| | 168 | function toggleConsole(forceOpen) |
|---|
| | 169 | { |
|---|
| | 170 | frameVisible = forceOpen || !frameVisible; |
|---|
| | 171 | if (consoleFrame) |
|---|
| | 172 | consoleFrame.style.visibility = frameVisible ? "visible" : "hidden"; |
|---|
| | 173 | else |
|---|
| | 174 | waitForBody(); |
|---|
| | 175 | } |
|---|
| | 176 | |
|---|
| | 177 | function focusCommandLine() |
|---|
| | 178 | { |
|---|
| | 179 | toggleConsole(true); |
|---|
| | 180 | if (commandLine) |
|---|
| | 181 | commandLine.focus(); |
|---|
| | 182 | } |
|---|
| | 183 | |
|---|
| | 184 | function waitForBody() |
|---|
| | 185 | { |
|---|
| | 186 | if (document.body) |
|---|
| | 187 | createFrame(); |
|---|
| | 188 | else |
|---|
| | 189 | setTimeout(waitForBody, 200); |
|---|
| | 190 | } |
|---|
| | 191 | |
|---|
| | 192 | function createFrame() |
|---|
| | 193 | { |
|---|
| | 194 | if (consoleFrame) |
|---|
| | 195 | return; |
|---|
| | 196 | |
|---|
| | 197 | window.onFirebugReady = function(doc) |
|---|
| | 198 | { |
|---|
| | 199 | window.onFirebugReady = null; |
|---|
| | 200 | |
|---|
| | 201 | var toolbar = doc.getElementById("toolbar"); |
|---|
| | 202 | toolbar.onmousedown = onSplitterMouseDown; |
|---|
| | 203 | |
|---|
| | 204 | commandLine = doc.getElementById("commandLine"); |
|---|
| | 205 | addEvent(commandLine, "keydown", onCommandLineKeyDown); |
|---|
| | 206 | |
|---|
| | 207 | addEvent(doc, isIE || isSafari ? "keydown" : "keypress", onKeyDown); |
|---|
| | 208 | |
|---|
| | 209 | consoleBody = doc.getElementById("log"); |
|---|
| | 210 | layout(); |
|---|
| | 211 | flush(); |
|---|
| | 212 | } |
|---|
| | 213 | |
|---|
| | 214 | var baseURL = getFirebugURL(); |
|---|
| | 215 | |
|---|
| | 216 | consoleFrame = document.createElement("iframe"); |
|---|
| | 217 | consoleFrame.setAttribute("src", baseURL+"/firebug.html"); |
|---|
| | 218 | consoleFrame.setAttribute("frameBorder", "0"); |
|---|
| | 219 | consoleFrame.style.visibility = (frameVisible ? "visible" : "hidden"); |
|---|
| | 220 | consoleFrame.style.zIndex = "2147483583"; |
|---|
| | 221 | consoleFrame.style.position = document.all ? "absolute" : "fixed"; |
|---|
| | 222 | consoleFrame.style.width = "100%"; |
|---|
| | 223 | consoleFrame.style.left = "0"; |
|---|
| | 224 | consoleFrame.style.bottom = "0"; |
|---|
| | 225 | consoleFrame.style.height = "200px"; |
|---|
| | 226 | document.body.appendChild(consoleFrame); |
|---|
| | 227 | } |
|---|
| | 228 | |
|---|
| | 229 | function getFirebugURL() |
|---|
| | 230 | { |
|---|
| | 231 | var scripts = document.getElementsByTagName("script"); |
|---|
| | 232 | for (var i = 0; i < scripts.length; ++i) |
|---|
| | 233 | { |
|---|
| | 234 | if (scripts[i].src.indexOf("firebug.js") != -1) |
|---|
| | 235 | { |
|---|
| | 236 | var lastSlash = scripts[i].src.lastIndexOf("/"); |
|---|
| | 237 | return scripts[i].src.substr(0, lastSlash); |
|---|
| | 238 | } |
|---|
| | 239 | } |
|---|
| | 240 | } |
|---|
| | 241 | |
|---|
| | 242 | function evalCommandLine() |
|---|
| | 243 | { |
|---|
| | 244 | var text = commandLine.value; |
|---|
| | 245 | commandLine.value = ""; |
|---|
| | 246 | |
|---|
| | 247 | logRow([clPrefix, text], "command"); |
|---|
| | 248 | |
|---|
| | 249 | var value; |
|---|
| | 250 | try |
|---|
| | 251 | { |
|---|
| | 252 | value = eval(text); |
|---|
| | 253 | } |
|---|
| | 254 | catch (exc) |
|---|
| | 255 | { |
|---|
| | 256 | } |
|---|
| | 257 | |
|---|
| | 258 | console.log(value); |
|---|
| | 259 | } |
|---|
| | 260 | |
|---|
| | 261 | function layout() |
|---|
| | 262 | { |
|---|
| | 263 | var toolbar = consoleBody.ownerDocument.getElementById("toolbar"); |
|---|
| | 264 | var height = consoleFrame.offsetHeight - (toolbar.offsetHeight + commandLine.offsetHeight); |
|---|
| | 265 | height = Math.max(height, 0); |
|---|
| | 266 | consoleBody.style.top = toolbar.offsetHeight + "px"; |
|---|
| | 267 | consoleBody.style.height = height + "px"; |
|---|
| | 268 | |
|---|
| | 269 | commandLine.style.top = (consoleFrame.offsetHeight - commandLine.offsetHeight) + "px"; |
|---|
| | 270 | } |
|---|
| | 271 | |
|---|
| | 272 | function logRow(message, className, handler) |
|---|
| | 273 | { |
|---|
| | 274 | if (consoleBody) |
|---|
| | 275 | writeMessage(message, className, handler); |
|---|
| | 276 | else |
|---|
| | 277 | { |
|---|
| | 278 | messageQueue.push([message, className, handler]); |
|---|
| | 279 | waitForBody(); |
|---|
| | 280 | } |
|---|
| | 281 | } |
|---|
| | 282 | |
|---|
| | 283 | function flush() |
|---|
| | 284 | { |
|---|
| | 285 | var queue = messageQueue; |
|---|
| | 286 | messageQueue = []; |
|---|
| | 287 | |
|---|
| | 288 | for (var i = 0; i < queue.length; ++i) |
|---|
| | 289 | writeMessage(queue[i][0], queue[i][1], queue[i][2]); |
|---|
| | 290 | } |
|---|
| | 291 | |
|---|
| | 292 | function writeMessage(message, className, handler) |
|---|
| | 293 | { |
|---|
| | 294 | var isScrolledToBottom = |
|---|
| | 295 | consoleBody.scrollTop + consoleBody.offsetHeight >= consoleBody.scrollHeight; |
|---|
| | 296 | |
|---|
| | 297 | if (!handler) |
|---|
| | 298 | handler = writeRow; |
|---|
| | 299 | |
|---|
| | 300 | handler(message, className); |
|---|
| | 301 | |
|---|
| | 302 | if (isScrolledToBottom) |
|---|
| | 303 | consoleBody.scrollTop = consoleBody.scrollHeight - consoleBody.offsetHeight; |
|---|
| | 304 | } |
|---|
| | 305 | |
|---|
| | 306 | function appendRow(row) |
|---|
| | 307 | { |
|---|
| | 308 | var container = groupStack.length ? groupStack[groupStack.length-1] : consoleBody; |
|---|
| | 309 | container.appendChild(row); |
|---|
| | 310 | } |
|---|
| | 311 | |
|---|
| | 312 | function writeRow(message, className) |
|---|
| | 313 | { |
|---|
| | 314 | var row = consoleBody.ownerDocument.createElement("div"); |
|---|
| | 315 | row.className = "logRow" + (className ? " logRow-"+className : ""); |
|---|
| | 316 | row.innerHTML = message.join(""); |
|---|
| | 317 | appendRow(row); |
|---|
| | 318 | } |
|---|
| | 319 | |
|---|
| | 320 | function pushGroup(message, className) |
|---|
| | 321 | { |
|---|
| | 322 | logFormatted(message, className); |
|---|
| | 323 | |
|---|
| | 324 | var groupRow = consoleBody.ownerDocument.createElement("div"); |
|---|
| | 325 | groupRow.className = "logGroup"; |
|---|
| | 326 | var groupRowBox = consoleBody.ownerDocument.createElement("div"); |
|---|
| | 327 | groupRowBox.className = "logGroupBox"; |
|---|
| | 328 | groupRow.appendChild(groupRowBox); |
|---|
| | 329 | appendRow(groupRowBox); |
|---|
| | 330 | groupStack.push(groupRowBox); |
|---|
| | 331 | } |
|---|
| | 332 | |
|---|
| | 333 | function popGroup() |
|---|
| | 334 | { |
|---|
| | 335 | groupStack.pop(); |
|---|
| | 336 | } |
|---|
| | 337 | |
|---|
| | 338 | // ******************************************************************************************** |
|---|
| | 339 | |
|---|
| | 340 | function logFormatted(objects, className) |
|---|
| | 341 | { |
|---|
| | 342 | var html = []; |
|---|
| | 343 | |
|---|
| | 344 | var format = objects[0]; |
|---|
| | 345 | var objIndex = 0; |
|---|
| | 346 | |
|---|
| | 347 | if (typeof(format) != "string") |
|---|
| | 348 | { |
|---|
| | 349 | format = ""; |
|---|
| | 350 | objIndex = -1; |
|---|
| | 351 | } |
|---|
| | 352 | |
|---|
| | 353 | var parts = parseFormat(format); |
|---|
| | 354 | for (var i = 0; i < parts.length; ++i) |
|---|
| | 355 | { |
|---|
| | 356 | var part = parts[i]; |
|---|
| | 357 | if (part && typeof(part) == "object") |
|---|
| | 358 | { |
|---|
| | 359 | var object = objects[++objIndex]; |
|---|
| | 360 | part.appender(object, html); |
|---|
| | 361 | } |
|---|
| | 362 | else |
|---|
| | 363 | appendText(part, html); |
|---|
| | 364 | } |
|---|
| | 365 | |
|---|
| | 366 | for (var i = objIndex+1; i < objects.length; ++i) |
|---|
| | 367 | { |
|---|
| | 368 | appendText(" ", html); |
|---|
| | 369 | |
|---|
| | 370 | var object = objects[i]; |
|---|
| | 371 | if (typeof(object) == "string") |
|---|
| | 372 | appendText(object, html); |
|---|
| | 373 | else |
|---|
| | 374 | appendObject(object, html); |
|---|
| | 375 | } |
|---|
| | 376 | |
|---|
| | 377 | logRow(html, className); |
|---|
| | 378 | } |
|---|
| | 379 | |
|---|
| | 380 | function parseFormat(format) |
|---|
| | 381 | { |
|---|
| | 382 | var parts = []; |
|---|
| | 383 | |
|---|
| | 384 | var reg = /((^%|[^\\]%)(\d+)?(\.)([a-zA-Z]))|((^%|[^\\]%)([a-zA-Z]))/; |
|---|
| | 385 | var appenderMap = {s: appendText, d: appendInteger, i: appendInteger, f: appendFloat}; |
|---|
| | 386 | |
|---|
| | 387 | for (var m = reg.exec(format); m; m = reg.exec(format)) |
|---|
| | 388 | { |
|---|
| | 389 | var type = m[8] ? m[8] : m[5]; |
|---|
| | 390 | var appender = type in appenderMap ? appenderMap[type] : appendObject; |
|---|
| | 391 | var precision = m[3] ? parseInt(m[3]) : (m[4] == "." ? -1 : 0); |
|---|
| | 392 | |
|---|
| | 393 | parts.push(format.substr(0, m[0][0] == "%" ? m.index : m.index+1)); |
|---|
| | 394 | parts.push({appender: appender, precision: precision}); |
|---|
| | 395 | |
|---|
| | 396 | format = format.substr(m.index+m[0].length); |
|---|
| | 397 | } |
|---|
| | 398 | |
|---|
| | 399 | parts.push(format); |
|---|
| | 400 | |
|---|
| | 401 | return parts; |
|---|
| | 402 | } |
|---|
| | 403 | |
|---|
| | 404 | function escapeHTML(value) |
|---|
| | 405 | { |
|---|
| | 406 | function replaceChars(ch) |
|---|
| | 407 | { |
|---|
| | 408 | switch (ch) |
|---|
| | 409 | { |
|---|
| | 410 | case "<": |
|---|
| | 411 | return "<"; |
|---|
| | 412 | case ">": |
|---|
| | 413 | return ">"; |
|---|
| | 414 | case "&": |
|---|
| | 415 | return "&"; |
|---|
| | 416 | case "'": |
|---|
| | 417 | return "'"; |
|---|
| | 418 | case '"': |
|---|
| | 419 | return """; |
|---|
| | 420 | } |
|---|
| | 421 | return "?"; |
|---|
| | 422 | }; |
|---|
| | 423 | return String(value).replace(/[<>&"']/g, replaceChars); |
|---|
| | 424 | } |
|---|
| | 425 | |
|---|
| | 426 | function objectToString(object) |
|---|
| | 427 | { |
|---|
| | 428 | try |
|---|
| | 429 | { |
|---|
| | 430 | return object+""; |
|---|
| | 431 | } |
|---|
| | 432 | catch (exc) |
|---|
| | 433 | { |
|---|
| | 434 | return null; |
|---|
| | 435 | } |
|---|
| | 436 | } |
|---|
| | 437 | |
|---|
| | 438 | // ******************************************************************************************** |
|---|
| | 439 | |
|---|
| | 440 | function appendText(object, html) |
|---|
| | 441 | { |
|---|
| | 442 | html.push(escapeHTML(objectToString(object))); |
|---|
| | 443 | } |
|---|
| | 444 | |
|---|
| | 445 | function appendNull(object, html) |
|---|
| | 446 | { |
|---|
| | 447 | html.push('<span class="objectBox-null">', escapeHTML(objectToString(object)), '</span>'); |
|---|
| | 448 | } |
|---|
| | 449 | |
|---|
| | 450 | function appendString(object, html) |
|---|
| | 451 | { |
|---|
| | 452 | html.push('<span class="objectBox-string">"', escapeHTML(objectToString(object)), |
|---|
| | 453 | '"</span>'); |
|---|
| | 454 | } |
|---|
| | 455 | |
|---|
| | 456 | function appendInteger(object, html) |
|---|
| | 457 | { |
|---|
| | 458 | html.push('<span class="objectBox-number">', escapeHTML(objectToString(object)), '</span>'); |
|---|
| | 459 | } |
|---|
| | 460 | |
|---|
| | 461 | function appendFloat(object, html) |
|---|
| | 462 | { |
|---|
| | 463 | html.push('<span class="objectBox-number">', escapeHTML(objectToString(object)), '</span>'); |
|---|
| | 464 | } |
|---|
| | 465 | |
|---|
| | 466 | function appendFunction(object, html) |
|---|
| | 467 | { |
|---|
| | 468 | var reName = /function ?(.*?)\(/; |
|---|
| | 469 | var m = reName.exec(objectToString(object)); |
|---|
| | 470 | var name = m ? m[1] : "function"; |
|---|
| | 471 | html.push('<span class="objectBox-function">', escapeHTML(name), '()</span>'); |
|---|
| | 472 | } |
|---|
| | 473 | |
|---|
| | 474 | function appendObject(object, html) |
|---|
| | 475 | { |
|---|
| | 476 | try |
|---|
| | 477 | { |
|---|
| | 478 | if (object == undefined) |
|---|
| | 479 | appendNull("undefined", html); |
|---|
| | 480 | else if (object == null) |
|---|
| | 481 | appendNull("null", html); |
|---|
| | 482 | else if (typeof object == "string") |
|---|
| | 483 | appendString(object, html); |
|---|
| | 484 | else if (typeof object == "number") |
|---|
| | 485 | appendInteger(object, html); |
|---|
| | 486 | else if (typeof object == "function") |
|---|
| | 487 | appendFunction(object, html); |
|---|
| | 488 | else if (object.nodeType == 1) |
|---|
| | 489 | appendSelector(object, html); |
|---|
| | 490 | else if (typeof object == "object") |
|---|
| | 491 | appendObjectFormatted(object, html); |
|---|
| | 492 | else |
|---|
| | 493 | appendText(object, html); |
|---|
| | 494 | } |
|---|
| | 495 | catch (exc) |
|---|
| | 496 | { |
|---|
| | 497 | } |
|---|
| | 498 | } |
|---|
| | 499 | |
|---|
| | 500 | function appendObjectFormatted(object, html) |
|---|
| | 501 | { |
|---|
| | 502 | var text = objectToString(object); |
|---|
| | 503 | var reObject = /\[object (.*?)\]/; |
|---|
| | 504 | |
|---|
| | 505 | var m = reObject.exec(text); |
|---|
| | 506 | html.push('<span class="objectBox-object">', m ? m[1] : text, '</span>') |
|---|
| | 507 | } |
|---|
| | 508 | |
|---|
| | 509 | function appendSelector(object, html) |
|---|
| | 510 | { |
|---|
| | 511 | html.push('<span class="objectBox-selector">'); |
|---|
| | 512 | |
|---|
| | 513 | html.push('<span class="selectorTag">', escapeHTML(object.nodeName.toLowerCase()), '</span>'); |
|---|
| | 514 | if (object.id) |
|---|
| | 515 | html.push('<span class="selectorId">#', escapeHTML(object.id), '</span>'); |
|---|
| | 516 | if (object.className) |
|---|
| | 517 | html.push('<span class="selectorClass">.', escapeHTML(object.className), '</span>'); |
|---|
| | 518 | |
|---|
| | 519 | html.push('</span>'); |
|---|
| | 520 | } |
|---|
| | 521 | |
|---|
| | 522 | function appendNode(node, html) |
|---|
| | 523 | { |
|---|
| | 524 | if (node.nodeType == 1) |
|---|
| | 525 | { |
|---|
| | 526 | html.push( |
|---|
| | 527 | '<div class="objectBox-element">', |
|---|
| | 528 | '<<span class="nodeTag">', node.nodeName.toLowerCase(), '</span>'); |
|---|
| | 529 | |
|---|
| | 530 | for (var i = 0; i < node.attributes.length; ++i) |
|---|
| | 531 | { |
|---|
| | 532 | var attr = node.attributes[i]; |
|---|
| | 533 | if (!attr.specified) |
|---|
| | 534 | continue; |
|---|
| | 535 | |
|---|
| | 536 | html.push(' <span class="nodeName">', attr.nodeName.toLowerCase(), |
|---|
| | 537 | '</span>="<span class="nodeValue">', escapeHTML(attr.nodeValue), |
|---|
| | 538 | '</span>"') |
|---|
| | 539 | } |
|---|
| | 540 | |
|---|
| | 541 | if (node.firstChild) |
|---|
| | 542 | { |
|---|
| | 543 | html.push('></div><div class="nodeChildren">'); |
|---|
| | 544 | |
|---|
| | 545 | for (var child = node.firstChild; child; child = child.nextSibling) |
|---|
| | 546 | appendNode(child, html); |
|---|
| | 547 | |
|---|
| | 548 | html.push('</div><div class="objectBox-element"></<span class="nodeTag">', |
|---|
| | 549 | node.nodeName.toLowerCase(), '></span></div>'); |
|---|
| | 550 | } |
|---|
| | 551 | else |
|---|
| | 552 | html.push('/></div>'); |
|---|
| | 553 | } |
|---|
| | 554 | else if (node.nodeType == 3) |
|---|
| | 555 | { |
|---|
| | 556 | html.push('<div class="nodeText">', escapeHTML(node.nodeValue), |
|---|
| | 557 | '</div>'); |
|---|
| | 558 | } |
|---|
| | 559 | } |
|---|
| | 560 | |
|---|
| | 561 | // ******************************************************************************************** |
|---|
| | 562 | |
|---|
| | 563 | function addEvent(object, name, handler) |
|---|
| | 564 | { |
|---|
| | 565 | if (document.all) |
|---|
| | 566 | object.attachEvent("on"+name, handler); |
|---|
| | 567 | else |
|---|
| | 568 | object.addEventListener(name, handler, false); |
|---|
| | 569 | } |
|---|
| | 570 | |
|---|
| | 571 | function removeEvent(object, name, handler) |
|---|
| | 572 | { |
|---|
| | 573 | if (document.all) |
|---|
| | 574 | object.detachEvent("on"+name, handler); |
|---|
| | 575 | else |
|---|
| | 576 | object.removeEventListener(name, handler, false); |
|---|
| | 577 | } |
|---|
| | 578 | |
|---|
| | 579 | function cancelEvent(event) |
|---|
| | 580 | { |
|---|
| | 581 | if (document.all) |
|---|
| | 582 | event.cancelBubble = true; |
|---|
| | 583 | else |
|---|
| | 584 | event.stopPropagation(); |
|---|
| | 585 | } |
|---|
| | 586 | |
|---|
| | 587 | function onError(msg, href, lineNo) |
|---|
| | 588 | { |
|---|
| | 589 | var html = []; |
|---|
| | 590 | |
|---|
| | 591 | var lastSlash = href.lastIndexOf("/"); |
|---|
| | 592 | var fileName = lastSlash == -1 ? href : href.substr(lastSlash+1); |
|---|
| | 593 | |
|---|
| | 594 | html.push( |
|---|
| | 595 | '<span class="errorMessage">', msg, '</span>', |
|---|
| | 596 | '<div class="objectBox-sourceLink">', fileName, ' (line ', lineNo, ')</div>' |
|---|
| | 597 | ); |
|---|
| | 598 | |
|---|
| | 599 | logRow(html, "error"); |
|---|
| | 600 | }; |
|---|
| | 601 | |
|---|
| | 602 | function onKeyDown(event) |
|---|
| | 603 | { |
|---|
| | 604 | if (event.keyCode == 123) |
|---|
| | 605 | toggleConsole(); |
|---|
| | 606 | else if ((event.keyCode == 108 || event.keyCode == 76) && event.shiftKey |
|---|
| | 607 | && (event.metaKey || event.ctrlKey)) |
|---|
| | 608 | focusCommandLine(); |
|---|
| | 609 | else |
|---|
| | 610 | return; |
|---|
| | 611 | |
|---|
| | 612 | cancelEvent(event); |
|---|
| | 613 | } |
|---|
| | 614 | |
|---|
| | 615 | function onSplitterMouseDown(event) |
|---|
| | 616 | { |
|---|
| | 617 | if (isSafari || isOpera) |
|---|
| | 618 | return; |
|---|
| | 619 | |
|---|
| | 620 | addEvent(document, "mousemove", onSplitterMouseMove); |
|---|
| | 621 | addEvent(document, "mouseup", onSplitterMouseUp); |
|---|
| | 622 | |
|---|
| | 623 | for (var i = 0; i < frames.length; ++i) |
|---|
| | 624 | { |
|---|
| | 625 | addEvent(frames[i].document, "mousemove", onSplitterMouseMove); |
|---|
| | 626 | addEvent(frames[i].document, "mouseup", onSplitterMouseUp); |
|---|
| | 627 | } |
|---|
| | 628 | } |
|---|
| | 629 | |
|---|
| | 630 | function onSplitterMouseMove(event) |
|---|
| | 631 | { |
|---|
| | 632 | var win = document.all |
|---|
| | 633 | ? event.srcElement.ownerDocument.parentWindow |
|---|
| | 634 | : event.target.ownerDocument.defaultView; |
|---|
| | 635 | |
|---|
| | 636 | var clientY = event.clientY; |
|---|
| | 637 | if (win != win.parent) |
|---|
| | 638 | clientY += win.frameElement ? win.frameElement.offsetTop : 0; |
|---|
| | 639 | |
|---|
| | 640 | var height = consoleFrame.offsetTop + consoleFrame.clientHeight; |
|---|
| | 641 | var toolbar = consoleBody.ownerDocument.getElementById("toolbar"); |
|---|
| | 642 | var y = Math.max(height - clientY, |
|---|
| | 643 | toolbar.offsetHeight + commandLine.offsetHeight); |
|---|
| | 644 | |
|---|
| | 645 | consoleFrame.style.height = y + "px"; |
|---|
| | 646 | layout(); |
|---|
| | 647 | } |
|---|
| | 648 | |
|---|
| | 649 | function onSplitterMouseUp(event) |
|---|
| | 650 | { |
|---|
| | 651 | removeEvent(document, "mousemove", onSplitterMouseMove); |
|---|
| | 652 | removeEvent(document, "mouseup", onSplitterMouseUp); |
|---|
| | 653 | |
|---|
| | 654 | for (var i = 0; i < frames.length; ++i) |
|---|
| | 655 | { |
|---|
| | 656 | removeEvent(frames[i].document, "mousemove", onSplitterMouseMove); |
|---|
| | 657 | removeEvent(frames[i].document, "mouseup", onSplitterMouseUp); |
|---|
| | 658 | } |
|---|
| | 659 | } |
|---|
| | 660 | |
|---|
| | 661 | function onCommandLineKeyDown(event) |
|---|
| | 662 | { |
|---|
| | 663 | if (event.keyCode == 13) |
|---|
| | 664 | evalCommandLine(); |
|---|
| | 665 | else if (event.keyCode == 27) |
|---|
| | 666 | commandLine.value = ""; |
|---|
| | 667 | } |
|---|
| | 668 | |
|---|
| | 669 | window.onerror = onError; |
|---|
| | 670 | addEvent(document, isIE || isSafari ? "keydown" : "keypress", onKeyDown); |
|---|
| | 671 | |
|---|
| | 672 | if (document.documentElement.getAttribute("debug") == "true") |
|---|
| | 673 | toggleConsole(true); |
|---|
| | 674 | })(); |
|---|
| | 675 | } |