OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * A TabView provides the ability to create tabs and switch between tabs. It's | 6 * A TabView provides the ability to create tabs and switch between tabs. It's |
7 * responsible for creating the DOM and managing the visibility of each tab. | 7 * responsible for creating the DOM and managing the visibility of each tab. |
8 * The first added tab is active by default and the others hidden. | 8 * The first added tab is active by default and the others hidden. |
9 */ | 9 */ |
10 var TabView = (function() { | 10 var TabView = (function() { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 this.tabElements_[id].head); | 78 this.tabElements_[id].head); |
79 this.tabElements_[id].body.parentNode.removeChild( | 79 this.tabElements_[id].body.parentNode.removeChild( |
80 this.tabElements_[id].body); | 80 this.tabElements_[id].body); |
81 | 81 |
82 delete this.tabElements_[id]; | 82 delete this.tabElements_[id]; |
83 if (this.activeTabId_ == id) { | 83 if (this.activeTabId_ == id) { |
84 this.switchTab_(Object.keys(this.tabElements_)[0]); | 84 this.switchTab_(Object.keys(this.tabElements_)[0]); |
85 } | 85 } |
86 }, | 86 }, |
87 | 87 |
88 makeTabRemovable: function(id) { | |
89 if (!this.tabElements_[id]) | |
90 return; | |
91 var close = document.createElement('a'); | |
92 close.textContent = '[x]'; | |
93 close.addEventListener('click', function() { | |
94 this.removeTab(id); | |
95 }.bind(this)); | |
96 this.tabElements_[id].head.appendChild(close); | |
97 }, | |
98 | |
99 /** | 88 /** |
100 * Switches the specified tab into view. | 89 * Switches the specified tab into view. |
101 * | 90 * |
102 * @param {string} activeId The id the of the tab that should be switched to | 91 * @param {string} activeId The id the of the tab that should be switched to |
103 * active state. | 92 * active state. |
104 * @private | 93 * @private |
105 */ | 94 */ |
106 switchTab_: function(activeId) { | 95 switchTab_: function(activeId) { |
107 if (this.activeTabId_ && this.tabElements_[this.activeTabId_]) { | 96 if (this.activeTabId_ && this.tabElements_[this.activeTabId_]) { |
108 this.tabElements_[this.activeTabId_].body.classList.remove( | 97 this.tabElements_[this.activeTabId_].body.classList.remove( |
(...skipping 12 matching lines...) Expand all Loading... |
121 | 110 |
122 /** Initializes the bar containing the tab heads. */ | 111 /** Initializes the bar containing the tab heads. */ |
123 initializeHeadBar_: function() { | 112 initializeHeadBar_: function() { |
124 this.headBar_ = document.createElement('div'); | 113 this.headBar_ = document.createElement('div'); |
125 this.root_.appendChild(this.headBar_); | 114 this.root_.appendChild(this.headBar_); |
126 this.headBar_.style.textAlign = 'center'; | 115 this.headBar_.style.textAlign = 'center'; |
127 }, | 116 }, |
128 }; | 117 }; |
129 return TabView; | 118 return TabView; |
130 })(); | 119 })(); |
OLD | NEW |