home *** CD-ROM | disk | FTP | other *** search
/ Computer Active Guide 2009 July / CAG7.ISO / Internetas / SafariSetup.exe / AppleApplicationSupport.msi / WebKit.resources_inspector_Section.js < prev    next >
Encoding:
Text File  |  2010-06-03  |  4.0 KB  |  141 lines

  1. /*
  2.  * Copyright (C) 2007 Apple Inc.  All rights reserved.
  3.  * Copyright (C) 2009 Google Inc.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  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.
  17.  *
  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.
  28.  */
  29.  
  30. WebInspector.Section = function(title, subtitle)
  31. {
  32.     this.element = document.createElement("div");
  33.     this.element.className = "section";
  34.     this.element.sectionForTest = this;
  35.  
  36.     this.headerElement = document.createElement("div");
  37.     this.headerElement.className = "header";
  38.  
  39.     this.titleElement = document.createElement("div");
  40.     this.titleElement.className = "title";
  41.  
  42.     this.subtitleElement = document.createElement("div");
  43.     this.subtitleElement.className = "subtitle";
  44.  
  45.     this.headerElement.appendChild(this.subtitleElement);
  46.     this.headerElement.appendChild(this.titleElement);
  47.  
  48.     this.headerElement.addEventListener("click", this.toggleExpanded.bind(this), false);
  49.     this.element.appendChild(this.headerElement);
  50.  
  51.     this.title = title;
  52.     this.subtitle = subtitle;
  53.     this._expanded = false;
  54. }
  55.  
  56. WebInspector.Section.prototype = {
  57.     get title()
  58.     {
  59.         return this._title;
  60.     },
  61.  
  62.     set title(x)
  63.     {
  64.         if (this._title === x)
  65.             return;
  66.         this._title = x;
  67.  
  68.         if (x instanceof Node) {
  69.             this.titleElement.removeChildren();
  70.             this.titleElement.appendChild(x);
  71.         } else
  72.           this.titleElement.textContent = x;
  73.     },
  74.  
  75.     get subtitle()
  76.     {
  77.         return this._subtitle;
  78.     },
  79.  
  80.     set subtitle(x)
  81.     {
  82.         if (this._subtitle === x)
  83.             return;
  84.         this._subtitle = x;
  85.         this.subtitleElement.innerHTML = x;
  86.     },
  87.  
  88.     get expanded()
  89.     {
  90.         return this._expanded;
  91.     },
  92.  
  93.     set expanded(x)
  94.     {
  95.         if (x)
  96.             this.expand();
  97.         else
  98.             this.collapse();
  99.     },
  100.  
  101.     get populated()
  102.     {
  103.         return this._populated;
  104.     },
  105.  
  106.     set populated(x)
  107.     {
  108.         this._populated = x;
  109.         if (!x && this.onpopulate && this._expanded) {
  110.             this.onpopulate(this);
  111.             this._populated = true;
  112.         }
  113.     },
  114.  
  115.     expand: function()
  116.     {
  117.         if (this._expanded)
  118.             return;
  119.         this._expanded = true;
  120.         this.element.addStyleClass("expanded");
  121.  
  122.         if (!this._populated && this.onpopulate) {
  123.             this.onpopulate(this);
  124.             this._populated = true;
  125.         }
  126.     },
  127.  
  128.     collapse: function()
  129.     {
  130.         if (!this._expanded)
  131.             return;
  132.         this._expanded = false;
  133.         this.element.removeStyleClass("expanded");
  134.     },
  135.  
  136.     toggleExpanded: function()
  137.     {
  138.         this.expanded = !this.expanded;
  139.     }
  140. }
  141.