3 Copyright (c) 2014 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
7 <link rel="import" href="/tvcm/ui.html">
8 <link rel="import" href="/tvcm/ui/dom_helpers.html">
9 <link rel="stylesheet" href="/tvcm/ui/info_bar.css">
13 tvcm.exportTo('tvcm.ui', function() {
17 var InfoBar = tvcm.ui.define('x-info-bar');
20 __proto__: HTMLDivElement.prototype,
22 decorate: function() {
23 this.messageEl_ = tvcm.ui.createSpan({className: 'message'});
24 this.buttonsEl_ = tvcm.ui.createSpan({className: 'buttons'});
26 this.appendChild(this.messageEl_);
27 this.appendChild(this.buttonsEl_);
33 return this.messageEl_.textContent;
36 set message(message) {
37 this.messageEl_.textContent = message;
41 return this.classList.contains('info-bar-hidden');
44 set visible(visible) {
46 this.classList.remove('info-bar-hidden');
48 this.classList.add('info-bar-hidden');
51 removeAllButtons: function() {
52 this.buttonsEl_.textContent = '';
55 addButton: function(text, clickCallback) {
56 var button = document.createElement('button');
57 button.textContent = text;
58 button.addEventListener('click', clickCallback);
59 this.buttonsEl_.appendChild(button);
67 var InfoBarGroup = tvcm.ui.define('x-info-bar-group');
69 InfoBarGroup.prototype = {
70 __proto__: HTMLUnknownElement.prototype,
72 decorate: function() {
76 clearMessages: function() {
78 this.updateContents_();
81 addMessage: function(text, opt_buttons) {
82 opt_buttons = opt_buttons || [];
83 for (var i = 0; i < opt_buttons.length; i++) {
84 if (opt_buttons[i].buttonText === undefined)
85 throw new Error('buttonText must be provided');
86 if (opt_buttons[i].onClick === undefined)
87 throw new Error('onClick must be provided');
92 buttons: opt_buttons || []
94 this.updateContents_();
97 updateContents_: function() {
98 this.textContent = '';
99 this.messages_.forEach(function(message) {
100 var bar = new InfoBar();
101 bar.message = message.text;
103 message.buttons.forEach(function(button) {
104 bar.addButton(button.buttonText, button.onClick);
106 this.appendChild(bar);
114 InfoBarGroup: InfoBarGroup