Home | History | Annotate | Download | only in front_end
      1 /*
      2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 /**
     27  * @constructor
     28  * @param {string} title
     29  * @param {string} subtitle
     30  */
     31 WebInspector.Placard = function(title, subtitle)
     32 {
     33     this.element = document.createElement("div");
     34     this.element.className = "placard";
     35     this.element.placard = this;
     36 
     37     this.titleElement = document.createElement("div");
     38     this.titleElement.className = "title";
     39 
     40     this.subtitleElement = document.createElement("div");
     41     this.subtitleElement.className = "subtitle";
     42 
     43     this.element.appendChild(this.subtitleElement);
     44     this.element.appendChild(this.titleElement);
     45 
     46     this.title = title;
     47     this.subtitle = subtitle;
     48     this.selected = false;
     49 }
     50 
     51 WebInspector.Placard.prototype = {
     52     /** @return {string} */
     53     get title()
     54     {
     55         return this._title;
     56     },
     57 
     58     set title(x)
     59     {
     60         if (this._title === x)
     61             return;
     62         this._title = x;
     63         this.titleElement.textContent = x;
     64     },
     65 
     66     /** @return {string} */
     67     get subtitle()
     68     {
     69         return this._subtitle;
     70     },
     71 
     72     set subtitle(x)
     73     {
     74         if (this._subtitle === x)
     75             return;
     76         this._subtitle = x;
     77         this.subtitleElement.textContent = x;
     78     },
     79 
     80     /** @return {boolean} */
     81     get selected()
     82     {
     83         return this._selected;
     84     },
     85 
     86     set selected(x)
     87     {
     88         if (x)
     89             this.select();
     90         else
     91             this.deselect();
     92     },
     93 
     94     select: function()
     95     {
     96         if (this._selected)
     97             return;
     98         this._selected = true;
     99         this.element.addStyleClass("selected");
    100     },
    101 
    102     deselect: function()
    103     {
    104         if (!this._selected)
    105             return;
    106         this._selected = false;
    107         this.element.removeStyleClass("selected");
    108     },
    109 
    110     toggleSelected: function()
    111     {
    112         this.selected = !this.selected;
    113     },
    114 
    115     discard: function()
    116     {
    117     }
    118 }
    119