| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 if (obj === null) | 31 if (obj === null) |
| 32 return "null"; | 32 return "null"; |
| 33 | 33 |
| 34 var type = typeof obj; | 34 var type = typeof obj; |
| 35 if (type !== "object" && type !== "function") | 35 if (type !== "object" && type !== "function") |
| 36 return type; | 36 return type; |
| 37 | 37 |
| 38 win = win || window; | 38 win = win || window; |
| 39 | 39 |
| 40 if (obj instanceof win.Node) | 40 if (obj instanceof win.Node) |
| 41 return "node"; | 41 return (obj.nodeType === undefined ? type : "node"); |
| 42 if (obj instanceof win.String) | 42 if (obj instanceof win.String) |
| 43 return "string"; | 43 return "string"; |
| 44 if (obj instanceof win.Array) | 44 if (obj instanceof win.Array) |
| 45 return "array"; | 45 return "array"; |
| 46 if (obj instanceof win.Boolean) | 46 if (obj instanceof win.Boolean) |
| 47 return "boolean"; | 47 return "boolean"; |
| 48 if (obj instanceof win.Number) | 48 if (obj instanceof win.Number) |
| 49 return "number"; | 49 return "number"; |
| 50 if (obj instanceof win.Date) | 50 if (obj instanceof win.Date) |
| 51 return "date"; | 51 return "date"; |
| 52 if (obj instanceof win.RegExp) | 52 if (obj instanceof win.RegExp) |
| 53 return "regexp"; | 53 return "regexp"; |
| 54 if (obj instanceof win.Error) | 54 if (obj instanceof win.Error) |
| 55 return "error"; | 55 return "error"; |
| 56 return type; | 56 return type; |
| 57 } | 57 } |
| 58 | 58 |
| 59 Object.proxyType = function(objectProxy) |
| 60 { |
| 61 if (objectProxy === null) |
| 62 return "null"; |
| 63 |
| 64 var type = typeof objectProxy; |
| 65 if (type !== "object" && type !== "function") |
| 66 return type; |
| 67 |
| 68 return objectProxy.type; |
| 69 } |
| 70 |
| 59 Object.hasProperties = function(obj) | 71 Object.hasProperties = function(obj) |
| 60 { | 72 { |
| 61 if (typeof obj === "undefined" || typeof obj === "null") | 73 if (typeof obj === "undefined" || typeof obj === "null") |
| 62 return false; | 74 return false; |
| 63 for (var name in obj) | 75 for (var name in obj) |
| 64 return true; | 76 return true; |
| 65 return false; | 77 return false; |
| 66 } | 78 } |
| 67 | 79 |
| 68 Object.describe = function(obj, abbreviated) | 80 Object.describe = function(obj, abbreviated, win) |
| 69 { | 81 { |
| 70 var type1 = Object.type(obj); | 82 var type1 = Object.type(obj, win); |
| 71 var type2 = Object.prototype.toString.call(obj).replace(/^\[object (.*)\]$/i
, "$1"); | 83 var type2 = Object.prototype.toString.call(obj).replace(/^\[object (.*)\]$/i
, "$1"); |
| 72 | 84 |
| 73 switch (type1) { | 85 switch (type1) { |
| 74 case "object": | 86 case "object": |
| 75 case "node": | 87 case "node": |
| 76 return type2; | 88 return type2; |
| 77 case "array": | 89 case "array": |
| 78 return "[" + obj.toString() + "]"; | 90 return "[" + obj.toString() + "]"; |
| 79 case "string": | 91 case "string": |
| 80 if (obj.length > 100) | 92 if (obj.length > 100) |
| 81 return "\"" + obj.substring(0, 100) + "\u2026\""; | 93 return "\"" + obj.substring(0, 100) + "\u2026\""; |
| 82 return "\"" + obj + "\""; | 94 return "\"" + obj + "\""; |
| 83 case "function": | 95 case "function": |
| 84 var objectText = String(obj); | 96 var objectText = String(obj); |
| 85 if (!/^function /.test(objectText)) | 97 if (!/^function /.test(objectText)) |
| 86 objectText = (type2 == "object") ? type1 : type2; | 98 objectText = (type2 == "object") ? type1 : type2; |
| 87 else if (abbreviated) | 99 else if (abbreviated) |
| 88 objectText = /.*/.exec(obj)[0].replace(/ +$/g, ""); | 100 objectText = /.*/.exec(obj)[0].replace(/ +$/g, ""); |
| 89 return objectText; | 101 return objectText; |
| 90 case "regexp": | 102 case "regexp": |
| 91 return String(obj).replace(/([\\\/])/g, "\\$1").replace(/\\(\/[gim]*)$/,
"$1").substring(1); | 103 return String(obj).replace(/([\\\/])/g, "\\$1").replace(/\\(\/[gim]*)$/,
"$1").substring(1); |
| 92 default: | 104 default: |
| 93 return String(obj); | 105 return String(obj); |
| 94 } | 106 } |
| 95 } | 107 } |
| 96 | 108 |
| 97 Object.sortedProperties = function(obj) | 109 Object.properties = function(obj) |
| 98 { | 110 { |
| 99 var properties = []; | 111 var properties = []; |
| 100 for (var prop in obj) | 112 for (var prop in obj) |
| 101 properties.push(prop); | 113 properties.push(prop); |
| 102 properties.sort(); | |
| 103 return properties; | 114 return properties; |
| 104 } | 115 } |
| 105 | 116 |
| 117 Object.sortedProperties = function(obj, sortFunc) |
| 118 { |
| 119 return Object.properties(obj).sort(sortFunc); |
| 120 } |
| 121 |
| 106 Function.prototype.bind = function(thisObject) | 122 Function.prototype.bind = function(thisObject) |
| 107 { | 123 { |
| 108 var func = this; | 124 var func = this; |
| 109 var args = Array.prototype.slice.call(arguments, 1); | 125 var args = Array.prototype.slice.call(arguments, 1); |
| 110 return function() { return func.apply(thisObject, args.concat(Array.prototyp
e.slice.call(arguments, 0))) }; | 126 return function() { return func.apply(thisObject, args.concat(Array.prototyp
e.slice.call(arguments, 0))) }; |
| 111 } | 127 } |
| 112 | 128 |
| 113 Node.prototype.rangeOfWord = function(offset, stopCharacters, stayWithinNode, di
rection) | 129 Node.prototype.rangeOfWord = function(offset, stopCharacters, stayWithinNode, di
rection) |
| 114 { | 130 { |
| 115 var startNode; | 131 var startNode; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 return false; | 243 return false; |
| 228 // Test for the simple case before using a RegExp. | 244 // Test for the simple case before using a RegExp. |
| 229 if (this.className === className) | 245 if (this.className === className) |
| 230 return true; | 246 return true; |
| 231 var regex = new RegExp("(^|\\s)" + className.escapeForRegExp() + "($|\\s)"); | 247 var regex = new RegExp("(^|\\s)" + className.escapeForRegExp() + "($|\\s)"); |
| 232 return regex.test(this.className); | 248 return regex.test(this.className); |
| 233 } | 249 } |
| 234 | 250 |
| 235 Node.prototype.enclosingNodeOrSelfWithNodeNameInArray = function(nameArray) | 251 Node.prototype.enclosingNodeOrSelfWithNodeNameInArray = function(nameArray) |
| 236 { | 252 { |
| 237 for (var node = this; node && !objectsAreSame(node, this.ownerDocument); nod
e = node.parentNode) | 253 for (var node = this; node && node !== this.ownerDocument; node = node.paren
tNode) |
| 238 for (var i = 0; i < nameArray.length; ++i) | 254 for (var i = 0; i < nameArray.length; ++i) |
| 239 if (node.nodeName.toLowerCase() === nameArray[i].toLowerCase()) | 255 if (node.nodeName.toLowerCase() === nameArray[i].toLowerCase()) |
| 240 return node; | 256 return node; |
| 241 return null; | 257 return null; |
| 242 } | 258 } |
| 243 | 259 |
| 244 Node.prototype.enclosingNodeOrSelfWithNodeName = function(nodeName) | 260 Node.prototype.enclosingNodeOrSelfWithNodeName = function(nodeName) |
| 245 { | 261 { |
| 246 return this.enclosingNodeOrSelfWithNodeNameInArray([nodeName]); | 262 return this.enclosingNodeOrSelfWithNodeNameInArray([nodeName]); |
| 247 } | 263 } |
| 248 | 264 |
| 249 Node.prototype.enclosingNodeOrSelfWithClass = function(className) | 265 Node.prototype.enclosingNodeOrSelfWithClass = function(className) |
| 250 { | 266 { |
| 251 for (var node = this; node && !objectsAreSame(node, this.ownerDocument); nod
e = node.parentNode) | 267 for (var node = this; node && node !== this.ownerDocument; node = node.paren
tNode) |
| 252 if (node.nodeType === Node.ELEMENT_NODE && node.hasStyleClass(className)
) | 268 if (node.nodeType === Node.ELEMENT_NODE && node.hasStyleClass(className)
) |
| 253 return node; | 269 return node; |
| 254 return null; | 270 return null; |
| 255 } | 271 } |
| 256 | 272 |
| 257 Node.prototype.enclosingNodeWithClass = function(className) | 273 Node.prototype.enclosingNodeWithClass = function(className) |
| 258 { | 274 { |
| 259 if (!this.parentNode) | 275 if (!this.parentNode) |
| 260 return null; | 276 return null; |
| 261 return this.parentNode.enclosingNodeOrSelfWithClass(className); | 277 return this.parentNode.enclosingNodeOrSelfWithClass(className); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 var total = 0; | 310 var total = 0; |
| 295 for (var element = this; element; element = element.offsetParent) | 311 for (var element = this; element; element = element.offsetParent) |
| 296 total += element.offsetTop; | 312 total += element.offsetTop; |
| 297 return total; | 313 return total; |
| 298 }); | 314 }); |
| 299 | 315 |
| 300 Element.prototype.firstChildSkippingWhitespace = firstChildSkippingWhitespace; | 316 Element.prototype.firstChildSkippingWhitespace = firstChildSkippingWhitespace; |
| 301 Element.prototype.lastChildSkippingWhitespace = lastChildSkippingWhitespace; | 317 Element.prototype.lastChildSkippingWhitespace = lastChildSkippingWhitespace; |
| 302 | 318 |
| 303 Node.prototype.isWhitespace = isNodeWhitespace; | 319 Node.prototype.isWhitespace = isNodeWhitespace; |
| 304 Node.prototype.nodeTypeName = nodeTypeName; | |
| 305 Node.prototype.displayName = nodeDisplayName; | 320 Node.prototype.displayName = nodeDisplayName; |
| 306 Node.prototype.contentPreview = nodeContentPreview; | 321 Node.prototype.isAncestor = function(node) |
| 307 Node.prototype.isAncestor = isAncestorNode; | 322 { |
| 323 return isAncestorNode(this, node); |
| 324 }; |
| 308 Node.prototype.isDescendant = isDescendantNode; | 325 Node.prototype.isDescendant = isDescendantNode; |
| 309 Node.prototype.firstCommonAncestor = firstCommonNodeAncestor; | |
| 310 Node.prototype.nextSiblingSkippingWhitespace = nextSiblingSkippingWhitespace; | 326 Node.prototype.nextSiblingSkippingWhitespace = nextSiblingSkippingWhitespace; |
| 311 Node.prototype.previousSiblingSkippingWhitespace = previousSiblingSkippingWhites
pace; | 327 Node.prototype.previousSiblingSkippingWhitespace = previousSiblingSkippingWhites
pace; |
| 312 Node.prototype.traverseNextNode = traverseNextNode; | 328 Node.prototype.traverseNextNode = traverseNextNode; |
| 313 Node.prototype.traversePreviousNode = traversePreviousNode; | 329 Node.prototype.traversePreviousNode = traversePreviousNode; |
| 314 Node.prototype.onlyTextChild = onlyTextChild; | 330 Node.prototype.onlyTextChild = onlyTextChild; |
| 315 | 331 |
| 316 String.prototype.hasSubstring = function(string, caseInsensitive) | 332 String.prototype.hasSubstring = function(string, caseInsensitive) |
| 317 { | 333 { |
| 318 if (!caseInsensitive) | 334 if (!caseInsensitive) |
| 319 return this.indexOf(string) !== -1; | 335 return this.indexOf(string) !== -1; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 } | 390 } |
| 375 | 391 |
| 376 String.prototype.trimURL = function(baseURLDomain) | 392 String.prototype.trimURL = function(baseURLDomain) |
| 377 { | 393 { |
| 378 var result = this.replace(new RegExp("^http[s]?:\/\/", "i"), ""); | 394 var result = this.replace(new RegExp("^http[s]?:\/\/", "i"), ""); |
| 379 if (baseURLDomain) | 395 if (baseURLDomain) |
| 380 result = result.replace(new RegExp("^" + baseURLDomain.escapeForRegExp()
, "i"), ""); | 396 result = result.replace(new RegExp("^" + baseURLDomain.escapeForRegExp()
, "i"), ""); |
| 381 return result; | 397 return result; |
| 382 } | 398 } |
| 383 | 399 |
| 384 function getStyleTextWithShorthands(style) | |
| 385 { | |
| 386 var cssText = ""; | |
| 387 var foundProperties = {}; | |
| 388 for (var i = 0; i < style.length; ++i) { | |
| 389 var individualProperty = style[i]; | |
| 390 var shorthandProperty = style.getPropertyShorthand(individualProperty); | |
| 391 var propertyName = (shorthandProperty || individualProperty); | |
| 392 | |
| 393 if (propertyName in foundProperties) | |
| 394 continue; | |
| 395 | |
| 396 if (shorthandProperty) { | |
| 397 var value = getShorthandValue(style, shorthandProperty); | |
| 398 var priority = getShorthandPriority(style, shorthandProperty); | |
| 399 } else { | |
| 400 var value = style.getPropertyValue(individualProperty); | |
| 401 var priority = style.getPropertyPriority(individualProperty); | |
| 402 } | |
| 403 | |
| 404 foundProperties[propertyName] = true; | |
| 405 | |
| 406 cssText += propertyName + ": " + value; | |
| 407 if (priority) | |
| 408 cssText += " !" + priority; | |
| 409 cssText += "; "; | |
| 410 } | |
| 411 | |
| 412 return cssText; | |
| 413 } | |
| 414 | |
| 415 function getShorthandValue(style, shorthandProperty) | |
| 416 { | |
| 417 var value = style.getPropertyValue(shorthandProperty); | |
| 418 if (!value) { | |
| 419 // Some shorthands (like border) return a null value, so compute a short
hand value. | |
| 420 // FIXME: remove this when http://bugs.webkit.org/show_bug.cgi?id=15823
is fixed. | |
| 421 | |
| 422 var foundProperties = {}; | |
| 423 for (var i = 0; i < style.length; ++i) { | |
| 424 var individualProperty = style[i]; | |
| 425 if (individualProperty in foundProperties || style.getPropertyShorth
and(individualProperty) !== shorthandProperty) | |
| 426 continue; | |
| 427 | |
| 428 var individualValue = style.getPropertyValue(individualProperty); | |
| 429 if (style.isPropertyImplicit(individualProperty) || individualValue
=== "initial") | |
| 430 continue; | |
| 431 | |
| 432 foundProperties[individualProperty] = true; | |
| 433 | |
| 434 if (!value) | |
| 435 value = ""; | |
| 436 else if (value.length) | |
| 437 value += " "; | |
| 438 value += individualValue; | |
| 439 } | |
| 440 } | |
| 441 return value; | |
| 442 } | |
| 443 | |
| 444 function getShorthandPriority(style, shorthandProperty) | |
| 445 { | |
| 446 var priority = style.getPropertyPriority(shorthandProperty); | |
| 447 if (!priority) { | |
| 448 for (var i = 0; i < style.length; ++i) { | |
| 449 var individualProperty = style[i]; | |
| 450 if (style.getPropertyShorthand(individualProperty) !== shorthandProp
erty) | |
| 451 continue; | |
| 452 priority = style.getPropertyPriority(individualProperty); | |
| 453 break; | |
| 454 } | |
| 455 } | |
| 456 return priority; | |
| 457 } | |
| 458 | |
| 459 function getLonghandProperties(style, shorthandProperty) | |
| 460 { | |
| 461 var properties = []; | |
| 462 var foundProperties = {}; | |
| 463 | |
| 464 for (var i = 0; i < style.length; ++i) { | |
| 465 var individualProperty = style[i]; | |
| 466 if (individualProperty in foundProperties || style.getPropertyShorthand(
individualProperty) !== shorthandProperty) | |
| 467 continue; | |
| 468 foundProperties[individualProperty] = true; | |
| 469 properties.push(individualProperty); | |
| 470 } | |
| 471 | |
| 472 return properties; | |
| 473 } | |
| 474 | |
| 475 function getUniqueStyleProperties(style) | |
| 476 { | |
| 477 var properties = []; | |
| 478 var foundProperties = {}; | |
| 479 | |
| 480 for (var i = 0; i < style.length; ++i) { | |
| 481 var property = style[i]; | |
| 482 if (property in foundProperties) | |
| 483 continue; | |
| 484 foundProperties[property] = true; | |
| 485 properties.push(property); | |
| 486 } | |
| 487 | |
| 488 return properties; | |
| 489 } | |
| 490 | |
| 491 function isNodeWhitespace() | 400 function isNodeWhitespace() |
| 492 { | 401 { |
| 493 if (!this || this.nodeType !== Node.TEXT_NODE) | 402 if (!this || this.nodeType !== Node.TEXT_NODE) |
| 494 return false; | 403 return false; |
| 495 if (!this.nodeValue.length) | 404 if (!this.nodeValue.length) |
| 496 return true; | 405 return true; |
| 497 return this.nodeValue.match(/^[\s\xA0]+$/); | 406 return this.nodeValue.match(/^[\s\xA0]+$/); |
| 498 } | 407 } |
| 499 | 408 |
| 500 function nodeTypeName() | |
| 501 { | |
| 502 if (!this) | |
| 503 return "(unknown)"; | |
| 504 | |
| 505 switch (this.nodeType) { | |
| 506 case Node.ELEMENT_NODE: return "Element"; | |
| 507 case Node.ATTRIBUTE_NODE: return "Attribute"; | |
| 508 case Node.TEXT_NODE: return "Text"; | |
| 509 case Node.CDATA_SECTION_NODE: return "Character Data"; | |
| 510 case Node.ENTITY_REFERENCE_NODE: return "Entity Reference"; | |
| 511 case Node.ENTITY_NODE: return "Entity"; | |
| 512 case Node.PROCESSING_INSTRUCTION_NODE: return "Processing Instruction"; | |
| 513 case Node.COMMENT_NODE: return "Comment"; | |
| 514 case Node.DOCUMENT_NODE: return "Document"; | |
| 515 case Node.DOCUMENT_TYPE_NODE: return "Document Type"; | |
| 516 case Node.DOCUMENT_FRAGMENT_NODE: return "Document Fragment"; | |
| 517 case Node.NOTATION_NODE: return "Notation"; | |
| 518 } | |
| 519 | |
| 520 return "(unknown)"; | |
| 521 } | |
| 522 | |
| 523 function nodeDisplayName() | 409 function nodeDisplayName() |
| 524 { | 410 { |
| 525 if (!this) | 411 if (!this) |
| 526 return ""; | 412 return ""; |
| 527 | 413 |
| 528 switch (this.nodeType) { | 414 switch (this.nodeType) { |
| 529 case Node.DOCUMENT_NODE: | 415 case Node.DOCUMENT_NODE: |
| 530 return "Document"; | 416 return "Document"; |
| 531 | 417 |
| 532 case Node.ELEMENT_NODE: | 418 case Node.ELEMENT_NODE: |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 } else if (this.systemId) | 473 } else if (this.systemId) |
| 588 docType += " SYSTEM \"" + this.systemId + "\""; | 474 docType += " SYSTEM \"" + this.systemId + "\""; |
| 589 if (this.internalSubset) | 475 if (this.internalSubset) |
| 590 docType += " [" + this.internalSubset + "]"; | 476 docType += " [" + this.internalSubset + "]"; |
| 591 return docType + ">"; | 477 return docType + ">"; |
| 592 } | 478 } |
| 593 | 479 |
| 594 return this.nodeName.toLowerCase().collapseWhitespace(); | 480 return this.nodeName.toLowerCase().collapseWhitespace(); |
| 595 } | 481 } |
| 596 | 482 |
| 597 function nodeContentPreview() | 483 function isAncestorNode(ancestor, node) |
| 598 { | 484 { |
| 599 if (!this || !this.hasChildNodes || !this.hasChildNodes()) | 485 if (!node || !ancestor) |
| 600 return ""; | |
| 601 | |
| 602 var limit = 0; | |
| 603 var preview = ""; | |
| 604 | |
| 605 // always skip whitespace here | |
| 606 var currentNode = traverseNextNode.call(this, true, this); | |
| 607 while (currentNode) { | |
| 608 if (currentNode.nodeType === Node.TEXT_NODE) | |
| 609 preview += currentNode.nodeValue.escapeHTML(); | |
| 610 else | |
| 611 preview += nodeDisplayName.call(currentNode).escapeHTML(); | |
| 612 | |
| 613 currentNode = traverseNextNode.call(currentNode, true, this); | |
| 614 | |
| 615 if (++limit > 4) { | |
| 616 preview += "…"; // ellipsis | |
| 617 break; | |
| 618 } | |
| 619 } | |
| 620 | |
| 621 return preview.collapseWhitespace(); | |
| 622 } | |
| 623 | |
| 624 function objectsAreSame(a, b) | |
| 625 { | |
| 626 // FIXME: Make this more generic so is works with any wrapped object, not ju
st nodes. | |
| 627 // This function is used to compare nodes that might be JSInspectedObjectWra
ppers, since | |
| 628 // JavaScript equality is not true for JSInspectedObjectWrappers of the same
node wrapped | |
| 629 // with different global ExecStates, we use isSameNode to compare them. | |
| 630 if (a === b) | |
| 631 return true; | |
| 632 if (!a || !b) | |
| 633 return false; | |
| 634 if (a.isSameNode && b.isSameNode) | |
| 635 return a.isSameNode(b); | |
| 636 return false; | |
| 637 } | |
| 638 | |
| 639 function isAncestorNode(ancestor) | |
| 640 { | |
| 641 if (!this || !ancestor) | |
| 642 return false; | 486 return false; |
| 643 | 487 |
| 644 var currentNode = ancestor.parentNode; | 488 var currentNode = node.parentNode; |
| 645 while (currentNode) { | 489 while (currentNode) { |
| 646 if (objectsAreSame(this, currentNode)) | 490 if (ancestor === currentNode) |
| 647 return true; | 491 return true; |
| 648 currentNode = currentNode.parentNode; | 492 currentNode = currentNode.parentNode; |
| 649 } | 493 } |
| 650 | |
| 651 return false; | 494 return false; |
| 652 } | 495 } |
| 653 | 496 |
| 654 function isDescendantNode(descendant) | 497 function isDescendantNode(descendant) |
| 655 { | 498 { |
| 656 return isAncestorNode.call(descendant, this); | 499 return isAncestorNode(descendant, this); |
| 657 } | |
| 658 | |
| 659 function firstCommonNodeAncestor(node) | |
| 660 { | |
| 661 if (!this || !node) | |
| 662 return; | |
| 663 | |
| 664 var node1 = this.parentNode; | |
| 665 var node2 = node.parentNode; | |
| 666 | |
| 667 if ((!node1 || !node2) || !objectsAreSame(node1, node2)) | |
| 668 return null; | |
| 669 | |
| 670 while (node1 && node2) { | |
| 671 if (!node1.parentNode || !node2.parentNode) | |
| 672 break; | |
| 673 if (!objectsAreSame(node1, node2)) | |
| 674 break; | |
| 675 | |
| 676 node1 = node1.parentNode; | |
| 677 node2 = node2.parentNode; | |
| 678 } | |
| 679 | |
| 680 return node1; | |
| 681 } | 500 } |
| 682 | 501 |
| 683 function nextSiblingSkippingWhitespace() | 502 function nextSiblingSkippingWhitespace() |
| 684 { | 503 { |
| 685 if (!this) | 504 if (!this) |
| 686 return; | 505 return; |
| 687 var node = this.nextSibling; | 506 var node = this.nextSibling; |
| 688 while (node && node.nodeType === Node.TEXT_NODE && isNodeWhitespace.call(nod
e)) | 507 while (node && node.nodeType === Node.TEXT_NODE && isNodeWhitespace.call(nod
e)) |
| 689 node = node.nextSibling; | 508 node = node.nextSibling; |
| 690 return node; | 509 return node; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 | 541 |
| 723 function traverseNextNode(skipWhitespace, stayWithin) | 542 function traverseNextNode(skipWhitespace, stayWithin) |
| 724 { | 543 { |
| 725 if (!this) | 544 if (!this) |
| 726 return; | 545 return; |
| 727 | 546 |
| 728 var node = skipWhitespace ? firstChildSkippingWhitespace.call(this) : this.f
irstChild; | 547 var node = skipWhitespace ? firstChildSkippingWhitespace.call(this) : this.f
irstChild; |
| 729 if (node) | 548 if (node) |
| 730 return node; | 549 return node; |
| 731 | 550 |
| 732 if (stayWithin && objectsAreSame(this, stayWithin)) | 551 if (stayWithin && this === stayWithin) |
| 733 return null; | 552 return null; |
| 734 | 553 |
| 735 node = skipWhitespace ? nextSiblingSkippingWhitespace.call(this) : this.next
Sibling; | 554 node = skipWhitespace ? nextSiblingSkippingWhitespace.call(this) : this.next
Sibling; |
| 736 if (node) | 555 if (node) |
| 737 return node; | 556 return node; |
| 738 | 557 |
| 739 node = this; | 558 node = this; |
| 740 while (node && !(skipWhitespace ? nextSiblingSkippingWhitespace.call(node) :
node.nextSibling) && (!stayWithin || !node.parentNode || !objectsAreSame(node.p
arentNode, stayWithin))) | 559 while (node && !(skipWhitespace ? nextSiblingSkippingWhitespace.call(node) :
node.nextSibling) && (!stayWithin || !node.parentNode || node.parentNode !== st
ayWithin)) |
| 741 node = node.parentNode; | 560 node = node.parentNode; |
| 742 if (!node) | 561 if (!node) |
| 743 return null; | 562 return null; |
| 744 | 563 |
| 745 return skipWhitespace ? nextSiblingSkippingWhitespace.call(node) : node.next
Sibling; | 564 return skipWhitespace ? nextSiblingSkippingWhitespace.call(node) : node.next
Sibling; |
| 746 } | 565 } |
| 747 | 566 |
| 748 function traversePreviousNode(skipWhitespace, stayWithin) | 567 function traversePreviousNode(skipWhitespace, stayWithin) |
| 749 { | 568 { |
| 750 if (!this) | 569 if (!this) |
| 751 return; | 570 return; |
| 752 if (stayWithin && objectsAreSame(this, stayWithin)) | 571 if (stayWithin && this === stayWithin) |
| 753 return null; | 572 return null; |
| 754 var node = skipWhitespace ? previousSiblingSkippingWhitespace.call(this) : t
his.previousSibling; | 573 var node = skipWhitespace ? previousSiblingSkippingWhitespace.call(this) : t
his.previousSibling; |
| 755 while (node && (skipWhitespace ? lastChildSkippingWhitespace.call(node) : no
de.lastChild) ) | 574 while (node && (skipWhitespace ? lastChildSkippingWhitespace.call(node) : no
de.lastChild) ) |
| 756 node = skipWhitespace ? lastChildSkippingWhitespace.call(node) : node.la
stChild; | 575 node = skipWhitespace ? lastChildSkippingWhitespace.call(node) : node.la
stChild; |
| 757 if (node) | 576 if (node) |
| 758 return node; | 577 return node; |
| 759 return this.parentNode; | 578 return this.parentNode; |
| 760 } | 579 } |
| 761 | 580 |
| 762 function onlyTextChild(ignoreWhitespace) | 581 function onlyTextChild(ignoreWhitespace) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 info.title = this.nodeName.toLowerCase().collapseWhitespace().escape
HTML(); | 662 info.title = this.nodeName.toLowerCase().collapseWhitespace().escape
HTML(); |
| 844 } | 663 } |
| 845 | 664 |
| 846 return info; | 665 return info; |
| 847 } | 666 } |
| 848 | 667 |
| 849 function getDocumentForNode(node) { | 668 function getDocumentForNode(node) { |
| 850 return node.nodeType == Node.DOCUMENT_NODE ? node : node.ownerDocument; | 669 return node.nodeType == Node.DOCUMENT_NODE ? node : node.ownerDocument; |
| 851 } | 670 } |
| 852 | 671 |
| 853 function parentNodeOrFrameElement(node) { | 672 function parentNode(node) { |
| 854 var parent = node.parentNode; | 673 return node.parentNode; |
| 855 if (parent) | |
| 856 return parent; | |
| 857 | |
| 858 return getDocumentForNode(node).defaultView.frameElement; | |
| 859 } | |
| 860 | |
| 861 function isAncestorIncludingParentFrames(a, b) { | |
| 862 if (objectsAreSame(a, b)) | |
| 863 return false; | |
| 864 for (var node = b; node; node = getDocumentForNode(node).defaultView.frameEl
ement) | |
| 865 if (objectsAreSame(a, node) || isAncestorNode.call(a, node)) | |
| 866 return true; | |
| 867 return false; | |
| 868 } | 674 } |
| 869 | 675 |
| 870 Number.secondsToString = function(seconds, formatterFunction, higherResolution) | 676 Number.secondsToString = function(seconds, formatterFunction, higherResolution) |
| 871 { | 677 { |
| 872 if (!formatterFunction) | 678 if (!formatterFunction) |
| 873 formatterFunction = String.sprintf; | 679 formatterFunction = String.sprintf; |
| 874 | 680 |
| 875 var ms = seconds * 1000; | 681 var ms = seconds * 1000; |
| 876 if (higherResolution && ms < 1000) | 682 if (higherResolution && ms < 1000) |
| 877 return formatterFunction("%.3fms", ms); | 683 return formatterFunction("%.3fms", ms); |
| 878 else if (ms < 1000) | 684 else if (ms < 1000) |
| 879 return formatterFunction("%.0fms", ms); | 685 return formatterFunction("%.0fms", ms); |
| 880 | 686 |
| 881 if (seconds < 60) | 687 if (seconds < 60) |
| 882 return formatterFunction("%.2fs", seconds); | 688 return formatterFunction("%.2fs", seconds); |
| 883 | 689 |
| 884 var minutes = seconds / 60; | 690 var minutes = seconds / 60; |
| 885 if (minutes < 60) | 691 if (minutes < 60) |
| 886 return formatterFunction("%.1fmin", minutes); | 692 return formatterFunction("%.1fmin", minutes); |
| 887 | 693 |
| 888 var hours = minutes / 60; | 694 var hours = minutes / 60; |
| 889 if (hours < 24) | 695 if (hours < 24) |
| 890 return formatterFunction("%.1fhrs", hours); | 696 return formatterFunction("%.1fhrs", hours); |
| 891 | 697 |
| 892 var days = hours / 24; | 698 var days = hours / 24; |
| 893 return formatterFunction("%.1f days", days); | 699 return formatterFunction("%.1f days", days); |
| 894 } | 700 } |
| 895 | 701 |
| 896 Number.bytesToString = function(bytes, formatterFunction) | 702 Number.bytesToString = function(bytes, formatterFunction, higherResolution) |
| 897 { | 703 { |
| 898 if (!formatterFunction) | 704 if (!formatterFunction) |
| 899 formatterFunction = String.sprintf; | 705 formatterFunction = String.sprintf; |
| 706 if (typeof higherResolution === "undefined") |
| 707 higherResolution = true; |
| 900 | 708 |
| 901 if (bytes < 1024) | 709 if (bytes < 1024) |
| 902 return formatterFunction("%.0fB", bytes); | 710 return formatterFunction("%.0fB", bytes); |
| 903 | 711 |
| 904 var kilobytes = bytes / 1024; | 712 var kilobytes = bytes / 1024; |
| 905 if (kilobytes < 1024) | 713 if (higherResolution && kilobytes < 1024) |
| 906 return formatterFunction("%.2fKB", kilobytes); | 714 return formatterFunction("%.2fKB", kilobytes); |
| 715 else if (kilobytes < 1024) |
| 716 return formatterFunction("%.0fKB", kilobytes); |
| 907 | 717 |
| 908 var megabytes = kilobytes / 1024; | 718 var megabytes = kilobytes / 1024; |
| 909 return formatterFunction("%.3fMB", megabytes); | 719 if (higherResolution) |
| 720 return formatterFunction("%.3fMB", megabytes); |
| 721 else |
| 722 return formatterFunction("%.0fMB", megabytes); |
| 910 } | 723 } |
| 911 | 724 |
| 912 Number.constrain = function(num, min, max) | 725 Number.constrain = function(num, min, max) |
| 913 { | 726 { |
| 914 if (num < min) | 727 if (num < min) |
| 915 num = min; | 728 num = min; |
| 916 else if (num > max) | 729 else if (num > max) |
| 917 num = max; | 730 num = max; |
| 918 return num; | 731 return num; |
| 919 } | 732 } |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 | 940 |
| 1128 var unusedSubstitutions = []; | 941 var unusedSubstitutions = []; |
| 1129 for (var i = 0; i < substitutions.length; ++i) { | 942 for (var i = 0; i < substitutions.length; ++i) { |
| 1130 if (i in usedSubstitutionIndexes) | 943 if (i in usedSubstitutionIndexes) |
| 1131 continue; | 944 continue; |
| 1132 unusedSubstitutions.push(substitutions[i]); | 945 unusedSubstitutions.push(substitutions[i]); |
| 1133 } | 946 } |
| 1134 | 947 |
| 1135 return { formattedResult: result, unusedSubstitutions: unusedSubstitutions }
; | 948 return { formattedResult: result, unusedSubstitutions: unusedSubstitutions }
; |
| 1136 } | 949 } |
| OLD | NEW |