Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(469)

Side by Side Diff: chrome/browser/resources/shared/js/cr/ui/card_slider.js

Issue 10918241: Make non-visible cards hidden for accessibility in CardSlider. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 * @param {number} index Index of the card to in the new set of cards to 179 * @param {number} index Index of the card to in the new set of cards to
180 * navigate to. 180 * navigate to.
181 */ 181 */
182 setCards: function(cards, index) { 182 setCards: function(cards, index) {
183 assert(index >= 0 && index < cards.length, 183 assert(index >= 0 && index < cards.length,
184 'Invalid index in CardSlider#setCards'); 184 'Invalid index in CardSlider#setCards');
185 this.cards_ = cards; 185 this.cards_ = cards;
186 186
187 this.updateCardWidths_(); 187 this.updateCardWidths_();
188 188
189 // Mark all cards as hidden for accessibility. The selected card will
190 // be marked visible during selectCard().
191 for (var i = 0; i < cards.length; i++)
192 this.cards_[i].setAttribute('aria-hidden', true);
Dan Beam 2012/09/14 02:48:38 nit: 2 \s indent, optionally we usually use curlie
aboxhall 2012/09/14 03:50:37 Done.
193
189 // Jump to the given card index. 194 // Jump to the given card index.
190 this.selectCard(index); 195 this.selectCard(index);
191 }, 196 },
192 197
193 /** 198 /**
194 * Updates the width of each card. 199 * Updates the width of each card.
195 * @private 200 * @private
196 */ 201 */
197 updateCardWidths_: function() { 202 updateCardWidths_: function() {
198 for (var i = 0, card; card = this.cards_[i]; i++) 203 for (var i = 0, card; card = this.cards_[i]; i++)
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 * @param {!Node} card A card that will be added to the card slider. 348 * @param {!Node} card A card that will be added to the card slider.
344 * @param {number} index An index at which the given |card| should be 349 * @param {number} index An index at which the given |card| should be
345 * inserted. Must be positive and less than the number of cards. 350 * inserted. Must be positive and less than the number of cards.
346 */ 351 */
347 addCardAtIndex: function(card, index) { 352 addCardAtIndex: function(card, index) {
348 assert(card instanceof Node, '|card| isn\'t a Node'); 353 assert(card instanceof Node, '|card| isn\'t a Node');
349 this.assertValidIndex_(index); 354 this.assertValidIndex_(index);
350 this.cards_ = Array.prototype.concat.call( 355 this.cards_ = Array.prototype.concat.call(
351 this.cards_.slice(0, index), card, this.cards_.slice(index)); 356 this.cards_.slice(0, index), card, this.cards_.slice(index));
352 357
358 // Mark the new card as hidden for accessibility. This will be corrected
Dan Beam 2012/09/14 02:48:38 nit: 1 \s between sentences
aboxhall 2012/09/14 03:50:37 Done.
359 // during selectCard() if this is the selected card.
360 card.setAttribute('aria-hidden', true);
361
353 if (this.currentCard_ == -1) 362 if (this.currentCard_ == -1)
354 this.currentCard_ = 0; 363 this.currentCard_ = 0;
355 else if (index <= this.currentCard_) 364 else if (index <= this.currentCard_)
356 this.selectCard(this.currentCard_ + 1, false, true, true); 365 this.selectCard(this.currentCard_ + 1, false, true, true);
357 366
358 this.fireAddedEvent_(card, index); 367 this.fireAddedEvent_(card, index);
359 }, 368 },
360 369
361 /** 370 /**
362 * Append a card to the end of the list. 371 * Append a card to the end of the list.
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 this.assertValidIndex_(newCardIndex); 473 this.assertValidIndex_(newCardIndex);
465 474
466 var previousCard = this.currentCardValue; 475 var previousCard = this.currentCardValue;
467 var isChangingCard = 476 var isChangingCard =
468 !this.cards_[newCardIndex].classList.contains('selected-card'); 477 !this.cards_[newCardIndex].classList.contains('selected-card');
469 478
470 if (typeof opt_forceChange != 'undefined' && opt_forceChange) 479 if (typeof opt_forceChange != 'undefined' && opt_forceChange)
471 isChangingCard = true; 480 isChangingCard = true;
472 481
473 if (isChangingCard) { 482 if (isChangingCard) {
474 if (previousCard) 483 if (previousCard) {
475 previousCard.classList.remove('selected-card'); 484 previousCard.classList.remove('selected-card');
485 previousCard.setAttribute('aria-hidden', true);
486 }
476 this.currentCard_ = newCardIndex; 487 this.currentCard_ = newCardIndex;
477 this.currentCardValue.classList.add('selected-card'); 488 this.currentCardValue.classList.add('selected-card');
489 this.currentCardValue.setAttribute('aria-hidden', false);
478 } 490 }
479 491
480 var willTransitionHappen = this.transformToCurrentCard_(opt_animate); 492 var willTransitionHappen = this.transformToCurrentCard_(opt_animate);
481 493
482 if (isChangingCard && !opt_dontNotify) { 494 if (isChangingCard && !opt_dontNotify) {
483 var event = document.createEvent('Event'); 495 var event = document.createEvent('Event');
484 event.initEvent('cardSlider:card_changed', true, true); 496 event.initEvent('cardSlider:card_changed', true, true);
485 event.cardSlider = this; 497 event.cardSlider = this;
486 event.wasAnimated = !!opt_animate; 498 event.wasAnimated = !!opt_animate;
487 this.container_.dispatchEvent(event); 499 this.container_.dispatchEvent(event);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 652
641 // Ensure we're at a card bounary 653 // Ensure we're at a card bounary
642 this.transformToCurrentCard_(true); 654 this.transformToCurrentCard_(true);
643 }, 655 },
644 }; 656 };
645 657
646 return { 658 return {
647 CardSlider: CardSlider 659 CardSlider: CardSlider
648 }; 660 };
649 }); 661 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698