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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 this.currentCardValue.classList.add('selected-card'); | 291 this.currentCardValue.classList.add('selected-card'); |
292 } | 292 } |
293 | 293 |
294 this.transformToCurrentCard_(opt_animate); | 294 this.transformToCurrentCard_(opt_animate); |
295 | 295 |
296 if (isChangingCard) { | 296 if (isChangingCard) { |
297 var event = document.createEvent('Event'); | 297 var event = document.createEvent('Event'); |
298 event.initEvent(CardSlider.EventType.CARD_CHANGED, true, true); | 298 event.initEvent(CardSlider.EventType.CARD_CHANGED, true, true); |
299 event.cardSlider = this; | 299 event.cardSlider = this; |
300 this.container_.dispatchEvent(event); | 300 this.container_.dispatchEvent(event); |
| 301 |
| 302 // We also dispatch an event on the card itself. |
| 303 cr.dispatchSimpleEvent(this.currentCardValue, 'cardselected', |
| 304 true, true); |
301 } | 305 } |
302 }, | 306 }, |
303 | 307 |
304 /** | 308 /** |
305 * Selects a card from the stack. Passes through to selectCard. | 309 * Selects a card from the stack. Passes through to selectCard. |
306 * @param {Node} newCard The card that should be selected. | 310 * @param {Node} newCard The card that should be selected. |
307 * @param {boolean=} opt_animate Whether to animate. | 311 * @param {boolean=} opt_animate Whether to animate. |
308 */ | 312 */ |
309 selectCardByValue: function(newCard, opt_animate) { | 313 selectCardByValue: function(newCard, opt_animate) { |
310 var i = this.cards_.indexOf(newCard); | 314 var i = this.cards_.indexOf(newCard); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 // Stop listening to any current touch | 423 // Stop listening to any current touch |
420 this.touchHandler_.cancelTouch(); | 424 this.touchHandler_.cancelTouch(); |
421 | 425 |
422 // Ensure we're at a card bounary | 426 // Ensure we're at a card bounary |
423 this.transformToCurrentCard_(true); | 427 this.transformToCurrentCard_(true); |
424 }, | 428 }, |
425 }; | 429 }; |
426 | 430 |
427 return CardSlider; | 431 return CardSlider; |
428 })(); | 432 })(); |
OLD | NEW |