Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 */ | 337 */ |
| 338 addCardAtIndex: function(card, index) { | 338 addCardAtIndex: function(card, index) { |
| 339 assert(card instanceof Node, '|card| isn\'t a Node'); | 339 assert(card instanceof Node, '|card| isn\'t a Node'); |
| 340 this.assertValidIndex_(index); | 340 this.assertValidIndex_(index); |
| 341 this.cards_ = Array.prototype.concat.call( | 341 this.cards_ = Array.prototype.concat.call( |
| 342 this.cards_.slice(0, index), card, this.cards_.slice(index)); | 342 this.cards_.slice(0, index), card, this.cards_.slice(index)); |
| 343 | 343 |
| 344 if (this.currentCard_ == -1) | 344 if (this.currentCard_ == -1) |
| 345 this.currentCard_ = 0; | 345 this.currentCard_ = 0; |
| 346 else if (index <= this.currentCard_) | 346 else if (index <= this.currentCard_) |
| 347 this.selectCard(this.currentCard_ + 1, false, true); | 347 this.selectCard(this.currentCard_ + 1, false, true, true); |
| 348 | 348 |
| 349 this.fireAddedEvent_(card, index); | 349 this.fireAddedEvent_(card, index); |
| 350 }, | 350 }, |
| 351 | 351 |
| 352 /** | 352 /** |
| 353 * Append a card to the end of the list. | 353 * Append a card to the end of the list. |
| 354 * @param {!Node} card A card to add at the end of the card slider. | 354 * @param {!Node} card A card to add at the end of the card slider. |
| 355 */ | 355 */ |
| 356 appendCard: function(card) { | 356 appendCard: function(card) { |
| 357 assert(card instanceof Node, '|card| isn\'t a Node'); | 357 assert(card instanceof Node, '|card| isn\'t a Node'); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 }, | 429 }, |
| 430 | 430 |
| 431 /** | 431 /** |
| 432 * Selects a new card, ensuring that it is a valid index, transforming the | 432 * Selects a new card, ensuring that it is a valid index, transforming the |
| 433 * view and possibly calling the change card callback. | 433 * view and possibly calling the change card callback. |
| 434 * @param {number} newCardIndex Index of card to show. | 434 * @param {number} newCardIndex Index of card to show. |
| 435 * @param {boolean=} opt_animate If true will animate transition from | 435 * @param {boolean=} opt_animate If true will animate transition from |
| 436 * current position to new position. | 436 * current position to new position. |
| 437 * @param {boolean=} opt_dontNotify If true, don't tell subscribers that | 437 * @param {boolean=} opt_dontNotify If true, don't tell subscribers that |
| 438 * we've changed cards. | 438 * we've changed cards. |
| 439 * @param {boolean=} opt_forceChange If true, ignore if the card already | |
| 440 * selected. | |
|
Dan Beam
2012/02/28 20:14:24
Why is this necessary? In theory if you're insert
GeorgeY
2012/02/28 21:17:42
I just fixed a *bug* that was here: if you inserte
Dan Beam
2012/02/28 22:30:12
I don't see a bug fix, I see an override.
GeorgeY
2012/02/29 00:15:45
Bug: insert a card *prior* to the selected card. C
| |
| 439 */ | 441 */ |
| 440 selectCard: function(newCardIndex, opt_animate, opt_dontNotify) { | 442 selectCard: function(newCardIndex, opt_animate, opt_dontNotify, |
| 443 opt_forceChange) { | |
| 441 this.assertValidIndex_(newCardIndex); | 444 this.assertValidIndex_(newCardIndex); |
| 442 | 445 |
| 443 var previousCard = this.currentCardValue; | 446 var previousCard = this.currentCardValue; |
| 444 var isChangingCard = | 447 var isChangingCard = |
| 445 !this.cards_[newCardIndex].classList.contains('selected-card'); | 448 !this.cards_[newCardIndex].classList.contains('selected-card'); |
| 446 | 449 |
| 450 if (opt_forceChange != 'undefined' && opt_forceChange) | |
|
Dan Beam
2012/02/28 20:14:24
typeof opt_forceChange
GeorgeY
2012/02/28 21:17:42
Done.
| |
| 451 isChangingCard = true; | |
| 452 | |
| 447 if (isChangingCard) { | 453 if (isChangingCard) { |
| 448 if (previousCard) | 454 if (previousCard) |
| 449 previousCard.classList.remove('selected-card'); | 455 previousCard.classList.remove('selected-card'); |
| 450 this.currentCard_ = newCardIndex; | 456 this.currentCard_ = newCardIndex; |
| 451 this.currentCardValue.classList.add('selected-card'); | 457 this.currentCardValue.classList.add('selected-card'); |
| 452 } | 458 } |
| 453 | 459 |
| 454 var willTransitionHappen = this.transformToCurrentCard_(opt_animate); | 460 var willTransitionHappen = this.transformToCurrentCard_(opt_animate); |
| 455 | 461 |
| 456 if (isChangingCard && !opt_dontNotify) { | 462 if (isChangingCard && !opt_dontNotify) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 606 | 612 |
| 607 // Ensure we're at a card bounary | 613 // Ensure we're at a card bounary |
| 608 this.transformToCurrentCard_(true); | 614 this.transformToCurrentCard_(true); |
| 609 }, | 615 }, |
| 610 }; | 616 }; |
| 611 | 617 |
| 612 return { | 618 return { |
| 613 CardSlider: CardSlider | 619 CardSlider: CardSlider |
| 614 }; | 620 }; |
| 615 }); | 621 }); |
| OLD | NEW |