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

📄 elementspanel.js

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 JS
📖 第 1 页 / 共 3 页
字号:
                                    classesElement.appendChild(document.createTextNode(part));                                    foundClasses[className] = true;                                }                            }                        }                    }                    break;                case Node.TEXT_NODE:                    if (isNodeWhitespace.call(current))                        crumbTitle = WebInspector.UIString("(whitespace)");                    else                        crumbTitle = WebInspector.UIString("(text)");                    break                case Node.COMMENT_NODE:                    crumbTitle = "<!-->";                    break;                case Node.DOCUMENT_TYPE_NODE:                    crumbTitle = "<!DOCTYPE>";                    break;                default:                    crumbTitle = current.nodeName.toLowerCase();            }            if (!crumb.childNodes.length) {                var nameElement = document.createElement("span");                nameElement.textContent = crumbTitle;                crumb.appendChild(nameElement);            }            crumb.title = crumbTitle;            if (foundRoot)                crumb.addStyleClass("dimmed");            if (objectsAreSame(current, this.focusedDOMNode))                crumb.addStyleClass("selected");            if (!crumbs.childNodes.length)                crumb.addStyleClass("end");            crumbs.appendChild(crumb);        }        if (crumbs.hasChildNodes())            crumbs.lastChild.addStyleClass("start");        this.updateBreadcrumbSizes();    },    updateBreadcrumbSizes: function(focusedCrumb)    {        if (!this.visible)            return;        if (document.body.offsetWidth <= 0) {            // The stylesheet hasn't loaded yet or the window is closed,            // so we can't calculate what is need. Return early.            return;        }        var crumbs = this.crumbsElement;        if (!crumbs.childNodes.length || crumbs.offsetWidth <= 0)            return; // No crumbs, do nothing.        // A Zero index is the right most child crumb in the breadcrumb.        var selectedIndex = 0;        var focusedIndex = 0;        var selectedCrumb;        var i = 0;        var crumb = crumbs.firstChild;        while (crumb) {            // Find the selected crumb and index.             if (!selectedCrumb && crumb.hasStyleClass("selected")) {                selectedCrumb = crumb;                selectedIndex = i;            }            // Find the focused crumb index.             if (crumb === focusedCrumb)                focusedIndex = i;            // Remove any styles that affect size before            // deciding to shorten any crumbs.            if (crumb !== crumbs.lastChild)                crumb.removeStyleClass("start");            if (crumb !== crumbs.firstChild)                crumb.removeStyleClass("end");            crumb.removeStyleClass("compact");            crumb.removeStyleClass("collapsed");            crumb.removeStyleClass("hidden");            crumb = crumb.nextSibling;            ++i;        }        // Restore the start and end crumb classes in case they got removed in coalesceCollapsedCrumbs().        // The order of the crumbs in the document is opposite of the visual order.        crumbs.firstChild.addStyleClass("end");        crumbs.lastChild.addStyleClass("start");        function crumbsAreSmallerThanContainer()        {            var rightPadding = 20;            var errorWarningElement = document.getElementById("error-warning-count");            if (!WebInspector.console.visible && errorWarningElement)                rightPadding += errorWarningElement.offsetWidth;            return ((crumbs.totalOffsetLeft + crumbs.offsetWidth + rightPadding) < window.innerWidth);        }        if (crumbsAreSmallerThanContainer())            return; // No need to compact the crumbs, they all fit at full size.        var BothSides = 0;        var AncestorSide = -1;        var ChildSide = 1;        function makeCrumbsSmaller(shrinkingFunction, direction, significantCrumb)        {            if (!significantCrumb)                significantCrumb = (focusedCrumb || selectedCrumb);            if (significantCrumb === selectedCrumb)                var significantIndex = selectedIndex;            else if (significantCrumb === focusedCrumb)                var significantIndex = focusedIndex;            else {                var significantIndex = 0;                for (var i = 0; i < crumbs.childNodes.length; ++i) {                    if (crumbs.childNodes[i] === significantCrumb) {                        significantIndex = i;                        break;                    }                }            }            function shrinkCrumbAtIndex(index)            {                var shrinkCrumb = crumbs.childNodes[index];                if (shrinkCrumb && shrinkCrumb !== significantCrumb)                    shrinkingFunction(shrinkCrumb);                if (crumbsAreSmallerThanContainer())                    return true; // No need to compact the crumbs more.                return false;            }            // Shrink crumbs one at a time by applying the shrinkingFunction until the crumbs            // fit in the container or we run out of crumbs to shrink.            if (direction) {                // Crumbs are shrunk on only one side (based on direction) of the signifcant crumb.                var index = (direction > 0 ? 0 : crumbs.childNodes.length - 1);                while (index !== significantIndex) {                    if (shrinkCrumbAtIndex(index))                        return true;                    index += (direction > 0 ? 1 : -1);                }            } else {                // Crumbs are shrunk in order of descending distance from the signifcant crumb,                // with a tie going to child crumbs.                var startIndex = 0;                var endIndex = crumbs.childNodes.length - 1;                while (startIndex != significantIndex || endIndex != significantIndex) {                    var startDistance = significantIndex - startIndex;                    var endDistance = endIndex - significantIndex;                    if (startDistance >= endDistance)                        var index = startIndex++;                    else                        var index = endIndex--;                    if (shrinkCrumbAtIndex(index))                        return true;                }            }            // We are not small enough yet, return false so the caller knows.            return false;        }        function coalesceCollapsedCrumbs()        {            var crumb = crumbs.firstChild;            var collapsedRun = false;            var newStartNeeded = false;            var newEndNeeded = false;            while (crumb) {                var hidden = crumb.hasStyleClass("hidden");                if (!hidden) {                    var collapsed = crumb.hasStyleClass("collapsed");                     if (collapsedRun && collapsed) {                        crumb.addStyleClass("hidden");                        crumb.removeStyleClass("compact");                        crumb.removeStyleClass("collapsed");                        if (crumb.hasStyleClass("start")) {                            crumb.removeStyleClass("start");                            newStartNeeded = true;                        }                        if (crumb.hasStyleClass("end")) {                            crumb.removeStyleClass("end");                            newEndNeeded = true;                        }                        continue;                    }                    collapsedRun = collapsed;                    if (newEndNeeded) {                        newEndNeeded = false;                        crumb.addStyleClass("end");                    }                } else                    collapsedRun = true;                crumb = crumb.nextSibling;            }            if (newStartNeeded) {                crumb = crumbs.lastChild;                while (crumb) {                    if (!crumb.hasStyleClass("hidden")) {                        crumb.addStyleClass("start");                        break;                    }                    crumb = crumb.previousSibling;                }            }        }        function compact(crumb)        {            if (crumb.hasStyleClass("hidden"))                return;            crumb.addStyleClass("compact");        }        function collapse(crumb, dontCoalesce)        {            if (crumb.hasStyleClass("hidden"))                return;            crumb.addStyleClass("collapsed");            crumb.removeStyleClass("compact");            if (!dontCoalesce)                coalesceCollapsedCrumbs();        }        function compactDimmed(crumb)        {            if (crumb.hasStyleClass("dimmed"))                compact(crumb);        }        function collapseDimmed(crumb)        {            if (crumb.hasStyleClass("dimmed"))                collapse(crumb);        }        if (!focusedCrumb) {            // When not focused on a crumb we can be biased and collapse less important            // crumbs that the user might not care much about.            // Compact child crumbs.            if (makeCrumbsSmaller(compact, ChildSide))                return;            // Collapse child crumbs.            if (makeCrumbsSmaller(collapse, ChildSide))                return;            // Compact dimmed ancestor crumbs.            if (makeCrumbsSmaller(compactDimmed, AncestorSide))                return;            // Collapse dimmed ancestor crumbs.            if (makeCrumbsSmaller(collapseDimmed, AncestorSide))                return;        }        // Compact ancestor crumbs, or from both sides if focused.        if (makeCrumbsSmaller(compact, (focusedCrumb ? BothSides : AncestorSide)))            return;        // Collapse ancestor crumbs, or from both sides if focused.        if (makeCrumbsSmaller(collapse, (focusedCrumb ? BothSides : AncestorSide)))            return;        if (!selectedCrumb)            return;        // Compact the selected crumb.        compact(selectedCrumb);        if (crumbsAreSmallerThanContainer())            return;        // Collapse the selected crumb as a last resort. Pass true to prevent coalescing.        collapse(selectedCrumb, true);    },    updateStyles: function(forceUpdate)    {        var stylesSidebarPane = this.sidebarPanes.styles;        if (!stylesSidebarPane.expanded || !stylesSidebarPane.needsUpdate)            return;        stylesSidebarPane.update(this.focusedDOMNode, null, forceUpdate);        stylesSidebarPane.needsUpdate = false;    },    updateMetrics: function()    {        var metricsSidebarPane = this.sidebarPanes.metrics;        if (!metricsSidebarPane.expanded || !metricsSidebarPane.needsUpdate)            return;        metricsSidebarPane.update(this.focusedDOMNode);        metricsSidebarPane.needsUpdate = false;    },    updateProperties: function()    {        var propertiesSidebarPane = this.sidebarPanes.properties;        if (!propertiesSidebarPane.expanded || !propertiesSidebarPane.needsUpdate)            return;        propertiesSidebarPane.update(this.focusedDOMNode);        propertiesSidebarPane.needsUpdate = false;    },    handleKeyEvent: function(event)    {        this.treeOutline.handleKeyEvent(event);    },    handleCopyEvent: function(event)    {        // Don't prevent the normal copy if the user has a selection.        if (!window.getSelection().isCollapsed)            return;        switch (this.focusedDOMNode.nodeType) {            case Node.ELEMENT_NODE:                var data = this.focusedDOMNode.outerHTML;                break;            case Node.COMMENT_NODE:                var data = "<!--" + this.focusedDOMNode.nodeValue + "-->";                break;            default:            case Node.TEXT_NODE:                var data = this.focusedDOMNode.nodeValue;        }        event.clipboardData.clearData();        event.preventDefault();        if (data)            event.clipboardData.setData("text/plain", data);    },    rightSidebarResizerDragStart: function(event)    {        WebInspector.elementDragStart(this.sidebarElement, this.rightSidebarResizerDrag.bind(this), this.rightSidebarResizerDragEnd.bind(this), event, "col-resize");    },    rightSidebarResizerDragEnd: function(event)    {        WebInspector.elementDragEnd(event);    },    rightSidebarResizerDrag: function(event)    {        var x = event.pageX;        var newWidth = Number.constrain(window.innerWidth - x, Preferences.minElementsSidebarWidth, window.innerWidth * 0.66);        this.sidebarElement.style.width = newWidth + "px";        this.contentElement.style.right = newWidth + "px";        this.sidebarResizeElement.style.right = (newWidth - 3) + "px";        this.treeOutline.updateSelection();        event.preventDefault();    },    _nodeSearchButtonClicked: function(event)    {        InspectorController.toggleNodeSearch();        if (InspectorController.searchingForNode())            this.nodeSearchButton.addStyleClass("toggled-on");        else            this.nodeSearchButton.removeStyleClass("toggled-on");    }}WebInspector.ElementsPanel.prototype.__proto__ = WebInspector.Panel.prototype;

⌨️ 快捷键说明

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