📄 inspector.js
字号:
/* * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com). * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */var Preferences = { ignoreWhitespace: true, showUserAgentStyles: true, maxInlineTextChildLength: 80, minConsoleHeight: 75, minSidebarWidth: 100, minElementsSidebarWidth: 200, minScriptsSidebarWidth: 200, showInheritedComputedStyleProperties: false, styleRulesExpandedState: {}, showMissingLocalizedStrings: false}var WebInspector = { resources: [], resourceURLMap: {}, missingLocalizedStrings: {}, get previousFocusElement() { return this._previousFocusElement; }, get currentFocusElement() { return this._currentFocusElement; }, set currentFocusElement(x) { if (this._currentFocusElement !== x) this._previousFocusElement = this._currentFocusElement; this._currentFocusElement = x; if (this._currentFocusElement) { this._currentFocusElement.focus(); // Make a caret selection inside the new element if there isn't a range selection and // there isn't already a caret selection inside. var selection = window.getSelection(); if (selection.isCollapsed && !this._currentFocusElement.isInsertionCaretInside()) { var selectionRange = document.createRange(); selectionRange.setStart(this._currentFocusElement, 0); selectionRange.setEnd(this._currentFocusElement, 0); selection.removeAllRanges(); selection.addRange(selectionRange); } } else if (this._previousFocusElement) this._previousFocusElement.blur(); }, get currentPanel() { return this._currentPanel; }, set currentPanel(x) { if (this._currentPanel === x) return; if (this._currentPanel) this._currentPanel.hide(); this._currentPanel = x; this.updateSearchLabel(); if (x) { x.show(); if (this.currentQuery) { if (x.performSearch) { function performPanelSearch() { this.updateSearchMatchesCount(); x.currentQuery = this.currentQuery; x.performSearch(this.currentQuery); } // Perform the search on a timeout so the panel switches fast. setTimeout(performPanelSearch.bind(this), 0); } else { // Update to show Not found for panels that can't be searched. this.updateSearchMatchesCount(); } } } }, get attached() { return this._attached; }, set attached(x) { if (this._attached === x) return; this._attached = x; this.updateSearchLabel(); var dockToggleButton = document.getElementById("dock-status-bar-item"); var body = document.body; if (x) { InspectorController.attach(); body.removeStyleClass("detached"); body.addStyleClass("attached"); dockToggleButton.title = WebInspector.UIString("Undock into separate window."); } else { InspectorController.detach(); body.removeStyleClass("attached"); body.addStyleClass("detached"); dockToggleButton.title = WebInspector.UIString("Dock to main window."); } }, get errors() { return this._errors || 0; }, set errors(x) { x = Math.max(x, 0); if (this._errors === x) return; this._errors = x; this._updateErrorAndWarningCounts(); }, get warnings() { return this._warnings || 0; }, set warnings(x) { x = Math.max(x, 0); if (this._warnings === x) return; this._warnings = x; this._updateErrorAndWarningCounts(); }, _updateErrorAndWarningCounts: function() { var errorWarningElement = document.getElementById("error-warning-count"); if (!errorWarningElement) return; if (!this.errors && !this.warnings) { errorWarningElement.addStyleClass("hidden"); return; } errorWarningElement.removeStyleClass("hidden"); errorWarningElement.removeChildren(); if (this.errors) { var errorElement = document.createElement("span"); errorElement.id = "error-count"; errorElement.textContent = this.errors; errorWarningElement.appendChild(errorElement); } if (this.warnings) { var warningsElement = document.createElement("span"); warningsElement.id = "warning-count"; warningsElement.textContent = this.warnings; errorWarningElement.appendChild(warningsElement); } if (this.errors) { if (this.warnings) { if (this.errors == 1) { if (this.warnings == 1) errorWarningElement.title = WebInspector.UIString("%d error, %d warning", this.errors, this.warnings); else errorWarningElement.title = WebInspector.UIString("%d error, %d warnings", this.errors, this.warnings); } else if (this.warnings == 1) errorWarningElement.title = WebInspector.UIString("%d errors, %d warning", this.errors, this.warnings); else errorWarningElement.title = WebInspector.UIString("%d errors, %d warnings", this.errors, this.warnings); } else if (this.errors == 1) errorWarningElement.title = WebInspector.UIString("%d error", this.errors); else errorWarningElement.title = WebInspector.UIString("%d errors", this.errors); } else if (this.warnings == 1) errorWarningElement.title = WebInspector.UIString("%d warning", this.warnings); else if (this.warnings) errorWarningElement.title = WebInspector.UIString("%d warnings", this.warnings); else errorWarningElement.title = null; }, get hoveredDOMNode() { return this._hoveredDOMNode; }, set hoveredDOMNode(x) { if (objectsAreSame(this._hoveredDOMNode, x)) return; this._hoveredDOMNode = x; if (this._hoveredDOMNode) this._updateHoverHighlightSoon(this.showingDOMNodeHighlight ? 50 : 500); else this._updateHoverHighlight(); }, _updateHoverHighlightSoon: function(delay) { if ("_updateHoverHighlightTimeout" in this) clearTimeout(this._updateHoverHighlightTimeout); this._updateHoverHighlightTimeout = setTimeout(this._updateHoverHighlight.bind(this), delay); }, _updateHoverHighlight: function() { if ("_updateHoverHighlightTimeout" in this) { clearTimeout(this._updateHoverHighlightTimeout); delete this._updateHoverHighlightTimeout; } if (this._hoveredDOMNode) { InspectorController.highlightDOMNode(this._hoveredDOMNode); this.showingDOMNodeHighlight = true; } else { InspectorController.hideDOMNodeHighlight(); this.showingDOMNodeHighlight = false; } }}WebInspector.loaded = function(){ var platform = InspectorController.platform(); document.body.addStyleClass("platform-" + platform); this.console = new WebInspector.Console(); this.panels = { elements: new WebInspector.ElementsPanel(), resources: new WebInspector.ResourcesPanel(), scripts: new WebInspector.ScriptsPanel(), profiles: new WebInspector.ProfilesPanel(), databases: new WebInspector.DatabasesPanel() }; var hiddenPanels = (InspectorController.hiddenPanels() || "").split(','); var toolbarElement = document.getElementById("toolbar"); var previousToolbarItem = toolbarElement.children[0]; for (var panelName in this.panels) { if (hiddenPanels.indexOf(panelName) !== -1) continue; var panel = this.panels[panelName]; var panelToolbarItem = panel.toolbarItem; panelToolbarItem.addEventListener("click", this._toolbarItemClicked.bind(this)); if (previousToolbarItem) toolbarElement.insertBefore(panelToolbarItem, previousToolbarItem.nextSibling); else toolbarElement.insertBefore(panelToolbarItem, toolbarElement.firstChild); previousToolbarItem = panelToolbarItem; } this.currentPanel = this.panels.elements; this.resourceCategories = { documents: new WebInspector.ResourceCategory(WebInspector.UIString("Documents"), "documents"), stylesheets: new WebInspector.ResourceCategory(WebInspector.UIString("Stylesheets"), "stylesheets"), images: new WebInspector.ResourceCategory(WebInspector.UIString("Images"), "images"), scripts: new WebInspector.ResourceCategory(WebInspector.UIString("Scripts"), "scripts"), xhr: new WebInspector.ResourceCategory(WebInspector.UIString("XHR"), "xhr"), fonts: new WebInspector.ResourceCategory(WebInspector.UIString("Fonts"), "fonts"), other: new WebInspector.ResourceCategory(WebInspector.UIString("Other"), "other") }; this.Tips = { ResourceNotCompressed: {id: 0, message: WebInspector.UIString("You could save bandwidth by having your web server compress this transfer with gzip or zlib.")} }; this.Warnings = { IncorrectMIMEType: {id: 0, message: WebInspector.UIString("Resource interpreted as %s but transferred with MIME type %s.")} }; this.addMainEventListeners(document); window.addEventListener("unload", this.windowUnload.bind(this), true); window.addEventListener("resize", this.windowResize.bind(this), true); document.addEventListener("focus", this.focusChanged.bind(this), true); document.addEventListener("keydown", this.documentKeyDown.bind(this), true); document.addEventListener("keyup", this.documentKeyUp.bind(this), true); document.addEventListener("beforecopy", this.documentCanCopy.bind(this), true); document.addEventListener("copy", this.documentCopy.bind(this), true); var mainPanelsElement = document.getElementById("main-panels"); mainPanelsElement.handleKeyEvent = this.mainKeyDown.bind(this); mainPanelsElement.handleKeyUpEvent = this.mainKeyUp.bind(this); mainPanelsElement.handleCopyEvent = this.mainCopy.bind(this); // Focus the mainPanelsElement in a timeout so it happens after the initial focus, // so it doesn't get reset to the first toolbar button. This initial focus happens // on Mac when the window is made key and the WebHTMLView becomes the first responder. setTimeout(function() { WebInspector.currentFocusElement = mainPanelsElement }, 0); var dockToggleButton = document.getElementById("dock-status-bar-item"); dockToggleButton.addEventListener("click", this.toggleAttach.bind(this), false); if (this.attached) dockToggleButton.title = WebInspector.UIString("Undock into separate window."); else dockToggleButton.title = WebInspector.UIString("Dock to main window."); var errorWarningCount = document.getElementById("error-warning-count"); errorWarningCount.addEventListener("click", this.console.show.bind(this.console), false); this._updateErrorAndWarningCounts(); var searchField = document.getElementById("search"); searchField.addEventListener("keydown", this.searchKeyDown.bind(this), false); searchField.addEventListener("keyup", this.searchKeyUp.bind(this), false); searchField.addEventListener("search", this.performSearch.bind(this), false); // when the search is emptied document.getElementById("toolbar").addEventListener("mousedown", this.toolbarDragStart, true); document.getElementById("close-button").addEventListener("click", this.close, true); InspectorController.loaded();}var windowLoaded = function(){ var localizedStringsURL = InspectorController.localizedStringsURL(); if (localizedStringsURL) { var localizedStringsScriptElement = document.createElement("script"); localizedStringsScriptElement.addEventListener("load", WebInspector.loaded.bind(WebInspector), false); localizedStringsScriptElement.type = "text/javascript"; localizedStringsScriptElement.src = localizedStringsURL; document.getElementsByTagName("head").item(0).appendChild(localizedStringsScriptElement); } else WebInspector.loaded(); window.removeEventListener("load", windowLoaded, false); delete windowLoaded;};window.addEventListener("load", windowLoaded, false);WebInspector.windowUnload = function(event){ InspectorController.windowUnloading();}WebInspector.windowResize = function(event){ if (this.currentPanel && this.currentPanel.resize) this.currentPanel.resize();}WebInspector.windowFocused = function(event){ if (event.target.nodeType === Node.DOCUMENT_NODE) document.body.removeStyleClass("inactive");}WebInspector.windowBlured = function(event){ if (event.target.nodeType === Node.DOCUMENT_NODE) document.body.addStyleClass("inactive");}WebInspector.focusChanged = function(event){ this.currentFocusElement = event.target;}WebInspector.setAttachedWindow = function(attached){ this.attached = attached;}WebInspector.close = function(event){ InspectorController.closeWindow();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -