OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 * @fileoverview Card slider implementation. Allows you to create interactions | 6 * @fileoverview Card slider implementation. Allows you to create interactions |
7 * that have items that can slide left to right to reveal additional items. | 7 * that have items that can slide left to right to reveal additional items. |
8 * Works by adding the necessary event handlers to a specific DOM structure | 8 * Works by adding the necessary event handlers to a specific DOM structure |
9 * including a frame, container and cards. | 9 * including a frame, container and cards. |
10 * - The frame defines the boundary of one item. Each card will be expanded to | 10 * - The frame defines the boundary of one item. Each card will be expanded to |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 this.transformToCurrentCard_(opt_animate); | 265 this.transformToCurrentCard_(opt_animate); |
266 | 266 |
267 if (isChangingCard) { | 267 if (isChangingCard) { |
268 var event = document.createEvent('Event'); | 268 var event = document.createEvent('Event'); |
269 event.initEvent(CardSlider.EventType.CARD_CHANGED, true, true); | 269 event.initEvent(CardSlider.EventType.CARD_CHANGED, true, true); |
270 event.cardSlider = this; | 270 event.cardSlider = this; |
271 this.container_.dispatchEvent(event); | 271 this.container_.dispatchEvent(event); |
272 } | 272 } |
273 }, | 273 }, |
274 | 274 |
275 selectCardByValue: function(newCard, opt_animate) { | |
csilv
2011/05/24 19:50:18
nit: Add a function comment.
| |
276 for (var i = 0; i < this.cards_.length; i++) { | |
277 if (newCard == this.cards_[i]) { | |
278 this.selectCard(i, opt_animate); | |
279 return; | |
280 } | |
281 } | |
282 assert(false); | |
283 }, | |
284 | |
275 /** | 285 /** |
276 * Centers the view on the card denoted by this.currentCard. Can either | 286 * Centers the view on the card denoted by this.currentCard. Can either |
277 * animate to that card or snap to it. | 287 * animate to that card or snap to it. |
278 * @param {boolean=} opt_animate If true will animate transition from | 288 * @param {boolean=} opt_animate If true will animate transition from |
279 * current position to new position. | 289 * current position to new position. |
280 * @private | 290 * @private |
281 */ | 291 */ |
282 transformToCurrentCard_: function(opt_animate) { | 292 transformToCurrentCard_: function(opt_animate) { |
283 this.currentLeft_ = -this.currentCard * this.cardWidth_; | 293 this.currentLeft_ = -this.currentCard * this.cardWidth_; |
284 | 294 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 | 389 |
380 // Ensure we're at a card bounary | 390 // Ensure we're at a card bounary |
381 this.transformToCurrentCard_(true); | 391 this.transformToCurrentCard_(true); |
382 }, | 392 }, |
383 | 393 |
384 | 394 |
385 }; | 395 }; |
386 | 396 |
387 return CardSlider; | 397 return CardSlider; |
388 })(); | 398 })(); |
OLD | NEW |