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.
32 * @param {string|!Element} title
33 * @param {string=} subtitle
35 WebInspector.Section = function(title, subtitle)
37 this.element = document.createElement("div");
38 this.element.className = "section";
39 this.element._section = this;
41 this.headerElement = document.createElement("div");
42 this.headerElement.className = "header";
44 this.titleElement = document.createElement("div");
45 this.titleElement.className = "title";
47 this.subtitleElement = document.createElement("div");
48 this.subtitleElement.className = "subtitle";
50 this.headerElement.appendChild(this.subtitleElement);
51 this.headerElement.appendChild(this.titleElement);
53 this.headerElement.addEventListener("click", this.handleClick.bind(this), false);
54 this.element.appendChild(this.headerElement);
57 this.subtitle = subtitle;
58 this._expanded = false;
61 WebInspector.Section.prototype = {
69 if (this._title === x)
73 if (x instanceof Node) {
74 this.titleElement.removeChildren();
75 this.titleElement.appendChild(x);
77 this.titleElement.textContent = x;
82 return this._subtitle;
87 if (this._subtitle === x)
90 this.subtitleElement.textContent = x;
93 get subtitleAsTextForTest()
95 var result = this.subtitleElement.textContent;
96 var child = this.subtitleElement.querySelector("[data-uncopyable]");
98 var linkData = child.getAttribute("data-uncopyable");
107 return this._expanded;
120 return this._populated;
126 if (!x && this._expanded) {
128 this._populated = true;
132 onpopulate: function()
134 // Overriden by subclasses.
139 var parent = this.element.parentElement;
143 var childElement = parent.firstChild;
144 while (childElement) {
145 if (childElement._section)
146 return childElement._section;
147 childElement = childElement.nextSibling;
155 var parent = this.element.parentElement;
159 var childElement = parent.lastChild;
160 while (childElement) {
161 if (childElement._section)
162 return childElement._section;
163 childElement = childElement.previousSibling;
171 var curElement = this.element;
173 curElement = curElement.nextSibling;
174 } while (curElement && !curElement._section);
176 return curElement ? curElement._section : null;
179 get previousSibling()
181 var curElement = this.element;
183 curElement = curElement.previousSibling;
184 } while (curElement && !curElement._section);
186 return curElement ? curElement._section : null;
193 this._expanded = true;
194 this.element.classList.add("expanded");
196 if (!this._populated) {
198 this._populated = true;
206 this._expanded = false;
207 this.element.classList.remove("expanded");
210 toggleExpanded: function()
212 this.expanded = !this.expanded;
215 handleClick: function(event)
217 this.toggleExpanded();