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

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

Issue 9358073: First version of the time slicing on the urls. Not ready for review yet. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added relative time to time slicing Created 8 years, 9 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 | Annotate | Revision Log
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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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.
439 */ 441 */
440 selectCard: function(newCardIndex, opt_animate, opt_dontNotify) { 442 selectCard: function(newCardIndex,
443 opt_animate,
444 opt_dontNotify,
445 opt_forceChange) {
441 this.assertValidIndex_(newCardIndex); 446 this.assertValidIndex_(newCardIndex);
442 447
443 var previousCard = this.currentCardValue; 448 var previousCard = this.currentCardValue;
444 var isChangingCard = 449 var isChangingCard =
445 !this.cards_[newCardIndex].classList.contains('selected-card'); 450 !this.cards_[newCardIndex].classList.contains('selected-card');
446 451
452 if (typeof opt_forceChange != 'undefined' && opt_forceChange)
453 isChangingCard = true;
454
447 if (isChangingCard) { 455 if (isChangingCard) {
448 if (previousCard) 456 if (previousCard)
449 previousCard.classList.remove('selected-card'); 457 previousCard.classList.remove('selected-card');
450 this.currentCard_ = newCardIndex; 458 this.currentCard_ = newCardIndex;
451 this.currentCardValue.classList.add('selected-card'); 459 this.currentCardValue.classList.add('selected-card');
452 } 460 }
453 461
454 var willTransitionHappen = this.transformToCurrentCard_(opt_animate); 462 var willTransitionHappen = this.transformToCurrentCard_(opt_animate);
455 463
456 if (isChangingCard && !opt_dontNotify) { 464 if (isChangingCard && !opt_dontNotify) {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 614
607 // Ensure we're at a card bounary 615 // Ensure we're at a card bounary
608 this.transformToCurrentCard_(true); 616 this.transformToCurrentCard_(true);
609 }, 617 },
610 }; 618 };
611 619
612 return { 620 return {
613 CardSlider: CardSlider 621 CardSlider: CardSlider
614 }; 622 };
615 }); 623 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/ntp4/suggestions_page.js ('k') | chrome/browser/ui/webui/ntp/new_tab_page_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698