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 PageListView implementation. | 6 * @fileoverview PageListView implementation. |
7 * PageListView manages page list, dot list, switcher buttons and handles apps | 7 * PageListView manages page list, dot list, switcher buttons and handles apps |
8 * pages callbacks from backend. | 8 * pages callbacks from backend. |
9 * | 9 * |
10 * Note that you need to have AppLauncherHandler in your WebUI to use this code. | 10 * Note that you need to have AppLauncherHandler in your WebUI to use this code. |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 logEvent('apps.layout: ' + (Date.now() - startTime)); | 405 logEvent('apps.layout: ' + (Date.now() - startTime)); |
406 | 406 |
407 // Tell the slider about the pages and mark the current page. | 407 // Tell the slider about the pages and mark the current page. |
408 this.updateSliderCards(); | 408 this.updateSliderCards(); |
409 this.cardSlider.currentCardValue.navigationDot.classList.add('selected'); | 409 this.cardSlider.currentCardValue.navigationDot.classList.add('selected'); |
410 | 410 |
411 if (!this.appsLoaded_) { | 411 if (!this.appsLoaded_) { |
412 this.appsLoaded_ = true; | 412 this.appsLoaded_ = true; |
413 cr.dispatchSimpleEvent(document, 'sectionready', true, true); | 413 cr.dispatchSimpleEvent(document, 'sectionready', true, true); |
414 } | 414 } |
415 $('app-launcher-promo').hidden = | |
416 !loadTimeData.getBoolean('showAppLauncherPromo') || | |
417 this.shownPage != loadTimeData.getInteger('apps_page_id'); | |
415 }, | 418 }, |
416 | 419 |
417 /** | 420 /** |
418 * Called by chrome when a new app has been added to chrome or has been | 421 * Called by chrome when a new app has been added to chrome or has been |
419 * enabled if previously disabled. | 422 * enabled if previously disabled. |
420 * @param {Object} appData A data structure full of relevant information for | 423 * @param {Object} appData A data structure full of relevant information for |
421 * the app. | 424 * the app. |
422 * @param {boolean=} opt_highlight Whether the app about to be added should | 425 * @param {boolean=} opt_highlight Whether the app about to be added should |
423 * be highlighted. | 426 * be highlighted. |
424 */ | 427 */ |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 | 471 |
469 // Set the App dot names. Skip the first dot (Most Visited). | 472 // Set the App dot names. Skip the first dot (Most Visited). |
470 var dots = this.dotList.getElementsByClassName('dot'); | 473 var dots = this.dotList.getElementsByClassName('dot'); |
471 var start = this.mostVisitedPage ? 1 : 0; | 474 var start = this.mostVisitedPage ? 1 : 0; |
472 for (var i = start; i < dots.length; ++i) { | 475 for (var i = start; i < dots.length; ++i) { |
473 dots[i].displayTitle = data.appPageNames[i - start] || ''; | 476 dots[i].displayTitle = data.appPageNames[i - start] || ''; |
474 } | 477 } |
475 }, | 478 }, |
476 | 479 |
477 /** | 480 /** |
481 * Callback invoked by chrome whenever the app launcher promo pref changes. | |
482 * @param {bool} show Identifies if we should show or hide the promo. | |
Dan Beam
2013/03/21 15:45:14
{boolean}
MAD
2013/03/21 16:47:47
Done.
| |
483 */ | |
484 appLauncherPromoPrefChangeCallback: function(show) { | |
485 $('app-launcher-promo').hidden = !show; | |
486 loadTimeData.overrideValues({'showAppLauncherPromo': show}); | |
Dan Beam
2013/03/21 15:45:14
nit: loadTimeData.overrideValues({showAppLauncherP
MAD
2013/03/21 16:47:47
Done.
| |
487 }, | |
488 | |
489 /** | |
478 * Invoked whenever the pages in apps-page-list have changed so that | 490 * Invoked whenever the pages in apps-page-list have changed so that |
479 * the Slider knows about the new elements. | 491 * the Slider knows about the new elements. |
480 */ | 492 */ |
481 updateSliderCards: function() { | 493 updateSliderCards: function() { |
482 var pageNo = Math.max(0, Math.min(this.cardSlider.currentCard, | 494 var pageNo = Math.max(0, Math.min(this.cardSlider.currentCard, |
483 this.tilePages.length - 1)); | 495 this.tilePages.length - 1)); |
484 this.cardSlider.setCards(Array.prototype.slice.call(this.tilePages), | 496 this.cardSlider.setCards(Array.prototype.slice.call(this.tilePages), |
485 pageNo); | 497 pageNo); |
486 switch (this.shownPage) { | 498 switch (this.shownPage) { |
487 case loadTimeData.getInteger('apps_page_id'): | 499 case loadTimeData.getInteger('apps_page_id'): |
488 this.cardSlider.selectCardByValue( | 500 this.cardSlider.selectCardByValue( |
489 this.appsPages[Math.min(this.shownPageIndex, | 501 this.appsPages[Math.min(this.shownPageIndex, |
490 this.appsPages.length - 1)]); | 502 this.appsPages.length - 1)]); |
491 break; | 503 break; |
492 case loadTimeData.getInteger('most_visited_page_id'): | 504 case loadTimeData.getInteger('most_visited_page_id'): |
493 if (this.mostVisitedPage) | 505 if (this.mostVisitedPage) { |
494 this.cardSlider.selectCardByValue(this.mostVisitedPage); | 506 this.cardSlider.selectCardByValue(this.mostVisitedPage); |
507 } else if (loadTimeData.getBoolean('showApps')) { | |
508 // If we don't have a most visited page, we are likely on the | |
509 // chrome://apps page, so set it appropriately so that we can | |
510 // display the app launcher promo. | |
511 this.shownPage = loadTimeData.getInteger('apps_page_id'); | |
Dan Beam
2013/03/21 15:45:14
^ er, shouldn't you be selectCardByValue()'ing her
MAD
2013/03/21 16:47:47
Yeah, I wasn't sure... Things seems to work anyway
| |
512 } | |
495 break; | 513 break; |
496 case loadTimeData.getInteger('suggestions_page_id'): | 514 case loadTimeData.getInteger('suggestions_page_id'): |
497 if (this.suggestionsPage) | 515 if (this.suggestionsPage) |
498 this.cardSlider.selectCardByValue(this.suggestionsPage); | 516 this.cardSlider.selectCardByValue(this.suggestionsPage); |
517 else if (this.mostVisitedPage) | |
518 this.shownPage = loadTimeData.getInteger('most_visited_page_id'); | |
519 else if (loadTimeData.getBoolean('showApps')) | |
520 this.shownPage = loadTimeData.getInteger('apps_page_id'); | |
499 break; | 521 break; |
500 } | 522 } |
501 }, | 523 }, |
502 | 524 |
503 /** | 525 /** |
504 * Called whenever tiles should be re-arranging themselves out of the way | 526 * Called whenever tiles should be re-arranging themselves out of the way |
505 * of a moving or insert tile. | 527 * of a moving or insert tile. |
506 */ | 528 */ |
507 enterRearrangeMode: function() { | 529 enterRearrangeMode: function() { |
508 if (loadTimeData.getBoolean('showApps')) { | 530 if (loadTimeData.getBoolean('showApps')) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
644 * Saves/updates the newly selected page to open when first loading the NTP. | 666 * Saves/updates the newly selected page to open when first loading the NTP. |
645 * @type {number} shownPage The new shown page type. | 667 * @type {number} shownPage The new shown page type. |
646 * @type {number} shownPageIndex The new shown page index. | 668 * @type {number} shownPageIndex The new shown page index. |
647 * @private | 669 * @private |
648 */ | 670 */ |
649 setShownPage_: function(shownPage, shownPageIndex) { | 671 setShownPage_: function(shownPage, shownPageIndex) { |
650 assert(shownPageIndex >= 0); | 672 assert(shownPageIndex >= 0); |
651 this.shownPage = shownPage; | 673 this.shownPage = shownPage; |
652 this.shownPageIndex = shownPageIndex; | 674 this.shownPageIndex = shownPageIndex; |
653 chrome.send('pageSelected', [this.shownPage, this.shownPageIndex]); | 675 chrome.send('pageSelected', [this.shownPage, this.shownPageIndex]); |
676 $('app-launcher-promo').hidden = | |
677 !loadTimeData.getBoolean('showAppLauncherPromo') || | |
678 this.shownPage != loadTimeData.getInteger('apps_page_id'); | |
Dan Beam
2013/03/21 15:45:14
please combine this and the same code above into a
MAD
2013/03/21 16:47:47
Done.
And it made me realize that if we would chan
| |
654 }, | 679 }, |
655 | 680 |
656 /** | 681 /** |
657 * Listen for card additions to update the page switchers or the current | 682 * Listen for card additions to update the page switchers or the current |
658 * card accordingly. | 683 * card accordingly. |
659 * @param {Event} e A card removed or added event. | 684 * @param {Event} e A card removed or added event. |
660 */ | 685 */ |
661 onCardAdded_: function(e) { | 686 onCardAdded_: function(e) { |
662 // When the second arg passed to insertBefore is falsey, it acts just like | 687 // When the second arg passed to insertBefore is falsey, it acts just like |
663 // appendChild. | 688 // appendChild. |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
769 if (page.navigationDot) | 794 if (page.navigationDot) |
770 page.navigationDot.remove(opt_animate); | 795 page.navigationDot.remove(opt_animate); |
771 this.cardSlider.removeCard(page); | 796 this.cardSlider.removeCard(page); |
772 }, | 797 }, |
773 }; | 798 }; |
774 | 799 |
775 return { | 800 return { |
776 PageListView: PageListView | 801 PageListView: PageListView |
777 }; | 802 }; |
778 }); | 803 }); |
OLD | NEW |