OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * Scrollable thumbnail ribbon at the bottom of the Gallery in the Slide mode. | 8 * Scrollable thumbnail ribbon at the bottom of the Gallery in the Slide mode. |
9 * | 9 * |
10 * @param {Document} document Document. | 10 * @param {Document} document Document. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 this.removeVanishing_(); | 89 this.removeVanishing_(); |
90 this.textContent = ''; | 90 this.textContent = ''; |
91 }; | 91 }; |
92 | 92 |
93 /** | 93 /** |
94 * Data model splice handler. | 94 * Data model splice handler. |
95 * @param {Event} event Event. | 95 * @param {Event} event Event. |
96 * @private | 96 * @private |
97 */ | 97 */ |
98 Ribbon.prototype.onSplice_ = function(event) { | 98 Ribbon.prototype.onSplice_ = function(event) { |
99 if (event.removed.length == 0) | |
100 return; | |
101 | |
102 if (event.removed.length > 1) { | 99 if (event.removed.length > 1) { |
103 console.error('Cannot remove multiple items'); | 100 console.error('Cannot remove multiple items.'); |
104 return; | 101 return; |
105 } | 102 } |
106 | 103 |
104 if (event.removed.length > 0 && event.added.length > 0) { | |
105 console.error('Replacing is not implemented.'); | |
106 return; | |
107 } | |
108 | |
109 if (event.added.length > 0) { | |
110 for (var i = 0; i < event.added.length; i++) { | |
111 var index = this.dataModel_.indexOf(event.added[i]); | |
112 if (index === -1) | |
113 continue; | |
114 var element = this.renderThumbnail_(index); | |
115 var nextItem = this.dataModel_.item(index + 1); | |
116 var nextElement = | |
117 nextItem && this.renderCache_[nextItem.getEntry().toURL()]; | |
118 this.insertBefore(element, nextElement); | |
yoshiki
2014/07/09 03:49:01
if nextElement is null, it may fail.
hirono
2014/07/09 04:04:54
The reference element can be null.
https://develop
| |
119 } | |
120 return; | |
121 } | |
122 | |
107 var removed = this.renderCache_[event.removed[0].getEntry().toURL()]; | 123 var removed = this.renderCache_[event.removed[0].getEntry().toURL()]; |
108 if (!removed || !removed.parentNode || !removed.hasAttribute('selected')) { | 124 if (!removed || !removed.parentNode || !removed.hasAttribute('selected')) { |
109 console.error('Can only remove the selected item'); | 125 console.error('Can only remove the selected item'); |
110 return; | 126 return; |
111 } | 127 } |
112 | 128 |
113 var persistentNodes = this.querySelectorAll('.ribbon-image:not([vanishing])'); | 129 var persistentNodes = this.querySelectorAll('.ribbon-image:not([vanishing])'); |
114 if (this.lastVisibleIndex_ < this.dataModel_.length) { // Not at the end. | 130 if (this.lastVisibleIndex_ < this.dataModel_.length) { // Not at the end. |
115 var lastNode = persistentNodes[persistentNodes.length - 1]; | 131 var lastNode = persistentNodes[persistentNodes.length - 1]; |
116 if (lastNode.nextSibling) { | 132 if (lastNode.nextSibling) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 Ribbon.prototype.onSelection_ = function() { | 169 Ribbon.prototype.onSelection_ = function() { |
154 var indexes = this.selectionModel_.selectedIndexes; | 170 var indexes = this.selectionModel_.selectedIndexes; |
155 if (indexes.length == 0) | 171 if (indexes.length == 0) |
156 return; // Ignore temporary empty selection. | 172 return; // Ignore temporary empty selection. |
157 var selectedIndex = indexes[0]; | 173 var selectedIndex = indexes[0]; |
158 | 174 |
159 var length = this.dataModel_.length; | 175 var length = this.dataModel_.length; |
160 | 176 |
161 // TODO(dgozman): use margin instead of 2 here. | 177 // TODO(dgozman): use margin instead of 2 here. |
162 var itemWidth = this.clientHeight - 2; | 178 var itemWidth = this.clientHeight - 2; |
163 var fullItems = Ribbon.ITEMS_COUNT; | 179 var fullItems = Math.min(Ribbon.ITEMS_COUNT, length); |
164 fullItems = Math.min(fullItems, length); | |
165 var right = Math.floor((fullItems - 1) / 2); | 180 var right = Math.floor((fullItems - 1) / 2); |
166 | 181 |
167 var fullWidth = fullItems * itemWidth; | 182 var fullWidth = fullItems * itemWidth; |
168 this.style.width = fullWidth + 'px'; | 183 this.style.width = fullWidth + 'px'; |
169 | 184 |
170 var lastIndex = selectedIndex + right; | 185 var lastIndex = selectedIndex + right; |
171 lastIndex = Math.max(lastIndex, fullItems - 1); | 186 lastIndex = Math.max(lastIndex, fullItems - 1); |
172 lastIndex = Math.min(lastIndex, length - 1); | 187 lastIndex = Math.min(lastIndex, length - 1); |
173 var firstIndex = lastIndex - fullItems + 1; | 188 var firstIndex = lastIndex - fullItems + 1; |
174 | 189 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 ImageUtil.setClass(this, 'fade-right', | 250 ImageUtil.setClass(this, 'fade-right', |
236 lastIndex < length - 1 && selectedIndex != lastIndex); | 251 lastIndex < length - 1 && selectedIndex != lastIndex); |
237 | 252 |
238 this.firstVisibleIndex_ = firstIndex; | 253 this.firstVisibleIndex_ = firstIndex; |
239 this.lastVisibleIndex_ = lastIndex; | 254 this.lastVisibleIndex_ = lastIndex; |
240 | 255 |
241 this.scheduleRemove_(); | 256 this.scheduleRemove_(); |
242 } | 257 } |
243 | 258 |
244 var oldSelected = this.querySelector('[selected]'); | 259 var oldSelected = this.querySelector('[selected]'); |
245 if (oldSelected) oldSelected.removeAttribute('selected'); | 260 if (oldSelected) |
261 oldSelected.removeAttribute('selected'); | |
246 | 262 |
247 var newSelected = | 263 var newSelected = |
248 this.renderCache_[this.dataModel_.item(selectedIndex).getEntry().toURL()]; | 264 this.renderCache_[this.dataModel_.item(selectedIndex).getEntry().toURL()]; |
249 if (newSelected) newSelected.setAttribute('selected', true); | 265 if (newSelected) |
266 newSelected.setAttribute('selected', true); | |
250 }; | 267 }; |
251 | 268 |
252 /** | 269 /** |
253 * Schedule the removal of thumbnails marked as vanishing. | 270 * Schedule the removal of thumbnails marked as vanishing. |
254 * @private | 271 * @private |
255 */ | 272 */ |
256 Ribbon.prototype.scheduleRemove_ = function() { | 273 Ribbon.prototype.scheduleRemove_ = function() { |
257 if (this.removeTimeout_) | 274 if (this.removeTimeout_) |
258 clearTimeout(this.removeTimeout_); | 275 clearTimeout(this.removeTimeout_); |
259 | 276 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 * @param {string} oldUrl Old url. | 374 * @param {string} oldUrl Old url. |
358 * @param {string} newUrl New url. | 375 * @param {string} newUrl New url. |
359 * @private | 376 * @private |
360 */ | 377 */ |
361 Ribbon.prototype.remapCache_ = function(oldUrl, newUrl) { | 378 Ribbon.prototype.remapCache_ = function(oldUrl, newUrl) { |
362 if (oldUrl != newUrl && (oldUrl in this.renderCache_)) { | 379 if (oldUrl != newUrl && (oldUrl in this.renderCache_)) { |
363 this.renderCache_[newUrl] = this.renderCache_[oldUrl]; | 380 this.renderCache_[newUrl] = this.renderCache_[oldUrl]; |
364 delete this.renderCache_[oldUrl]; | 381 delete this.renderCache_[oldUrl]; |
365 } | 382 } |
366 }; | 383 }; |
OLD | NEW |