⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 treeoutline.js

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 JS
📖 第 1 页 / 共 2 页
字号:
        this.identifier = TreeOutline._knownTreeElementNextIdentifier++;        this.representedObject.__treeElementIdentifier = this.identifier;    }    this._hidden = false;    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 = {    selectable: true,    arrowToggleWidth: 10,    get listItemElement() {        return this._listItemNode;    },    get childrenListElement() {        return this._childrenListNode;    },    get title() {        return this._title;    },    set title(x) {        this._title = x;        if (this._listItemNode)            this._listItemNode.innerHTML = x;    },    get tooltip() {        return this._tooltip;    },    set tooltip(x) {        this._tooltip = x;        if (this._listItemNode)            this._listItemNode.title = x ? x : "";    },    get hasChildren() {        return this._hasChildren;    },    set hasChildren(x) {        if (this._hasChildren === x)            return;        this._hasChildren = x;        if (!this._listItemNode)            return;        if (x)            this._listItemNode.addStyleClass("parent");        else {            this._listItemNode.removeStyleClass("parent");            this.collapse();        }    },    get hidden() {        return this._hidden;    },    set hidden(x) {        if (this._hidden === x)            return;        this._hidden = x;        if (x) {            if (this._listItemNode)                this._listItemNode.addStyleClass("hidden");            if (this._childrenListNode)                this._childrenListNode.addStyleClass("hidden");        } else {            if (this._listItemNode)                this._listItemNode.removeStyleClass("hidden");            if (this._childrenListNode)                this._childrenListNode.removeStyleClass("hidden");        }    },    get shouldRefreshChildren() {        return this._shouldRefreshChildren;    },    set shouldRefreshChildren(x) {        this._shouldRefreshChildren = x;        if (x && this.expanded)            this.expand();    }}TreeElement.prototype.appendChild = TreeOutline._appendChild;TreeElement.prototype.insertChild = TreeOutline._insertChild;TreeElement.prototype.removeChild = TreeOutline._removeChild;TreeElement.prototype.removeChildAtIndex = TreeOutline._removeChildAtIndex;TreeElement.prototype.removeChildren = TreeOutline._removeChildren;TreeElement.prototype.removeChildrenRecursive = TreeOutline._removeChildrenRecursive;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._listItemNode.innerHTML = this._title;        this._listItemNode.title = this._tooltip ? this._tooltip : "";        if (this.hidden)            this._listItemNode.addStyleClass("hidden");        if (this.hasChildren)            this._listItemNode.addStyleClass("parent");        if (this.expanded)            this._listItemNode.addStyleClass("expanded");        if (this.selected)            this._listItemNode.addStyleClass("selected");        this._listItemNode.addEventListener("mousedown", TreeElement.treeElementSelected, 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.treeElementSelected = function(event){    var element = event.currentTarget;    if (!element || !element.treeElement || !element.treeElement.selectable)        return;    if (element.treeElement.isEventWithinDisclosureTriangle(event))        return;    element.treeElement.select();}TreeElement.treeElementToggled = function(event){    var element = event.currentTarget;    if (!element || !element.treeElement)        return;    if (!element.treeElement.isEventWithinDisclosureTriangle(event))        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();    }}TreeElement.treeElementDoubleClicked = function(event){    var element = event.currentTarget;    if (!element || !element.treeElement)        return;    if (element.treeElement.ondblclick)        element.treeElement.ondblclick(element.treeElement, event);    else if (element.treeElement.hasChildren && !element.treeElement.expanded)        element.treeElement.expand();}TreeElement.prototype.collapse = function(){    if (this._listItemNode)        this._listItemNode.removeStyleClass("expanded");    if (this._childrenListNode)        this._childrenListNode.removeStyleClass("expanded");    this.expanded = false;    if (this.treeOutline)        this.treeOutline._treeElementsExpandedState[this.identifier] = true;    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;    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.addStyleClass("children");        if (this.hidden)            this._childrenListNode.addStyleClass("hidden");        if (this.onpopulate)            this.onpopulate(this);        for (var i = 0; i < this.children.length; ++i)            this.children[i]._attach();        delete this._shouldRefreshChildren;    }    if (this._listItemNode) {        this._listItemNode.addStyleClass("expanded");        if (this._childrenListNode && this._childrenListNode.parentNode != this._listItemNode.parentNode)            this.parent._childrenListNode.insertBefore(this._childrenListNode, this._listItemNode.nextSibling);    }    if (this._childrenListNode)        this._childrenListNode.addStyleClass("expanded");    this.expanded = true;    if (this.treeOutline)        this.treeOutline._treeElementsExpandedState[this.identifier] = true;    if (this.onexpand)        this.onexpand(this);}TreeElement.prototype.expandRecursively = function(maxDepth){    var item = this;    var info = {};    var depth = 0;    // The Inspector uses TreeOutlines to represents object properties, so recursive expansion    // in some case can be infinite, since JavaScript objects can hold circular references.    // So default to a recursion cap of 3 levels, since that gives fairly good results.    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.select = function(supressOnSelect){    if (!this.treeOutline || !this.selectable || this.selected)        return;    if (this.treeOutline.selectedTreeElement)        this.treeOutline.selectedTreeElement.deselect();    this.selected = true;    this.treeOutline.selectedTreeElement = this;    if (this._listItemNode)        this._listItemNode.addStyleClass("selected");    if (this.onselect && !supressOnSelect)        this.onselect(this);}TreeElement.prototype.deselect = function(supressOnDeselect){    if (!this.treeOutline || this.treeOutline.selectedTreeElement !== this || !this.selected)        return;    this.selected = false;    this.treeOutline.selectedTreeElement = null;    if (this._listItemNode)        this._listItemNode.removeStyleClass("selected");    if (this.ondeselect && !supressOnDeselect)        this.ondeselect(this);}TreeElement.prototype.traverseNextTreeElement = function(skipHidden, stayWithin, dontPopulate, info){    if (!dontPopulate && this.hasChildren && this.onpopulate)        this.onpopulate(this);    if (info)        info.depthChange = 0;    var element = skipHidden ? (this.revealed() ? this.children[0] : null) : this.children[0];    if (element && (!skipHidden || (skipHidden && this.expanded))) {        if (info)            info.depthChange = 1;        return element;    }    if (this === stayWithin)        return null;    element = skipHidden ? (this.revealed() ? this.nextSibling : null) : this.nextSibling;    if (element)        return element;    element = this;    while (element && !element.root && !(skipHidden ? (element.revealed() ? element.nextSibling : null) : element.nextSibling) && element.parent !== stayWithin) {        if (info)            info.depthChange -= 1;        element = element.parent;    }    if (!element)        return null;    return (skipHidden ? (element.revealed() ? element.nextSibling : null) : element.nextSibling);}TreeElement.prototype.traversePreviousTreeElement = function(skipHidden, dontPopulate){    var element = skipHidden ? (this.revealed() ? this.previousSibling : null) : this.previousSibling;    if (!dontPopulate && element && element.hasChildren && element.onpopulate)        element.onpopulate(element);    while (element && (skipHidden ? (element.revealed() && element.expanded ? element.children[element.children.length - 1] : null) : element.children[element.children.length - 1])) {        if (!dontPopulate && element.hasChildren && element.onpopulate)            element.onpopulate(element);        element = (skipHidden ? (element.revealed() && element.expanded ? element.children[element.children.length - 1] : null) : element.children[element.children.length - 1]);    }    if (element)        return element;    if (!this.parent || this.parent.root)        return null;    return this.parent;}TreeElement.prototype.isEventWithinDisclosureTriangle = function(event){    var left = this._listItemNode.totalOffsetLeft;    return event.pageX >= left && event.pageX <= left + this.arrowToggleWidth && this.hasChildren;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -