| 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 New tab page | 6 * @fileoverview New tab page |
| 7 * This is the main code for the new tab page. NewTabView manages page list, | 7 * This is the main code for the new tab page. NewTabView manages page list, |
| 8 * dot list and handles apps pages callbacks from backend. It also handles | 8 * dot list and handles apps pages callbacks from backend. It also handles |
| 9 * the layout of the Bottom Panel and the global UI states of the New Tab Page. | 9 * the layout of the Bottom Panel and the global UI states of the New Tab Page. |
| 10 */ | 10 */ |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 * be highlighted. | 475 * be highlighted. |
| 476 */ | 476 */ |
| 477 appAdded: function(data, opt_highlight) { | 477 appAdded: function(data, opt_highlight) { |
| 478 assert(loadTimeData.getBoolean('showApps')); | 478 assert(loadTimeData.getBoolean('showApps')); |
| 479 | 479 |
| 480 if (data.id == this.highlightAppId) { | 480 if (data.id == this.highlightAppId) { |
| 481 opt_highlight = true; | 481 opt_highlight = true; |
| 482 this.highlightAppId = null; | 482 this.highlightAppId = null; |
| 483 } | 483 } |
| 484 | 484 |
| 485 var pageIndex = data.page_index || 0; | 485 if (!this.appsLoaded_) |
| 486 opt_highlight = false; |
| 486 | 487 |
| 487 var app = $(data.id); | 488 var app = $(data.id); |
| 488 if (app) { | 489 if (app) { |
| 489 app.replaceAppData(data); | 490 app.replaceAppData(data); |
| 490 } else if (opt_highlight) { | 491 } else if (opt_highlight) { |
| 491 this.appsPage.insertAndHighlightApp(data); | 492 this.appsPage.insertAndHighlightApp(data); |
| 492 this.setShownPage_(loadTimeData.getInteger('apps_page_id'), | 493 this.setShownPage_(loadTimeData.getInteger('apps_page_id'), |
| 493 data.page_index); | 494 data.page_index); |
| 494 } else { | 495 } else { |
| 495 this.appsPage.insertApp(data, false); | 496 this.appsPage.insertApp(data, false); |
| 496 } | 497 } |
| 497 }, | 498 }, |
| 498 | 499 |
| 499 /** | 500 /** |
| 500 * Callback invoked by chrome whenever an app preference changes. | 501 * Callback invoked by chrome whenever an app preference changes. |
| 501 * @param {Object} data An object with all the data on available | 502 * @param {Object} data An object with all the data on available |
| 502 * applications. | 503 * applications. |
| 503 */ | 504 */ |
| 504 appsPrefChangedCallback: function(data) { | 505 appsPrefChangedCallback: function(data) { |
| 505 assert(loadTimeData.getBoolean('showApps')); | 506 assert(loadTimeData.getBoolean('showApps')); |
| 506 | 507 |
| 507 for (var i = 0; i < data.apps.length; ++i) { | 508 for (var i = 0; i < data.apps.length; ++i) { |
| 508 $(data.apps[i].id).data = data.apps[i]; | 509 var element = $(data.apps[i].id); |
| 510 if (element) |
| 511 element.data = data.apps[i]; |
| 509 } | 512 } |
| 510 }, | 513 }, |
| 511 | 514 |
| 512 /** | 515 /** |
| 513 * Invoked whenever the pages in page-list have changed so that the | 516 * Invoked whenever the pages in page-list have changed so that the |
| 514 * CardSlider knows about the new elements. | 517 * CardSlider knows about the new elements. |
| 515 */ | 518 */ |
| 516 updateSliderCards: function() { | 519 updateSliderCards: function() { |
| 517 var pageNo = Math.max(0, Math.min(this.cardSlider.currentCard, | 520 var pageNo = Math.max(0, Math.min(this.cardSlider.currentCard, |
| 518 this.tilePages.length - 1)); | 521 this.tilePages.length - 1)); |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 */ | 789 */ |
| 787 showBottomPanel_: function(show) { | 790 showBottomPanel_: function(show) { |
| 788 $('bottom-panel').classList.toggle('hide-bottom-panel', !show); | 791 $('bottom-panel').classList.toggle('hide-bottom-panel', !show); |
| 789 }, | 792 }, |
| 790 }; | 793 }; |
| 791 | 794 |
| 792 /** | 795 /** |
| 793 * Invoked at startup once the DOM is available to initialize the app. | 796 * Invoked at startup once the DOM is available to initialize the app. |
| 794 */ | 797 */ |
| 795 function onLoad() { | 798 function onLoad() { |
| 799 |
| 800 if (!loadTimeData.getBoolean('showApps')) |
| 801 cr.dispatchSimpleEvent(document, 'sectionready', true, true); |
| 802 |
| 796 // Load the current theme colors. | 803 // Load the current theme colors. |
| 797 themeChanged(); | 804 themeChanged(); |
| 798 | 805 |
| 799 newTabView = new NewTabView(); | 806 newTabView = new NewTabView(); |
| 800 | 807 |
| 801 bottomPanelOffsetTop = $('bottom-panel').offsetTop; | 808 bottomPanelOffsetTop = $('bottom-panel').offsetTop; |
| 802 headerHeight = $('bottom-panel-header').offsetHeight; | 809 headerHeight = $('bottom-panel-header').offsetHeight; |
| 803 | 810 |
| 804 notificationContainer = getRequiredElement('notification-container'); | 811 notificationContainer = getRequiredElement('notification-container'); |
| 805 | 812 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 document.documentElement.classList.remove('starting-up'); | 877 document.documentElement.classList.remove('starting-up'); |
| 871 | 878 |
| 872 startTime = Date.now(); | 879 startTime = Date.now(); |
| 873 }); | 880 }); |
| 874 } | 881 } |
| 875 | 882 |
| 876 /* | 883 /* |
| 877 * The number of sections to wait on. | 884 * The number of sections to wait on. |
| 878 * @type {number} | 885 * @type {number} |
| 879 */ | 886 */ |
| 880 var sectionsToWaitFor = 1; | 887 var sectionsToWaitFor = 2; |
| 881 | 888 |
| 882 /** | 889 /** |
| 883 * Queued callbacks which lie in wait for all sections to be ready. | 890 * Queued callbacks which lie in wait for all sections to be ready. |
| 884 * @type {!Array} | 891 * @type {!Array} |
| 885 */ | 892 */ |
| 886 var readyCallbacks = []; | 893 var readyCallbacks = []; |
| 887 | 894 |
| 888 /** | 895 /** |
| 889 * Fired as each section of pages becomes ready. | 896 * Fired as each section of pages becomes ready. |
| 890 * @param {Event} e Each page's synthetic DOM event. | 897 * @param {Event} e Each page's synthetic DOM event. |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1125 setRecentlyClosedTabs: noop, | 1132 setRecentlyClosedTabs: noop, |
| 1126 showNotification: showNotification, | 1133 showNotification: showNotification, |
| 1127 themeChanged: themeChanged, | 1134 themeChanged: themeChanged, |
| 1128 updateLogin: noop, | 1135 updateLogin: noop, |
| 1129 }; | 1136 }; |
| 1130 }); | 1137 }); |
| 1131 | 1138 |
| 1132 document.addEventListener('DOMContentLoaded', ntp.onLoad); | 1139 document.addEventListener('DOMContentLoaded', ntp.onLoad); |
| 1133 | 1140 |
| 1134 var toCssPx = cr.ui.toCssPx; | 1141 var toCssPx = cr.ui.toCssPx; |
| OLD | NEW |