2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Google Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 WebInspector.Section = function(title, subtitle)
32 this.element = document.createElement("div");
33 this.element.className = "section";
34 this.element._section = this;
36 this.headerElement = document.createElement("div");
37 this.headerElement.className = "header";
39 this.titleElement = document.createElement("div");
40 this.titleElement.className = "title";
42 this.subtitleElement = document.createElement("div");
43 this.subtitleElement.className = "subtitle";
45 this.headerElement.appendChild(this.subtitleElement);
46 this.headerElement.appendChild(this.titleElement);
48 this.headerElement.addEventListener("click", this.handleClick.bind(this), false);
49 this.element.appendChild(this.headerElement);
52 this.subtitle = subtitle;
53 this._expanded = false;
56 WebInspector.Section.prototype = {
64 if (this._title === x)
68 if (x instanceof Node) {
69 this.titleElement.removeChildren();
70 this.titleElement.appendChild(x);
72 this.titleElement.textContent = x;
77 return this._subtitle;
82 if (this._subtitle === x)
85 this.subtitleElement.textContent = x;
88 get subtitleAsTextForTest()
90 var result = this.subtitleElement.textContent;
91 var child = this.subtitleElement.querySelector("[data-uncopyable]");
93 var linkData = child.getAttribute("data-uncopyable");
102 return this._expanded;
115 return this._populated;
121 if (!x && this.onpopulate && this._expanded) {
122 this.onpopulate(this);
123 this._populated = true;
129 var parent = this.element.parentElement;
133 var childElement = parent.firstChild;
134 while (childElement) {
135 if (childElement._section)
136 return childElement._section;
137 childElement = childElement.nextSibling;
145 var parent = this.element.parentElement;
149 var childElement = parent.lastChild;
150 while (childElement) {
151 if (childElement._section)
152 return childElement._section;
153 childElement = childElement.previousSibling;
161 var curElement = this.element;
163 curElement = curElement.nextSibling;
164 } while (curElement && !curElement._section);
166 return curElement ? curElement._section : null;
169 get previousSibling()
171 var curElement = this.element;
173 curElement = curElement.previousSibling;
174 } while (curElement && !curElement._section);
176 return curElement ? curElement._section : null;
183 this._expanded = true;
184 this.element.addStyleClass("expanded");
186 if (!this._populated && this.onpopulate) {
187 this.onpopulate(this);
188 this._populated = true;
196 this._expanded = false;
197 this.element.removeStyleClass("expanded");
200 toggleExpanded: function()
202 this.expanded = !this.expanded;
205 handleClick: function(e)
207 this.toggleExpanded();