OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * PreviewPanel UI class. | 8 * PreviewPanel UI class. |
9 * @param {HTMLElement} element DOM Element of preview panel. | 9 * @param {HTMLElement} element DOM Element of preview panel. |
10 * @param {PreviewPanel.VisibilityType} visibilityType Initial value of the | 10 * @param {PreviewPanel.VisibilityType} visibilityType Initial value of the |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 PreviewPanel.Event = Object.freeze({ | 85 PreviewPanel.Event = Object.freeze({ |
86 // Event to be triggered at the end of visibility change. | 86 // Event to be triggered at the end of visibility change. |
87 VISIBILITY_CHANGE: 'visibilityChange' | 87 VISIBILITY_CHANGE: 'visibilityChange' |
88 }); | 88 }); |
89 | 89 |
90 /** | 90 /** |
91 * Visibility type of the preview panel. | 91 * Visibility type of the preview panel. |
92 */ | 92 */ |
93 PreviewPanel.VisibilityType = Object.freeze({ | 93 PreviewPanel.VisibilityType = Object.freeze({ |
94 // Preview panel always shows. | 94 // Preview panel always shows. |
95 ALWAYS: 'always', | 95 ALWAYS_VISIBLE: 'alwaysVisible', |
96 // Preview panel shows when the entries property are set. | 96 // Preview panel shows when the entries property are set. |
97 AUTO: 'auto', | 97 AUTO: 'auto', |
98 // Preview panel does not show. | 98 // Preview panel does not show. |
99 HIDDEN: 'hidden' | 99 ALWAYS_HIDDEN: 'alwaysHidden' |
100 }); | 100 }); |
101 | 101 |
102 /** | 102 /** |
103 * @private | 103 * @private |
104 */ | 104 */ |
105 PreviewPanel.Visibility_ = Object.freeze({ | 105 PreviewPanel.Visibility_ = Object.freeze({ |
106 VISIBLE: 'visible', | 106 VISIBLE: 'visible', |
107 HIDING: 'hiding', | 107 HIDING: 'hiding', |
108 HIDDEN: 'hidden' | 108 HIDDEN: 'hidden' |
109 }); | 109 }); |
(...skipping 27 matching lines...) Expand all Loading... |
137 set visibilityType(visibilityType) { | 137 set visibilityType(visibilityType) { |
138 this.visibilityType_ = visibilityType; | 138 this.visibilityType_ = visibilityType; |
139 this.updateVisibility_(); | 139 this.updateVisibility_(); |
140 }, | 140 }, |
141 | 141 |
142 get visible() { | 142 get visible() { |
143 return this.element_.getAttribute('visibility') == | 143 return this.element_.getAttribute('visibility') == |
144 PreviewPanel.Visibility_.VISIBLE; | 144 PreviewPanel.Visibility_.VISIBLE; |
145 }, | 145 }, |
146 | 146 |
| 147 /** |
| 148 * Obtains the height of preview panel. |
| 149 * @return {number} Height of preview panel. |
| 150 */ |
147 get height() { | 151 get height() { |
148 this.height_ = this.height_ || this.element_.clientHeight; | 152 this.height_ = this.height_ || this.element_.clientHeight; |
149 return this.height_; | 153 return this.height_; |
150 } | 154 } |
151 }; | 155 }; |
152 | 156 |
153 /** | 157 /** |
154 * Initializes the element. | 158 * Initializes the element. |
155 */ | 159 */ |
156 PreviewPanel.prototype.initialize = function() { | 160 PreviewPanel.prototype.initialize = function() { |
157 this.element_.addEventListener('webkitTransitionEnd', | 161 this.element_.addEventListener('webkitTransitionEnd', |
158 this.onTransitionEnd_.bind(this)); | 162 this.onTransitionEnd_.bind(this)); |
159 this.updateVisibility_(); | 163 this.updateVisibility_(); |
160 }; | 164 }; |
161 | 165 |
162 /** | 166 /** |
163 * Update the visibility of the preview panel. | 167 * Update the visibility of the preview panel. |
164 * @private | 168 * @private |
165 */ | 169 */ |
166 PreviewPanel.prototype.updateVisibility_ = function() { | 170 PreviewPanel.prototype.updateVisibility_ = function() { |
167 // Get the new visibility value. | 171 // Get the new visibility value. |
168 var visibility = this.element_.getAttribute('visibility'); | 172 var visibility = this.element_.getAttribute('visibility'); |
169 var newVisible = null; | 173 var newVisible = null; |
170 switch (this.visibilityType_) { | 174 switch (this.visibilityType_) { |
171 case PreviewPanel.VisibilityType.ALWAYS: | 175 case PreviewPanel.VisibilityType.ALWAYS_VISIBLE: |
172 newVisible = true; | 176 newVisible = true; |
173 break; | 177 break; |
174 case PreviewPanel.VisibilityType.AUTO: | 178 case PreviewPanel.VisibilityType.AUTO: |
175 newVisible = this.entries_.length != 0 || | 179 newVisible = this.entries_.length != 0 || |
176 !PathUtil.isRootPath(this.currentPath_); | 180 !PathUtil.isRootPath(this.currentPath_); |
177 break; | 181 break; |
178 case PreviewPanel.VisibilityType.HIDDEN: | 182 case PreviewPanel.VisibilityType.ALWAYS_HIDDEN: |
179 newVisible = false; | 183 newVisible = false; |
180 break; | 184 break; |
181 default: | 185 default: |
182 console.error('Invalid visibilityType.'); | 186 console.error('Invalid visibilityType.'); |
183 return; | 187 return; |
184 } | 188 } |
185 | 189 |
186 // If the visibility has been already the new value, just return. | 190 // If the visibility has been already the new value, just return. |
187 if ((visibility == PreviewPanel.Visibility_.VISIBLE && newVisible) || | 191 if ((visibility == PreviewPanel.Visibility_.VISIBLE && newVisible) || |
188 (visibility == PreviewPanel.Visibility_.HIDDEN && !newVisible)) | 192 (visibility == PreviewPanel.Visibility_.HIDDEN && !newVisible)) |
(...skipping 15 matching lines...) Expand all Loading... |
204 */ | 208 */ |
205 PreviewPanel.prototype.onTransitionEnd_ = function(event) { | 209 PreviewPanel.prototype.onTransitionEnd_ = function(event) { |
206 if (event.target != this.element_ || event.propertyName != 'opacity') | 210 if (event.target != this.element_ || event.propertyName != 'opacity') |
207 return; | 211 return; |
208 var visibility = this.element_.getAttribute('visibility'); | 212 var visibility = this.element_.getAttribute('visibility'); |
209 if (visibility != PreviewPanel.Visibility_.HIDING) | 213 if (visibility != PreviewPanel.Visibility_.HIDING) |
210 return; | 214 return; |
211 this.element_.setAttribute('visibility', PreviewPanel.Visibility_.HIDDEN); | 215 this.element_.setAttribute('visibility', PreviewPanel.Visibility_.HIDDEN); |
212 cr.dispatchSimpleEvent(this, PreviewPanel.Event.VISIBILITY_CHANGE); | 216 cr.dispatchSimpleEvent(this, PreviewPanel.Event.VISIBILITY_CHANGE); |
213 }; | 217 }; |
OLD | NEW |