2 * Copyright (C) 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 WebInspector.Panel = function(views)
31 this._visible = false;
33 this.element = document.createElement("div");
34 this.element.className = "panel";
37 this.viewButtons = [];
40 var selectViewFunction = function(event)
42 var clickedView = event.currentTarget.view;
43 clickedView.panel.currentView = clickedView;
46 for (var i = 0; i < views.length; ++i) {
50 view.buttonElement = document.createElement("button");
51 view.buttonElement.title = view.title;
52 view.buttonElement.addEventListener("click", selectViewFunction, false);
53 view.buttonElement.appendChild(document.createElement("img"));
54 view.buttonElement.view = view;
56 view.contentElement = document.createElement("div");
57 view.contentElement.className = "content " + view.name;
59 this.views[view.name] = view;
60 this.viewButtons.push(view.buttonElement);
61 this.element.appendChild(view.contentElement);
66 WebInspector.Panel.prototype = {
70 if (!this.element.parentNode)
72 this.element.addStyleClass("selected");
74 if (this.currentView && this.currentView.show)
75 this.currentView.show();
80 if (this.currentView && this.currentView.hide)
81 this.currentView.hide();
82 document.getElementById("toolbarButtons").removeChildren();
83 this.element.removeStyleClass("selected");
84 this._visible = false;
87 updateToolbar: function()
89 var buttonContainer = document.getElementById("toolbarButtons");
90 buttonContainer.removeChildren();
92 var buttons = this.viewButtons;
93 if (buttons.length < 2)
96 for (var i = 0; i < buttons.length; ++i) {
97 var button = buttons[i];
100 button.addStyleClass("first");
101 else if (i === (buttons.length - 1))
102 button.addStyleClass("last");
105 var divider = document.createElement("img");
106 divider.className = "split-button-divider";
107 buttonContainer.appendChild(divider);
110 button.addStyleClass("split-button");
111 button.addStyleClass("view-button-" + button.title.toLowerCase());
113 buttonContainer.appendChild(button);
119 document.getElementById("panels").appendChild(this.element);
124 if (WebInspector.currentPanel === this)
125 WebInspector.currentPanel = null;
126 if (this.element && this.element.parentNode)
127 this.element.parentNode.removeChild(this.element);
132 return this._currentView;
137 if (typeof x === "string" || x instanceof String)
140 if (this._currentView === x)
143 if (this !== x.panel) {
144 console.error("Set currentView to a view " + x.title + " whose panel is not this panel");
148 if (this._currentView) {
149 this._currentView.buttonElement.removeStyleClass("selected");
150 this._currentView.contentElement.removeStyleClass("selected");
151 if (this._currentView.hide)
152 this._currentView.hide();
155 this._currentView = x;
158 x.buttonElement.addStyleClass("selected");
159 x.contentElement.addStyleClass("selected");
167 return this._visible;
172 if (this._visible === x)