| 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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 logEvent('apps.layout: ' + (Date.now() - startTime)); | 400 logEvent('apps.layout: ' + (Date.now() - startTime)); |
| 401 | 401 |
| 402 // Tell the slider about the pages and mark the current page. | 402 // Tell the slider about the pages and mark the current page. |
| 403 this.updateSliderCards(); | 403 this.updateSliderCards(); |
| 404 this.cardSlider.currentCardValue.navigationDot.classList.add('selected'); | 404 this.cardSlider.currentCardValue.navigationDot.classList.add('selected'); |
| 405 | 405 |
| 406 if (!this.appsLoaded_) { | 406 if (!this.appsLoaded_) { |
| 407 this.appsLoaded_ = true; | 407 this.appsLoaded_ = true; |
| 408 cr.dispatchSimpleEvent(document, 'sectionready', true, true); | 408 cr.dispatchSimpleEvent(document, 'sectionready', true, true); |
| 409 } | 409 } |
| 410 this.updateAppLauncherPromoHiddenState_(); | |
| 411 }, | 410 }, |
| 412 | 411 |
| 413 /** | 412 /** |
| 414 * Called by chrome when a new app has been added to chrome or has been | 413 * Called by chrome when a new app has been added to chrome or has been |
| 415 * enabled if previously disabled. | 414 * enabled if previously disabled. |
| 416 * @param {AppInfo} appData A data structure full of relevant information | 415 * @param {AppInfo} appData A data structure full of relevant information |
| 417 * for the app. | 416 * for the app. |
| 418 * @param {boolean=} opt_highlight Whether the app about to be added should | 417 * @param {boolean=} opt_highlight Whether the app about to be added should |
| 419 * be highlighted. | 418 * be highlighted. |
| 420 */ | 419 */ |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 } | 461 } |
| 463 | 462 |
| 464 // Set the App dot names. | 463 // Set the App dot names. |
| 465 var dots = this.dotList.getElementsByClassName('dot'); | 464 var dots = this.dotList.getElementsByClassName('dot'); |
| 466 for (var i = 0; i < dots.length; ++i) { | 465 for (var i = 0; i < dots.length; ++i) { |
| 467 dots[i].displayTitle = data.appPageNames[i] || ''; | 466 dots[i].displayTitle = data.appPageNames[i] || ''; |
| 468 } | 467 } |
| 469 }, | 468 }, |
| 470 | 469 |
| 471 /** | 470 /** |
| 472 * Callback invoked by chrome whenever the app launcher promo pref changes. | |
| 473 * @param {boolean} show Identifies if we should show or hide the promo. | |
| 474 */ | |
| 475 appLauncherPromoPrefChangeCallback: function(show) { | |
| 476 loadTimeData.overrideValues({showAppLauncherPromo: show}); | |
| 477 this.updateAppLauncherPromoHiddenState_(); | |
| 478 }, | |
| 479 | |
| 480 /** | |
| 481 * Updates the hidden state of the app launcher promo based on the page | |
| 482 * shown and load data content. | |
| 483 * @private | |
| 484 */ | |
| 485 updateAppLauncherPromoHiddenState_: function() { | |
| 486 $('app-launcher-promo').hidden = | |
| 487 !loadTimeData.getBoolean('showAppLauncherPromo'); | |
| 488 }, | |
| 489 | |
| 490 /** | |
| 491 * Invoked whenever the pages in apps-page-list have changed so that | 471 * Invoked whenever the pages in apps-page-list have changed so that |
| 492 * the Slider knows about the new elements. | 472 * the Slider knows about the new elements. |
| 493 */ | 473 */ |
| 494 updateSliderCards: function() { | 474 updateSliderCards: function() { |
| 495 var pageNo = Math.max(0, Math.min(this.cardSlider.currentCard, | 475 var pageNo = Math.max(0, Math.min(this.cardSlider.currentCard, |
| 496 this.tilePages.length - 1)); | 476 this.tilePages.length - 1)); |
| 497 this.cardSlider.setCards(Array.prototype.slice.call(this.tilePages), | 477 this.cardSlider.setCards(Array.prototype.slice.call(this.tilePages), |
| 498 pageNo); | 478 pageNo); |
| 499 if (loadTimeData.getBoolean('showApps')) { | 479 if (loadTimeData.getBoolean('showApps')) { |
| 500 this.cardSlider.selectCardByValue( | 480 this.cardSlider.selectCardByValue( |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 }, | 619 }, |
| 640 | 620 |
| 641 /** | 621 /** |
| 642 * Saves/updates the newly selected page to open when first loading the NTP. | 622 * Saves/updates the newly selected page to open when first loading the NTP. |
| 643 * @param {number} shownPageIndex The new shown page index. | 623 * @param {number} shownPageIndex The new shown page index. |
| 644 * @private | 624 * @private |
| 645 */ | 625 */ |
| 646 setShownPage_: function(shownPageIndex) { | 626 setShownPage_: function(shownPageIndex) { |
| 647 assert(shownPageIndex >= 0); | 627 assert(shownPageIndex >= 0); |
| 648 this.shownPageIndex = shownPageIndex; | 628 this.shownPageIndex = shownPageIndex; |
| 649 chrome.send('pageSelected', [this.shownPageIndex]); | 629 chrome.send('pageSelected', [this.shownPage, this.shownPageIndex]); |
| 650 this.updateAppLauncherPromoHiddenState_(); | |
| 651 }, | 630 }, |
| 652 | 631 |
| 653 /** | 632 /** |
| 654 * Listen for card additions to update the page switchers or the current | 633 * Listen for card additions to update the page switchers or the current |
| 655 * card accordingly. | 634 * card accordingly. |
| 656 * @param {Event} e A card removed or added event. | 635 * @param {Event} e A card removed or added event. |
| 657 */ | 636 */ |
| 658 onCardAdded_: function(e) { | 637 onCardAdded_: function(e) { |
| 659 // When the second arg passed to insertBefore is falsey, it acts just like | 638 // When the second arg passed to insertBefore is falsey, it acts just like |
| 660 // appendChild. | 639 // appendChild. |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 if (page.navigationDot) | 745 if (page.navigationDot) |
| 767 page.navigationDot.remove(opt_animate); | 746 page.navigationDot.remove(opt_animate); |
| 768 this.cardSlider.removeCard(page); | 747 this.cardSlider.removeCard(page); |
| 769 }, | 748 }, |
| 770 }; | 749 }; |
| 771 | 750 |
| 772 return { | 751 return { |
| 773 PageListView: PageListView | 752 PageListView: PageListView |
| 774 }; | 753 }; |
| 775 }); | 754 }); |
| OLD | NEW |