Home | History | Annotate | Download | only in ui
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 'use strict';
      6 
      7 base.requireStylesheet('ui.info_bar');
      8 base.require('ui');
      9 base.require('ui.dom_helpers');
     10 
     11 base.exportTo('ui', function() {
     12   /**
     13    * @constructor
     14    */
     15   var InfoBar = ui.define('info-bar');
     16 
     17   InfoBar.prototype = {
     18     __proto__: HTMLDivElement.prototype,
     19 
     20     decorate: function() {
     21       this.messageEl_ = ui.createSpan({className: 'message'});
     22       this.buttonsEl_ = ui.createSpan({className: 'buttons'});
     23 
     24       this.appendChild(this.messageEl_);
     25       this.appendChild(this.buttonsEl_);
     26       this.message = '';
     27       this.visible = false;
     28     },
     29 
     30     get message() {
     31       return this.messageEl_.textContent;
     32     },
     33 
     34     set message(message) {
     35       this.messageEl_.textContent = message;
     36     },
     37 
     38     get visible() {
     39       return this.classList.contains('info-bar-hidden');
     40     },
     41 
     42     set visible(visible) {
     43       if (visible)
     44         this.classList.remove('info-bar-hidden');
     45       else
     46         this.classList.add('info-bar-hidden');
     47     },
     48 
     49     removeAllButtons: function() {
     50       this.buttonsEl_.textContent = '';
     51     },
     52 
     53     addButton: function(text, clickCallback) {
     54       var button = document.createElement('button');
     55       button.textContent = text;
     56       button.addEventListener('click', clickCallback);
     57       this.buttonsEl_.appendChild(button);
     58       return button;
     59     }
     60   };
     61 
     62   return {
     63     InfoBar: InfoBar
     64   };
     65 });
     66