/node_modules/node-inspector/front-end/devtools.js
JavaScript | 18673 lines | 15945 code | 2253 blank | 475 comment | 1502 complexity | a4c4924773b2b5e2f953e62c60f1ad5e MD5 | raw file
Possible License(s): MIT, Apache-2.0, BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- String.prototype.hasSubstring = function(string, caseInsensitive)
- {
- if (!caseInsensitive)
- return this.indexOf(string) !== -1;
- return this.match(new RegExp(string.escapeForRegExp(), "i"));
- }
- String.prototype.findAll = function(string)
- {
- var matches = [];
- var i = this.indexOf(string);
- while (i !== -1) {
- matches.push(i);
- i = this.indexOf(string, i + string.length);
- }
- return matches;
- }
- String.prototype.lineEndings = function()
- {
- if (!this._lineEndings) {
- this._lineEndings = this.findAll("\n");
- this._lineEndings.push(this.length);
- }
- return this._lineEndings;
- }
- String.prototype.escapeCharacters = function(chars)
- {
- var foundChar = false;
- for (var i = 0; i < chars.length; ++i) {
- if (this.indexOf(chars.charAt(i)) !== -1) {
- foundChar = true;
- break;
- }
- }
- if (!foundChar)
- return this;
- var result = "";
- for (var i = 0; i < this.length; ++i) {
- if (chars.indexOf(this.charAt(i)) !== -1)
- result += "\\";
- result += this.charAt(i);
- }
- return result;
- }
- String.prototype.escapeForRegExp = function()
- {
- return this.escapeCharacters("^[]{}()\\.$*+?|");
- }
- String.prototype.escapeHTML = function()
- {
- return this.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
- }
- String.prototype.collapseWhitespace = function()
- {
- return this.replace(/[\s\xA0]+/g, " ");
- }
- String.prototype.trimMiddle = function(maxLength)
- {
- if (this.length <= maxLength)
- return this;
- var leftHalf = maxLength >> 1;
- var rightHalf = maxLength - leftHalf - 1;
- return this.substr(0, leftHalf) + "\u2026" + this.substr(this.length - rightHalf, rightHalf);
- }
- String.prototype.trimEnd = function(maxLength)
- {
- if (this.length <= maxLength)
- return this;
- return this.substr(0, maxLength - 1) + "\u2026";
- }
- String.prototype.trimURL = function(baseURLDomain)
- {
- var result = this.replace(/^(https|http|file):\/\//i, "");
- if (baseURLDomain)
- result = result.replace(new RegExp("^" + baseURLDomain.escapeForRegExp(), "i"), "");
- return result;
- }
- String.prototype.removeURLFragment = function()
- {
- var fragmentIndex = this.indexOf("#");
- if (fragmentIndex == -1)
- fragmentIndex = this.length;
- return this.substring(0, fragmentIndex);
- }
- String.prototype.startsWith = function(substring)
- {
- return !this.lastIndexOf(substring, 0);
- }
- String.prototype.endsWith = function(substring)
- {
- return this.indexOf(substring, this.length - substring.length) !== -1;
- }
- Number.constrain = function(num, min, max)
- {
- if (num < min)
- num = min;
- else if (num > max)
- num = max;
- return num;
- }
- Date.prototype.toISO8601Compact = function()
- {
- function leadZero(x)
- {
- return x > 9 ? '' + x : '0' + x
- }
- return this.getFullYear() +
- leadZero(this.getMonth() + 1) +
- leadZero(this.getDate()) + 'T' +
- leadZero(this.getHours()) +
- leadZero(this.getMinutes()) +
- leadZero(this.getSeconds());
- }
- Object.defineProperty(Array.prototype, "remove",
- {
- value: function(value, onlyFirst)
- {
- if (onlyFirst) {
- var index = this.indexOf(value);
- if (index !== -1)
- this.splice(index, 1);
- return;
- }
- var length = this.length;
- for (var i = 0; i < length; ++i) {
- if (this[i] === value)
- this.splice(i, 1);
- }
- }
- });
- Object.defineProperty(Array.prototype, "keySet",
- {
- value: function()
- {
- var keys = {};
- for (var i = 0; i < this.length; ++i)
- keys[this[i]] = true;
- return keys;
- }
- });
- Object.defineProperty(Array.prototype, "upperBound",
- {
- value: function(value)
- {
- var first = 0;
- var count = this.length;
- while (count > 0) {
- var step = count >> 1;
- var middle = first + step;
- if (value >= this[middle]) {
- first = middle + 1;
- count -= step + 1;
- } else
- count = step;
- }
- return first;
- }
- });
- Object.defineProperty(Uint32Array.prototype, "sort", {
- value: Array.prototype.sort
- });
- (function() {
- var partition = {
- value: function(comparator, left, right, pivotIndex)
- {
- function swap(array, i1, i2)
- {
- var temp = array[i1];
- array[i1] = array[i2];
- array[i2] = temp;
- }
- var pivotValue = this[pivotIndex];
- swap(this, right, pivotIndex);
- var storeIndex = left;
- for (var i = left; i < right; ++i) {
- if (comparator(this[i], pivotValue) < 0) {
- swap(this, storeIndex, i);
- ++storeIndex;
- }
- }
- swap(this, right, storeIndex);
- return storeIndex;
- }
- };
- Object.defineProperty(Array.prototype, "partition", partition);
- Object.defineProperty(Uint32Array.prototype, "partition", partition);
- var sortRange = {
- value: function(comparator, leftBound, rightBound, k)
- {
- function quickSortFirstK(array, comparator, left, right, k)
- {
- if (right <= left)
- return;
- var pivotIndex = Math.floor(Math.random() * (right - left)) + left;
- var pivotNewIndex = array.partition(comparator, left, right, pivotIndex);
- quickSortFirstK(array, comparator, left, pivotNewIndex - 1, k);
- if (pivotNewIndex < left + k - 1)
- quickSortFirstK(array, comparator, pivotNewIndex + 1, right, k);
- }
- if (leftBound === 0 && rightBound === (this.length - 1) && k === this.length)
- this.sort(comparator);
- else
- quickSortFirstK(this, comparator, leftBound, rightBound, k);
- return this;
- }
- }
- Object.defineProperty(Array.prototype, "sortRange", sortRange);
- Object.defineProperty(Uint32Array.prototype, "sortRange", sortRange);
- })();
- Object.defineProperty(Array.prototype, "qselect",
- {
- value: function(k, comparator)
- {
- if (k < 0 || k >= this.length)
- return;
- if (!comparator)
- comparator = function(a, b) { return a - b; }
- var low = 0;
- var high = this.length - 1;
- for (;;) {
- var pivotPosition = this.partition(comparator, low, high, Math.floor((high + low) / 2));
- if (pivotPosition === k)
- return this[k];
- else if (pivotPosition > k)
- high = pivotPosition - 1;
- else
- low = pivotPosition + 1;
- }
- }
- });
- function binarySearch(object, array, comparator)
- {
- var first = 0;
- var last = array.length - 1;
- while (first <= last) {
- var mid = (first + last) >> 1;
- var c = comparator(object, array[mid]);
- if (c > 0)
- first = mid + 1;
- else if (c < 0)
- last = mid - 1;
- else
- return mid;
- }
- return -(first + 1);
- }
- Object.defineProperty(Array.prototype, "binaryIndexOf",
- {
- value: function(value, comparator)
- {
- var result = binarySearch(value, this, comparator);
- return result >= 0 ? result : -1;
- }
- });
- function insertionIndexForObjectInListSortedByFunction(anObject, aList, aFunction)
- {
- var index = binarySearch(anObject, aList, aFunction);
- if (index < 0)
- return -index - 1;
- else {
- while (index > 0 && aFunction(anObject, aList[index - 1]) === 0)
- index--;
- return index;
- }
- }
- Array.diff = function(left, right)
- {
- var o = left;
- var n = right;
- var ns = {};
- var os = {};
- for (var i = 0; i < n.length; i++) {
- if (ns[n[i]] == null)
- ns[n[i]] = { rows: [], o: null };
- ns[n[i]].rows.push(i);
- }
- for (var i = 0; i < o.length; i++) {
- if (os[o[i]] == null)
- os[o[i]] = { rows: [], n: null };
- os[o[i]].rows.push(i);
- }
- for (var i in ns) {
- if (ns[i].rows.length == 1 && typeof(os[i]) != "undefined" && os[i].rows.length == 1) {
- n[ns[i].rows[0]] = { text: n[ns[i].rows[0]], row: os[i].rows[0] };
- o[os[i].rows[0]] = { text: o[os[i].rows[0]], row: ns[i].rows[0] };
- }
- }
- for (var i = 0; i < n.length - 1; i++) {
- if (n[i].text != null && n[i + 1].text == null && n[i].row + 1 < o.length && o[n[i].row + 1].text == null && n[i + 1] == o[n[i].row + 1]) {
- n[i + 1] = { text: n[i + 1], row: n[i].row + 1 };
- o[n[i].row + 1] = { text: o[n[i].row + 1], row: i + 1 };
- }
- }
- for (var i = n.length - 1; i > 0; i--) {
- if (n[i].text != null && n[i - 1].text == null && n[i].row > 0 && o[n[i].row - 1].text == null &&
- n[i - 1] == o[n[i].row - 1]) {
- n[i - 1] = { text: n[i - 1], row: n[i].row - 1 };
- o[n[i].row - 1] = { text: o[n[i].row - 1], row: i - 1 };
- }
- }
- return { left: o, right: n };
- }
- Array.convert = function(list)
- {
- return Array.prototype.slice.call(list);
- }
- String.sprintf = function(format, var_arg)
- {
- return String.vsprintf(format, Array.prototype.slice.call(arguments, 1));
- }
- String.tokenizeFormatString = function(format, formatters)
- {
- var tokens = [];
- var substitutionIndex = 0;
- function addStringToken(str)
- {
- tokens.push({ type: "string", value: str });
- }
- function addSpecifierToken(specifier, precision, substitutionIndex)
- {
- tokens.push({ type: "specifier", specifier: specifier, precision: precision, substitutionIndex: substitutionIndex });
- }
- function isDigit(c)
- {
- return !!/[0-9]/.exec(c);
- }
- var index = 0;
- for (var precentIndex = format.indexOf("%", index); precentIndex !== -1; precentIndex = format.indexOf("%", index)) {
- addStringToken(format.substring(index, precentIndex));
- index = precentIndex + 1;
- if (isDigit(format[index])) {
- var number = parseInt(format.substring(index), 10);
- while (isDigit(format[index]))
- ++index;
- if (number > 0 && format[index] === "$") {
- substitutionIndex = (number - 1);
- ++index;
- }
- }
- var precision = -1;
- if (format[index] === ".") {
- ++index;
- precision = parseInt(format.substring(index), 10);
- if (isNaN(precision))
- precision = 0;
- while (isDigit(format[index]))
- ++index;
- }
- if (!(format[index] in formatters)) {
- addStringToken(format.substring(precentIndex, index + 1));
- ++index;
- continue;
- }
- addSpecifierToken(format[index], precision, substitutionIndex);
- ++substitutionIndex;
- ++index;
- }
- addStringToken(format.substring(index));
- return tokens;
- }
- String.standardFormatters = {
- d: function(substitution)
- {
- return !isNaN(substitution) ? substitution : 0;
- },
- f: function(substitution, token)
- {
- if (substitution && token.precision > -1)
- substitution = substitution.toFixed(token.precision);
- return !isNaN(substitution) ? substitution : (token.precision > -1 ? Number(0).toFixed(token.precision) : 0);
- },
- s: function(substitution)
- {
- return substitution;
- }
- }
- String.vsprintf = function(format, substitutions)
- {
- return String.format(format, substitutions, String.standardFormatters, "", function(a, b) { return a + b; }).formattedResult;
- }
- String.format = function(format, substitutions, formatters, initialValue, append)
- {
- if (!format || !substitutions || !substitutions.length)
- return { formattedResult: append(initialValue, format), unusedSubstitutions: substitutions };
- function prettyFunctionName()
- {
- return "String.format(\"" + format + "\", \"" + substitutions.join("\", \"") + "\")";
- }
- function warn(msg)
- {
- console.warn(prettyFunctionName() + ": " + msg);
- }
- function error(msg)
- {
- console.error(prettyFunctionName() + ": " + msg);
- }
- var result = initialValue;
- var tokens = String.tokenizeFormatString(format, formatters);
- var usedSubstitutionIndexes = {};
- for (var i = 0; i < tokens.length; ++i) {
- var token = tokens[i];
- if (token.type === "string") {
- result = append(result, token.value);
- continue;
- }
- if (token.type !== "specifier") {
- error("Unknown token type \"" + token.type + "\" found.");
- continue;
- }
- if (token.substitutionIndex >= substitutions.length) {
- error("not enough substitution arguments. Had " + substitutions.length + " but needed " + (token.substitutionIndex + 1) + ", so substitution was skipped.");
- result = append(result, "%" + (token.precision > -1 ? token.precision : "") + token.specifier);
- continue;
- }
- usedSubstitutionIndexes[token.substitutionIndex] = true;
- if (!(token.specifier in formatters)) {
- warn("unsupported format character \u201C" + token.specifier + "\u201D. Treating as a string.");
- result = append(result, substitutions[token.substitutionIndex]);
- continue;
- }
- result = append(result, formatters[token.specifier](substitutions[token.substitutionIndex], token));
- }
- var unusedSubstitutions = [];
- for (var i = 0; i < substitutions.length; ++i) {
- if (i in usedSubstitutionIndexes)
- continue;
- unusedSubstitutions.push(substitutions[i]);
- }
- return { formattedResult: result, unusedSubstitutions: unusedSubstitutions };
- }
- function createSearchRegex(query, caseSensitive, isRegex)
- {
- var regexFlags = caseSensitive ? "g" : "gi";
- var regexObject;
- if (isRegex) {
- try {
- regexObject = new RegExp(query, regexFlags);
- } catch (e) {
- }
- }
- if (!regexObject)
- regexObject = createPlainTextSearchRegex(query, regexFlags);
- return regexObject;
- }
- function createPlainTextSearchRegex(query, flags)
- {
- var regexSpecialCharacters = "[](){}+-*.,?\\^$|";
- var regex = "";
- for (var i = 0; i < query.length; ++i) {
- var c = query.charAt(i);
- if (regexSpecialCharacters.indexOf(c) != -1)
- regex += "\\";
- regex += c;
- }
- return new RegExp(regex, flags || "");
- }
- function countRegexMatches(regex, content)
- {
- var text = content;
- var result = 0;
- var match;
- while (text && (match = regex.exec(text))) {
- if (match[0].length > 0)
- ++result;
- text = text.substring(match.index + 1);
- }
- return result;
- }
- function numberToStringWithSpacesPadding(value, symbolsCount)
- {
- var numberString = value.toString();
- var paddingLength = Math.max(0, symbolsCount - numberString.length);
- var paddingString = Array(paddingLength + 1).join("\u00a0");
- return paddingString + numberString;
- }
- function TextDiff()
- {
- this.added = [];
- this.removed = [];
- this.changed = [];
- }
- TextDiff.compute = function(baseContent, newContent)
- {
- var oldLines = baseContent.split(/\r?\n/);
- var newLines = newContent.split(/\r?\n/);
- var diff = Array.diff(oldLines, newLines);
- var diffData = new TextDiff();
- var offset = 0;
- var right = diff.right;
- for (var i = 0; i < right.length; ++i) {
- if (typeof right[i] === "string") {
- if (right.length > i + 1 && right[i + 1].row === i + 1 - offset)
- diffData.changed.push(i);
- else {
- diffData.added.push(i);
- offset++;
- }
- } else
- offset = i - right[i].row;
- }
- return diffData;
- }
- var Map = function()
- {
- this._map = {};
- }
- Map._lastObjectIdentifier = 0;
- Map.prototype = {
- put: function(key, value)
- {
- var objectIdentifier = key.__identifier;
- if (!objectIdentifier) {
- objectIdentifier = ++Map._lastObjectIdentifier;
- key.__identifier = objectIdentifier;
- }
- this._map[objectIdentifier] = value;
- },
- remove: function(key)
- {
- var result = this._map[key.__identifier];
- delete this._map[key.__identifier];
- return result;
- },
- values: function()
- {
- var result = [];
- for (var objectIdentifier in this._map)
- result.push(this._map[objectIdentifier]);
- return result;
- },
- get: function(key)
- {
- return this._map[key.__identifier];
- },
- clear: function()
- {
- this._map = {};
- }
- }
- Node.prototype.rangeOfWord = function(offset, stopCharacters, stayWithinNode, direction)
- {
- var startNode;
- var startOffset = 0;
- var endNode;
- var endOffset = 0;
- if (!stayWithinNode)
- stayWithinNode = this;
- if (!direction || direction === "backward" || direction === "both") {
- var node = this;
- while (node) {
- if (node === stayWithinNode) {
- if (!startNode)
- startNode = stayWithinNode;
- break;
- }
- if (node.nodeType === Node.TEXT_NODE) {
- var start = (node === this ? (offset - 1) : (node.nodeValue.length - 1));
- for (var i = start; i >= 0; --i) {
- if (stopCharacters.indexOf(node.nodeValue[i]) !== -1) {
- startNode = node;
- startOffset = i + 1;
- break;
- }
- }
- }
- if (startNode)
- break;
- node = node.traversePreviousNode(stayWithinNode);
- }
- if (!startNode) {
- startNode = stayWithinNode;
- startOffset = 0;
- }
- } else {
- startNode = this;
- startOffset = offset;
- }
- if (!direction || direction === "forward" || direction === "both") {
- node = this;
- while (node) {
- if (node === stayWithinNode) {
- if (!endNode)
- endNode = stayWithinNode;
- break;
- }
- if (node.nodeType === Node.TEXT_NODE) {
- var start = (node === this ? offset : 0);
- for (var i = start; i < node.nodeValue.length; ++i) {
- if (stopCharacters.indexOf(node.nodeValue[i]) !== -1) {
- endNode = node;
- endOffset = i;
- break;
- }
- }
- }
- if (endNode)
- break;
- node = node.traverseNextNode(stayWithinNode);
- }
- if (!endNode) {
- endNode = stayWithinNode;
- endOffset = stayWithinNode.nodeType === Node.TEXT_NODE ? stayWithinNode.nodeValue.length : stayWithinNode.childNodes.length;
- }
- } else {
- endNode = this;
- endOffset = offset;
- }
- var result = this.ownerDocument.createRange();
- result.setStart(startNode, startOffset);
- result.setEnd(endNode, endOffset);
- return result;
- }
- Node.prototype.traverseNextTextNode = function(stayWithin)
- {
- var node = this.traverseNextNode(stayWithin);
- if (!node)
- return;
- while (node && node.nodeType !== Node.TEXT_NODE)
- node = node.traverseNextNode(stayWithin);
- return node;
- }
- Node.prototype.rangeBoundaryForOffset = function(offset)
- {
- var node = this.traverseNextTextNode(this);
- while (node && offset > node.nodeValue.length) {
- offset -= node.nodeValue.length;
- node = node.traverseNextTextNode(this);
- }
- if (!node)
- return { container: this, offset: 0 };
- return { container: node, offset: offset };
- }
- Element.prototype.removeStyleClass = function(className)
- {
- this.classList.remove(className);
- }
- Element.prototype.removeMatchingStyleClasses = function(classNameRegex)
- {
- var regex = new RegExp("(^|\\s+)" + classNameRegex + "($|\\s+)");
- if (regex.test(this.className))
- this.className = this.className.replace(regex, " ");
- }
- Element.prototype.addStyleClass = function(className)
- {
- this.classList.add(className);
- }
- Element.prototype.hasStyleClass = function(className)
- {
- return this.classList.contains(className);
- }
- Element.prototype.positionAt = function(x, y)
- {
- this.style.left = x + "px";
- this.style.top = y + "px";
- }
- Element.prototype.pruneEmptyTextNodes = function()
- {
- var sibling = this.firstChild;
- while (sibling) {
- var nextSibling = sibling.nextSibling;
- if (sibling.nodeType === this.TEXT_NODE && sibling.nodeValue === "")
- this.removeChild(sibling);
- sibling = nextSibling;
- }
- }
- Element.prototype.isScrolledToBottom = function()
- {
- return this.scrollTop + this.clientHeight === this.scrollHeight;
- }
- Node.prototype.enclosingNodeOrSelfWithNodeNameInArray = function(nameArray)
- {
- for (var node = this; node && node !== this.ownerDocument; node = node.parentNode)
- for (var i = 0; i < nameArray.length; ++i)
- if (node.nodeName.toLowerCase() === nameArray[i].toLowerCase())
- return node;
- return null;
- }
- Node.prototype.enclosingNodeOrSelfWithNodeName = function(nodeName)
- {
- return this.enclosingNodeOrSelfWithNodeNameInArray([nodeName]);
- }
- Node.prototype.enclosingNodeOrSelfWithClass = function(className)
- {
- for (var node = this; node && node !== this.ownerDocument; node = node.parentNode)
- if (node.nodeType === Node.ELEMENT_NODE && node.hasStyleClass(className))
- return node;
- return null;
- }
- Node.prototype.enclosingNodeWithClass = function(className)
- {
- if (!this.parentNode)
- return null;
- return this.parentNode.enclosingNodeOrSelfWithClass(className);
- }
- Element.prototype.query = function(query)
- {
- return this.ownerDocument.evaluate(query, this, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
- }
- Element.prototype.removeChildren = function()
- {
- if (this.firstChild)
- this.textContent = "";
- }
- Element.prototype.isInsertionCaretInside = function()
- {
- var selection = window.getSelection();
- if (!selection.rangeCount || !selection.isCollapsed)
- return false;
- var selectionRange = selection.getRangeAt(0);
- return selectionRange.startContainer.isSelfOrDescendant(this);
- }
- Element.prototype.createChild = function(elementName, className)
- {
- var element = this.ownerDocument.createElement(elementName);
- if (className)
- element.className = className;
- this.appendChild(element);
- return element;
- }
- DocumentFragment.prototype.createChild = Element.prototype.createChild;
- Element.prototype.totalOffsetLeft = function()
- {
- return this.totalOffset().left;
- }
- Element.prototype.totalOffsetTop = function()
- {
- return this.totalOffset().top;
- }
- Element.prototype.totalOffset = function()
- {
- var totalLeft = 0;
- var totalTop = 0;
- for (var element = this; element; element = element.offsetParent) {
- totalLeft += element.offsetLeft;
- totalTop += element.offsetTop;
- if (this !== element) {
- totalLeft += element.clientLeft - element.scrollLeft;
- totalTop += element.clientTop - element.scrollTop;
- }
- }
- return { left: totalLeft, top: totalTop };
- }
- Element.prototype.scrollOffset = function()
- {
- var curLeft = 0;
- var curTop = 0;
- for (var element = this; element; element = element.scrollParent) {
- curLeft += element.scrollLeft;
- curTop += element.scrollTop;
- }
- return { left: curLeft, top: curTop };
- }
- function AnchorBox(x, y, width, height)
- {
- this.x = x || 0;
- this.y = y || 0;
- this.width = width || 0;
- this.height = height || 0;
- }
- Element.prototype.offsetRelativeToWindow = function(targetWindow)
- {
- var elementOffset = new AnchorBox();
- var curElement = this;
- var curWindow = this.ownerDocument.defaultView;
- while (curWindow && curElement) {
- elementOffset.x += curElement.totalOffsetLeft();
- elementOffset.y += curElement.totalOffsetTop();
- if (curWindow === targetWindow)
- break;
- curElement = curWindow.frameElement;
- curWindow = curWindow.parent;
- }
- return elementOffset;
- }
- Element.prototype.boxInWindow = function(targetWindow)
- {
- targetWindow = targetWindow || this.ownerDocument.defaultView;
- var anchorBox = this.offsetRelativeToWindow(window);
- anchorBox.width = Math.min(this.offsetWidth, window.innerWidth - anchorBox.x);
- anchorBox.height = Math.min(this.offsetHeight, window.innerHeight - anchorBox.y);
- return anchorBox;
- }
- Element.prototype.setTextAndTitle = function(text)
- {
- this.textContent = text;
- this.title = text;
- }
- KeyboardEvent.prototype.__defineGetter__("data", function()
- {
- switch (this.type) {
- case "keypress":
- if (!this.ctrlKey && !this.metaKey)
- return String.fromCharCode(this.charCode);
- else
- return "";
- case "keydown":
- case "keyup":
- if (!this.ctrlKey && !this.metaKey && !this.altKey)
- return String.fromCharCode(this.which);
- else
- return "";
- }
- });
- Event.prototype.consume = function(preventDefault)
- {
- this.stopImmediatePropagation();
- if (preventDefault)
- this.preventDefault();
- this.handled = true;
- }
- Text.prototype.select = function(start, end)
- {
- start = start || 0;
- end = end || this.textContent.length;
- if (start < 0)
- start = end + start;
- var selection = this.ownerDocument.defaultView.getSelection();
- selection.removeAllRanges();
- var range = this.ownerDocument.createRange();
- range.setStart(this, start);
- range.setEnd(this, end);
- selection.addRange(range);
- return this;
- }
- Element.prototype.selectionLeftOffset = function()
- {
- var selection = window.getSelection();
- if (!selection.containsNode(this, true))
- return null;
- var leftOffset = selection.anchorOffset;
- var node = selection.anchorNode;
- while (node !== this) {
- while (node.previousSibling) {
- node = node.previousSibling;
- leftOffset += node.textContent.length;
- }
- node = node.parentNode;
- }
- return leftOffset;
- }
- Node.prototype.isAncestor = function(node)
- {
- if (!node)
- return false;
- var currentNode = node.parentNode;
- while (currentNode) {
- if (this === currentNode)
- return true;
- currentNode = currentNode.parentNode;
- }
- return false;
- }
- Node.prototype.isDescendant = function(descendant)
- {
- return !!descendant && descendant.isAncestor(this);
- }
- Node.prototype.isSelfOrAncestor = function(node)
- {
- return !!node && (node === this || this.isAncestor(node));
- }
- Node.prototype.isSelfOrDescendant = function(node)
- {
- return !!node && (node === this || this.isDescendant(node));
- }
- Node.prototype.traverseNextNode = function(stayWithin)
- {
- var node = this.firstChild;
- if (node)
- return node;
- if (stayWithin && this === stayWithin)
- return null;
- node = this.nextSibling;
- if (node)
- return node;
- node = this;
- while (node && !node.nextSibling && (!stayWithin || !node.parentNode || node.parentNode !== stayWithin))
- node = node.parentNode;
- if (!node)
- return null;
- return node.nextSibling;
- }
- Node.prototype.traversePreviousNode = function(stayWithin)
- {
- if (stayWithin && this === stayWithin)
- return null;
- var node = this.previousSibling;
- while (node && node.lastChild)
- node = node.lastChild;
- if (node)
- return node;
- return this.parentNode;
- }
- HTMLTextAreaElement.prototype.moveCursorToEnd = function()
- {
- var length = this.value.length;
- this.setSelectionRange(length, length);
- }
- function isEnterKey(event) {
- return event.keyCode !== 229 && event.keyIdentifier === "Enter";
- }
- function consumeEvent(e)
- {
- e.consume();
- }
- function TreeOutline(listNode, nonFocusable)
- {
- this.children = [];
- this.selectedTreeElement = null;
- this._childrenListNode = listNode;
- this.childrenListElement = this._childrenListNode;
- this._childrenListNode.removeChildren();
- this.expandTreeElementsWhenArrowing = false;
- this.root = true;
- this.hasChildren = false;
- this.expanded = true;
- this.selected = false;
- this.treeOutline = this;
- this.comparator = null;
- this.searchable = false;
- this.searchInputElement = null;
- this.setFocusable(!nonFocusable);
- this._childrenListNode.addEventListener("keydown", this._treeKeyDown.bind(this), true);
- this._childrenListNode.addEventListener("keypress", this._treeKeyPress.bind(this), true);
- this._treeElementsMap = new Map();
- this._expandedStateMap = new Map();
- }
- TreeOutline.prototype.setFocusable = function(focusable)
- {
- if (focusable)
- this._childrenListNode.setAttribute("tabIndex", 0);
- else
- this._childrenListNode.removeAttribute("tabIndex");
- }
- TreeOutline.prototype.appendChild = function(child)
- {
- var insertionIndex;
- if (this.treeOutline.comparator)
- insertionIndex = insertionIndexForObjectInListSortedByFunction(child, this.children, this.treeOutline.comparator);
- else
- insertionIndex = this.children.length;
- this.insertChild(child, insertionIndex);
- }
- TreeOutline.prototype.insertChild = function(child, index)
- {
- if (!child)
- throw("child can't be undefined or null");
- var previousChild = (index > 0 ? this.children[index - 1] : null);
- if (previousChild) {
- previousChild.nextSibling = child;
- child.previousSibling = previousChild;
- } else {
- child.previousSibling = null;
- }
- var nextChild = this.children[index];
- if (nextChild) {
- nextChild.previousSibling = child;
- child.nextSibling = nextChild;
- } else {
- child.nextSibling = null;
- }
- this.children.splice(index, 0, child);
- this.hasChildren = true;
- child.parent = this;
- child.treeOutline = this.treeOutline;
- child.treeOutline._rememberTreeElement(child);
- var current = child.children[0];
- while (current) {
- current.treeOutline = this.treeOutline;
- current.treeOutline._rememberTreeElement(current);
- current = current.traverseNextTreeElement(false, child, true);
- }
- if (child.hasChildren && typeof(child.treeOutline._expandedStateMap.get(child.representedObject)) !== "undefined")
- child.expanded = child.treeOutline._expandedStateMap.get(child.representedObject);
- if (!this._childrenListNode) {
- this._childrenListNode = this.treeOutline._childrenListNode.ownerDocument.createElement("ol");
- this._childrenListNode.parentTreeElement = this;
- this._childrenListNode.classList.add("children");
- if (this.hidden)
- this._childrenListNode.classList.add("hidden");
- }
- child._attach();
- if (this.treeOutline.onadd)
- this.treeOutline.onadd(child);
- }
- TreeOutline.prototype.removeChildAtIndex = function(childIndex)
- {
- if (childIndex < 0 || childIndex >= this.children.length)
- throw("childIndex out of range");
- var child = this.children[childIndex];
- this.children.splice(childIndex, 1);
- var parent = child.parent;
- if (child.deselect()) {
- if (child.previousSibling)
- child.previousSibling.select();
- else if (child.nextSibling)
- child.nextSibling.select();
- else
- parent.select();
- }
- if (child.previousSibling)
- child.previousSibling.nextSibling = child.nextSibling;
- if (child.nextSibling)
- child.nextSibling.previousSibling = child.previousSibling;
- if (child.treeOutline) {
- child.treeOutline._forgetTreeElement(child);
- child.treeOutline._forgetChildrenRecursive(child);
- }
- child._detach();
- child.treeOutline = null;
- child.parent = null;
- child.nextSibling = null;
- child.previousSibling = null;
- }
- TreeOutline.prototype.removeChild = function(child)
- {
- if (!child)
- throw("child can't be undefined or null");
- var childIndex = this.children.indexOf(child);
- if (childIndex === -1)
- throw("child not found in this node's children");
- this.removeChildAtIndex.call(this, childIndex);
- }
- TreeOutline.prototype.removeChildren = function()
- {
- for (var i = 0; i < this.children.length; ++i) {
- var child = this.children[i];
- child.deselect();
- if (child.treeOutline) {
- child.treeOutline._forgetTreeElement(child);
- child.treeOutline._forgetChildrenRecursive(child);
- }
- child._detach();
- child.treeOutline = null;
- child.parent = null;
- child.nextSibling = null;
- child.previousSibling = null;
- }
- this.children = [];
- }
- TreeOutline.prototype._rememberTreeElement = function(element)
- {
- if (!this._treeElementsMap.get(element.representedObject))
- this._treeElementsMap.put(element.representedObject, []);
- var elements = this._treeElementsMap.get(element.representedObject);
- if (elements.indexOf(element) !== -1)
- return;
- elements.push(element);
- }
- TreeOutline.prototype._forgetTreeElement = function(element)
- {
- if (this._treeElementsMap.get(element.representedObject))
- this._treeElementsMap.get(element.representedObject).remove(element, true);
- }
- TreeOutline.prototype._forgetChildrenRecursive = function(parentElement)
- {
- var child = parentElement.children[0];
- while (child) {
- this._forgetTreeElement(child);
- child = child.traverseNextTreeElement(false, parentElement, true);
- }
- }
- TreeOutline.prototype.getCachedTreeElement = function(representedObject)
- {
- if (!representedObject)
- return null;
- var elements = this._treeElementsMap.get(representedObject);
- if (elements && elements.length)
- return elements[0];
- return null;
- }
- TreeOutline.prototype.findTreeElement = function(representedObject, isAncestor, getParent)
- {
- if (!representedObject)
- return null;
- var cachedElement = this.getCachedTreeElement(representedObject);
- if (cachedElement)
- return cachedElement;
- var item;
- var found = false;
- for (var i = 0; i < this.children.length; ++i) {
- item = this.children[i];
- if (item.representedObject === representedObject || isAncestor(item.representedObject, representedObject)) {
- found = true;
- break;
- }
- }
- if (!found)
- return null;
- var ancestors = [];
- var currentObject = representedObject;
- while (currentObject) {
- ancestors.unshift(currentObject);
- if (currentObject === item.representedObject)
- break;
- currentObject = getParent(currentObject);
- }
- for (var i = 0; i < ancestors.length; ++i) {
- if (ancestors[i] === representedObject)
- continue;
- item = this.findTreeElement(ancestors[i], isAncestor, getParent);
- if (item)
- item.onpopulate();
- }
- return this.getCachedTreeElement(representedObject);
- }
- TreeOutline.prototype._treeElementDidChange = function(treeElement)
- {
- if (treeElement.treeOutline !== this)
- return;
- if (this.onchange)
- this.onchange(treeElement);
- }
- TreeOutline.prototype.treeElementFromPoint = function(x, y)
- {
- var node = this._childrenListNode.ownerDocument.elementFromPoint(x, y);
- if (!node)
- return null;
- var listNode = node.enclosingNodeOrSelfWithNodeNameInArray(["ol", "li"]);
- if (listNode)
- return listNode.parentTreeElement || listNode.treeElement;
- return null;
- }
- TreeOutline.prototype._treeKeyPress = function(event)
- {
- if (!this.searchable || WebInspector.isBeingEdited(this._childrenListNode))
- return;
- var searchText = String.fromCharCode(event.charCode);
- if (searchText.trim() !== searchText)
- return;
- this._startSearch(searchText);
- event.consume(true);
- }
- TreeOutline.prototype._treeKeyDown = function(event)
- {
- if (event.target !== this._childrenListNode)
- return;
- if (!this.selectedTreeElement || event.shiftKey || event.metaKey || event.ctrlKey)
- return;
- var handled = false;
- var nextSelectedElement;
- if (event.keyIdentifier === "Up" && !event.altKey) {
- nextSelectedElement = this.selectedTreeElement.traversePreviousTreeElement(true);
- while (nextSelectedElement && !nextSelectedElement.selectable)
- nextSelectedElement = nextSelectedElement.traversePreviousTreeElement(!this.expandTreeElementsWhenArrowing);
- handled = nextSelectedElement ? true : false;
- } else if (event.keyIdentifier === "Down" && !event.altKey) {
- nextSelectedElement = this.selectedTreeElement.traverseNextTreeElement(true);
- while (nextSelectedElement && !nextSelectedElement.selectable)
- nextSelectedElement = nextSelectedElement.traverseNextTreeElement(!this.expandTreeElementsWhenArrowing);
- handled = nextSelectedElement ? true : false;
- } else if (event.keyIdentifier === "Left") {
- if (this.selectedTreeElement.expanded) {
- if (event.altKey)
- this.selectedTreeElement.collapseRecursively();
- else
- this.selectedTreeElement.collapse();
- handled = true;
- } else if (this.selectedTreeElement.parent && !this.selectedTreeElement.parent.root) {
- handled = true;
- if (this.selectedTreeElement.parent.selectable) {
- nextSelectedElement = this.selectedTreeElement.parent;
- while (nextSelectedElement && !nextSelectedElement.selectable)
- nextSelectedElement = nextSelectedElement.parent;
- handled = nextSelectedElement ? true : false;
- } else if (this.selectedTreeElement.parent)
- this.selectedTreeElement.parent.collapse();
- }
- } else if (event.keyIdentifier === "Right") {
- if (!this.selectedTreeElement.revealed()) {
- this.selectedTreeElement.reveal();
- handled = true;
- } else if (this.selectedTreeElement.hasChildren) {
- handled = true;
- if (this.selectedTreeElement.expanded) {
- nextSelectedElement = this.selectedTreeElement.children[0];
- while (nextSelectedElement && !nextSelectedElement.selectable)
- nextSelectedElement = nextSelectedElement.nextSibling;
- handled = nextSelectedElement ? true : false;
- } else {
- if (event.altKey)
- this.selectedTreeElement.expandRecursively();
- else
- this.selectedTreeElement.expand();
- }
- }
- } else if (event.keyCode === 8 || event.keyCode === 46 ) {
- if (this.selectedTreeElement.ondelete)
- handled = this.selectedTreeElement.ondelete();
- } else if (isEnterKey(event)) {
- if (this.selectedTreeElement.onenter)
- handled = this.selectedTreeElement.onenter();
- } else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Space.code) {
- if (this.selectedTreeElement.onspace)
- handled = this.selectedTreeElement.onspace();
- }
- if (nextSelectedElement) {
- nextSelectedElement.reveal();
- nextSelectedElement.select(false, true);
- }
- if (handled)
- event.consume(true);
- }
- TreeOutline.prototype.expand = function()
- {
- }
- TreeOutline.prototype.collapse = function()
- {
- }
- TreeOutline.prototype.revealed = function()
- {
- return true;
- }
- TreeOutline.prototype.reveal = function()
- {
- }
- TreeOutline.prototype.select = function()
- {
- }
- TreeOutline.prototype.revealAndSelect = function(omitFocus)
- {
- }
- TreeOutline.prototype._startSearch = function(searchText)
- {
- if (!this.searchInputElement || !this.searchable)
- return;
- this._searching = true;
- if (this.searchStarted)
- this.searchStarted();
- this.searchInputElement.value = searchText;
- function focusSearchInput()
- {
- this.searchInputElement.focus();
- }
- window.setTimeout(focusSearchInput.bind(this), 0);
- this._searchTextChanged();
- this._boundSearchTextChanged = this._searchTextChanged.bind(this);
- this.searchInputElement.addEventListener("paste", this._boundSearchTextChanged);
- this.searchInputElement.addEventListener("cut", this._boundSearchTextChanged);
- this.searchInputElement.addEventListener("keypress", this._boundSearchTextChanged);
- this._boundSearchInputKeyDown = this._searchInputKeyDown.bind(this);
- this.searchInputElement.addEventListener("keydown", this._boundSearchInputKeyDown);
- this._boundSearchInputBlur = this._searchInputBlur.bind(this);
- this.searchInputElement.addEventListener("blur", this._boundSearchInputBlur);
- }
- TreeOutline.prototype._searchTextChanged = function()
- {
- function updateSearch()
- {
- var nextSelectedElement = this._nextSearchMatch(this.searchInputElement.value, this.selectedTreeElement, false);
- if (!nextSelectedElement)
- nextSelectedElement = this._nextSearchMatch(this.searchInputElement.value, this.children[0], false);
- this._showSearchMatchElement(nextSelectedElement);
- }
- window.setTimeout(updateSearch.bind(this), 0);
- }
- TreeOutline.prototype._showSearchMatchElement = function(treeElement)
- {
- this._currentSearchMatchElement = treeElement;
- if (treeElement) {
- this._childrenListNode.classList.add("search-match-found");
- this._childrenListNode.classList.remove("search-match-not-found");
- treeElement.revealAndSelect(true);
- } else {
- this._childrenListNode.classList.remove("search-match-found");
- this._childrenListNode.classList.add("search-match-not-found");
- }
- }
- TreeOutline.prototype._searchInputKeyDown = function(event)
- {
- if (event.shiftKey || event.metaKey || event.ctrlKey || event.altKey)
- return;
- var handled = false;
- var nextSelectedElement;
- if (event.keyIdentifier === "Down") {
- nextSelectedElement = this._nextSearchMatch(this.searchInputElement.value, this.selectedTreeElement, true);
- handled = true;
- } else if (event.keyIdentifier === "Up") {
- nextSelectedElement = this._previousSearchMatch(this.searchInputElement.value, this.selectedTreeElement);
- handled = true;
- } else if (event.keyCode === 27 ) {
- this._searchFinished();
- handled = true;
- } else if (isEnterKey(event)) {
- var lastSearchMatchElement = this._currentSearchMatchElement;
- this._searchFinished();
- if (lastSearchMatchElement && lastSearchMatchElement.onenter)
- lastSearchMatchElement.onenter();
- handled = true;
- }
- if (nextSelectedElement)
- this._showSearchMatchElement(nextSelectedElement);
- if (handled)
- event.consume(true);
- else
- window.setTimeout(this._boundSearchTextChanged, 0);
- }
- TreeOutline.prototype._nextSearchMatch = function(searchText, startTreeElement, skipStartTreeElement)
- {
- var currentTreeElement = startTreeElement;
- var skipCurrentTreeElement = skipStartTreeElement;
- while (currentTreeElement && (skipCurrentTreeElement || !currentTreeElement.matchesSearchText || !currentTreeElement.matchesSearchText(searchText))) {
- currentTreeElement = currentTreeElement.traverseNextTreeElement(true, null, true);
- skipCurrentTreeElement = false;
- }
- return currentTreeElement;
- }
- TreeOutline.prototype._previousSearchMatch = function(searchText, startTreeElement)
- {
- var currentTreeElement = startTreeElement;
- var skipCurrentTreeElement = true;
- while (currentTreeElement && (skipCurrentTreeElement || !currentTreeElement.matchesSearchText || !currentTreeElement.matchesSearchText(searchText))) {
- currentTreeElement = currentTreeElement.traversePreviousTreeElement(true, true);
- skipCurrentTreeElement = false;
- }
- return currentTreeElement;
- }
- TreeOutline.prototype._searchInputBlur = function(event)
- {
- this._searchFinished();
- }
- TreeOutline.prototype._searchFinished = function()
- {
- if (!this._searching)
- return;
- delete this._searching;
- this._childrenListNode.classList.remove("search-match-found");
- this._childrenListNode.classList.remove("search-match-not-found");
- delete this._currentSearchMatchElement;
- this.searchInputElement.value = "";
- this.searchInputElement.removeEventListener("paste", this._boundSearchTextChanged);
- this.searchInputElement.removeEventListener("cut", this._boundSearchTextChanged);
- delete this._boundSearchTextChanged;
- this.searchInputElement.removeEventListener("keydown", this._boundSearchInputKeyDown);
- delete this._boundSearchInputKeyDown;
- this.searchInputElement.removeEventListener("blur", this._boundSearchInputBlur);
- delete this._boundSearchInputBlur;
- if (this.searchFinished)
- this.searchFinished();
- this.treeOutline._childrenListNode.focus();
- }
- TreeOutline.prototype.stopSearch = function()
- {
- this._searchFinished();
- }
- function TreeElement(title, representedObject, hasChildren)
- {
- this._title = title;
- this.representedObject = (representedObject || {});
- this._hidden = false;
- this._selectable = true;
- this.expanded = false;
- this.selected = false;
- this.hasChildren = hasChildren;
- this.children = [];
- this.treeOutline = null;
- this.parent = null;
- this.previousSibling = null;
- this.nextSibling = null;
- this._listItemNode = null;
- }
- TreeElement.prototype = {
- arrowToggleWidth: 10,
- get selectable() {
- if (this._hidden)
- return false;
- return this._selectable;
- },
- set selectable(x) {
- this._selectable = x;
- },
- get listItemElement() {
- return this._listItemNode;
- },
- get childrenListElement() {
- return this._childrenListNode;
- },
- get title() {
- return this._title;
- },
- set title(x) {
- this._title = x;
- this._setListItemNodeContent();
- this.didChange();
- },
- get tooltip() {
- return this._tooltip;
- },
- set tooltip(x) {
- this._tooltip = x;
- if (this._listItemNode)
- this._listItemNode.title = x ? x : "";
- this.didChange();
- },
- get hasChildren() {
- return this._hasChildren;
- },
- set hasChildren(x) {
- if (this._hasChildren === x)
- return;
- this._hasChildren = x;
- if (!this._listItemNode)
- return;
- if (x)
- this._listItemNode.classList.add("parent");
- else {
- this._listItemNode.classList.remove("parent");
- this.collapse();
- }
- this.didChange();
- },
- get hidden() {
- return this._hidden;
- },
- set hidden(x) {
- if (this._hidden === x)
- return;
- this._hidden = x;
- if (x) {
- if (this._listItemNode)
- this._listItemNode.classList.add("hidden");
- if (this._childrenListNode)
- this._childrenListNode.classList.add("hidden");
- } else {
- if (this._listItemNode)
- this._listItemNode.classList.remove("hidden");
- if (this._childrenListNode)
- this._childrenListNode.classList.remove("hidden");
- }
- },
- get shouldRefreshChildren() {
- return this._shouldRefreshChildren;
- },
- set shouldRefreshChildren(x) {
- this._shouldRefreshChildren = x;
- if (x && this.expanded)
- this.expand();
- },
- _fireDidChange: function()
- {
- delete this._didChangeTimeoutIdentifier;
- if (this.treeOutline)
- this.treeOutline._treeElementDidChange(this);
- },
- didChange: function()
- {
- if (!this.treeOutline)
- return;
- if (!this._didChangeTimeoutIdentifier)
- this._didChangeTimeoutIdentifier = setTimeout(this._fireDidChange.bind(this), 0);
- },
- _setListItemNodeContent: function()
- {
- if (!this._listItemNode)
- return;
- if (typeof this._title === "string")
- this._listItemNode.textContent = this._title;
- else {
- this._listItemNode.removeChildren();
- if (this._title)
- this._listItemNode.appendChild(this._title);
- }
- }
- }
- TreeElement.prototype.appendChild = TreeOutline.prototype.appendChild;
- TreeElement.prototype.insertChild = TreeOutline.prototype.insertChild;
- TreeElement.prototype.removeChild = TreeOutline.prototype.removeChild;
- TreeElement.prototype.removeChildAtIndex = TreeOutline.prototype.removeChildAtIndex;
- TreeElement.prototype.removeChildren = TreeOutline.prototype.removeChildren;
- TreeElement.prototype._attach = function()
- {
- if (!this._listItemNode || this.parent._shouldRefreshChildren) {
- if (this._listItemNode && this._listItemNode.parentNode)
- this._listItemNode.parentNode.removeChild(this._listItemNode);
- this._listItemNode = this.treeOutline._childrenListNode.ownerDocument.createElement("li");
- this._listItemNode.treeElement = this;
- this._setListItemNodeContent();
- this._listItemNode.title = this._tooltip ? this._tooltip : "";
- if (this.hidden)
- this._listItemNode.classList.add("hidden");
- if (this.hasChildren)
- this._listItemNode.classList.add("parent");
- if (this.expanded)
- this._listItemNode.classList.add("expanded");
- if (this.selected)
- this._listItemNode.classList.add("selected");
- this._listItemNode.addEventListener("mousedown", TreeElement.treeElementMouseDown, false);
- this._listItemNode.addEventListener("click", TreeElement.treeElementToggled, false);
- this._listItemNode.addEventListener("dblclick", TreeElement.treeElementDoubleClicked, false);
- if (this.onattach)
- this.onattach(this);
- }
- var nextSibling = null;
- if (this.nextSibling && this.nextSibling._listItemNode && this.nextSibling._listItemNode.parentNode === this.parent._childrenListNode)
- nextSibling = this.nextSibling._listItemNode;
- this.parent._childrenListNode.insertBefore(this._listItemNode, nextSibling);
- if (this._childrenListNode)
- this.parent._childrenListNode.insertBefore(this._childrenListNode, this._listItemNode.nextSibling);
- if (this.selected)
- this.select();
- if (this.expanded)
- this.expand();
- }
- TreeElement.prototype._detach = function()
- {
- if (this._listItemNode && this._listItemNode.parentNode)
- this._listItemNode.parentNode.removeChild(this._listItemNode);
- if (this._childrenListNode && this._childrenListNode.parentNode)
- this._childrenListNode.parentNode.removeChild(this._childrenListNode);
- }
- TreeElement.treeElementMouseDown = function(event)
- {
- var element = event.currentTarget;
- if (!element || !element.treeElement || !element.treeElement.selectable)
- return;
- if (element.treeElement.isEventWithinDisclosureTriangle(event))
- return;
- element.treeElement.selectOnMouseDown(event);
- }
- TreeElement.treeElementToggled = function(event)
- {
- var element = event.currentTarget;
- if (!element || !element.treeElement)
- return;
- var toggleOnClick = element.treeElement.toggleOnClick && !element.treeElement.selectable;
- var isInTriangle = element.treeElement.isEventWithinDisclosureTriangle(event);
- if (!toggleOnClick && !isInTriangle)
- return;
- if (element.treeElement.expanded) {
- if (event.altKey)
- element.treeElement.collapseRecursively();
- else
- element.treeElement.collapse();
- } else {
- if (event.altKey)
- element.treeElement.expandRecursively();
- else
- element.treeElement.expand();
- }
- event.consume();
- }
- TreeElement.treeElementDoubleClicked = function(event)
- {
- var element = event.currentTarget;
- if (!element || !element.treeElement)
- return;
- if (element.treeElement.ondblclick) {
- var handled = element.treeElement.ondblclick.call(element.treeElement, event);
- if (handled)
- return;
- } else if (element.treeElement.hasChildren && !element.treeElement.expanded)
- element.treeElement.expand();
- }
- TreeElement.prototype.collapse = function()
- {
- if (this._listItemNode)
- this._listItemNode.classList.remove("expanded");
- if (this._childrenListNode)
- this._childrenListNode.classList.remove("expanded");
- this.expanded = false;
- if (this.treeOutline)
- this.treeOutline._expandedStateMap.put(this.representedObject, false);
- if (this.oncollapse)
- this.oncollapse(this);
- }
- TreeElement.prototype.collapseRecursively = function()
- {
- var item = this;
- while (item) {
- if (item.expanded)
- item.collapse();
- item = item.traverseNextTreeElement(false, this, true);
- }
- }
- TreeElement.prototype.expand = function()
- {
- if (!this.hasChildren || (this.expanded && !this._shouldRefreshChildren && this._childrenListNode))
- return;
- this.expanded = true;
- if (this.treeOutline)
- this.treeOutline._expandedStateMap.put(this.representedObject, true);
- if (this.treeOutline && (!this._childrenListNode || this._shouldRefreshChildren)) {
- if (this._childrenListNode && this._childrenListNode.parentNode)
- this._childrenListNode.parentNode.removeChild(this._childrenListNode);
- this._childrenListNode = this.treeOutline._childrenListNode.ownerDocument.createElement("ol");
- this._childrenListNode.parentTreeElement = this;
- this._childrenListNode.classList.add("children");
- if (this.hidden)
- this._childrenListNode.classList.add("hidden");
- this.onpopulate();
- for (var i = 0; i < this.children.length; ++i)
- this.children[i]._attach();
- delete this._shouldRefreshChildren;
- }
- if (this._listItemNode) {
- this._listItemNode.classList.add("expanded");
- if (this._childrenListNode && this._childrenListNode.parentNode != this._listItemNode.parentNode)
- this.parent._childrenListNode.insertBefore(this._childrenListNode, this._listItemNode.nextSibling);
- }
- if (this._childrenListNode)
- this._childrenListNode.classList.add("expanded");
- if (this.onexpand)
- this.onexpand(this);
- }
- TreeElement.prototype.expandRecursively = function(maxDepth)
- {
- var item = this;
- var info = {};
- var depth = 0;
- if (typeof maxDepth === "undefined" || typeof maxDepth === "null")
- maxDepth = 3;
- while (item) {
- if (depth < maxDepth)
- item.expand();
- item = item.traverseNextTreeElement(false, this, (depth >= maxDepth), info);
- depth += info.depthChange;
- }
- }
- TreeElement.prototype.hasAncestor = function(ancestor) {
- if (!ancestor)
- return false;
- var currentNode = this.parent;
- while (currentNode) {
- if (ancestor === currentNode)
- return true;
- currentNode = currentNode.parent;
- }
- return false;
- }
- TreeElement.prototype.reveal = function()
- {
- var currentAncestor = this.parent;
- while (currentAncestor && !currentAncestor.root) {
- if (!currentAncestor.expanded)
- currentAncestor.expand();
- currentAncestor = currentAncestor.parent;
- }
- if (this.onreveal)
- this.onreveal(this);
- }
- TreeElement.prototype.revealed = function()
- {
- var currentAncestor = this.parent;
- while (currentAncestor && !currentAncestor.root) {
- if (!currentAncestor.expanded)
- return false;
- currentAncestor = currentAncestor.parent;
- }
- return true;
- }
- TreeElement.prototype.selectOnMouseDown = function(event)
- {
- if (this.select(false, true))
- event.consume(true);
- }
- TreeElement.prototype.select = function(omitFocus, selectedByUser)
- {
- if (!this.treeOutline || !this.selectable || this.selected)
- return false;
- if (this.treeOutline.selectedTreeElement)
- this.treeOutline.selectedTreeElement.deselect();
- this.selected = true;
- if(!omitFocus)
- this.treeOutline._childrenListNode.focus();
- if (!this.treeOutline)
- return false;
- this.treeOutline.selectedTreeElement = this;
- if (this._listItemNode)
- this._listItemNode.classList.add("selected");
- if (this.onselect)
- return this.onselect(this, selectedByUser);
- return false;
- }
- TreeElement.prototype.revealAndSelect = function(omitFocus)
- {
- this.reveal();
- this.select(omitFocus);
- }
- TreeElement.prototype.deselect = function(supressOnDeselect)
- {
- if (!this.treeOutline || this.treeOutline.selectedTreeElement !== this || !this.selected)
- return false;
- this.selected = false;
- this.treeOutline.selectedTreeElement = null;
- if (this._listItemNode)
- this._listItemNode.classList.remove("selected");
- if (this.ondeselect && !supressOnDeselect)
- this.ondeselect(this);
- return true;
- }
- TreeElement.prototype.onpopulate = function()
- {
- }
- TreeElement.prototype.traverseNextTreeElement = function(skipUnrevealed, stayWithin, dontPopulate, info)
- {
- if (!dontPopulate && this.hasChildren)
- this.onpopulate();
- if (info)
- info.depthChange = 0;
- var element = skipUnrevealed ? (this.revealed() ? this.children[0] : null) : this.children[0];
- if (element && (!skipUnrevealed || (skipUnrevealed && this.expanded))) {
- if (info)
- info.depthChange = 1;
- return element;
- }
- if (this === stayWithin)
- return null;
- element = skipUnrevealed ? (this.revealed() ? this.nextSibling : null) : this.nextSibling;
- if (element)
- return element;
- element = this;
- while (element && !element.root && !(skipUnrevealed ? (element.revealed() ? element.nextSibling : null) : element.nextSibling) && element.parent !== stayWithin) {
- if (info)
- info.depthChange -= 1;
- element = element.parent;
- }
- if (!element)
- return null;
- return (skipUnrevealed ? (element.revealed() ? element.nextSibling : null) : element.nextSibling);
- }
- TreeElement.prototype.traversePreviousTreeElement = function(skipUnrevealed, dontPopulate)
- {
- var element = skipUnrevealed ? (this.revealed() ? this.previousSibling : null) : this.previousSibling;
- if (!dontPopulate && element && element.hasChildren)
- element.onpopulate();
- while (element && (skipUnrevealed ? (element.revealed() && element.expanded ? element.children[element.children.length - 1] : null) : element.children[element.children.length - 1])) {
- if (!dontPopulate && element.hasChildren)
- element.onpopulate();
- element = (skipUnrevealed ? (element.revealed() && element.expanded ? element.children[element.children.length - 1] : null) : element.childre…
Large files files are truncated, but you can click here to view the full file