| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 used by touch-enabled Chrome | 7 * This is the main code for the new tab page used by touch-enabled Chrome |
| 8 * browsers. For now this is still a prototype. | 8 * browsers. For now this is still a prototype. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 */ | 95 */ |
| 96 var eventTracker = new EventTracker; | 96 var eventTracker = new EventTracker; |
| 97 | 97 |
| 98 /** | 98 /** |
| 99 * Object for accessing localized strings. | 99 * Object for accessing localized strings. |
| 100 * @type {!LocalStrings} | 100 * @type {!LocalStrings} |
| 101 */ | 101 */ |
| 102 var localStrings = new LocalStrings; | 102 var localStrings = new LocalStrings; |
| 103 | 103 |
| 104 /** | 104 /** |
| 105 * If non-null, this is the ID of the app to highlight to the user the next |
| 106 * time getAppsCallback runs. "Highlight" in this case means to switch to |
| 107 * the page and run the new tile animation. |
| 108 * @type {String} |
| 109 */ |
| 110 var highlightAppId = null; |
| 111 |
| 112 /** |
| 105 * The time in milliseconds for most transitions. This should match what's | 113 * The time in milliseconds for most transitions. This should match what's |
| 106 * in new_tab.css. Unfortunately there's no better way to try to time | 114 * in new_tab.css. Unfortunately there's no better way to try to time |
| 107 * something to occur until after a transition has completed. | 115 * something to occur until after a transition has completed. |
| 108 * @type {number} | 116 * @type {number} |
| 109 * @const | 117 * @const |
| 110 */ | 118 */ |
| 111 var DEFAULT_TRANSITION_TIME = 500; | 119 var DEFAULT_TRANSITION_TIME = 500; |
| 112 | 120 |
| 113 /** | 121 /** |
| 114 * Invoked at startup once the DOM is available to initialize the app. | 122 * Invoked at startup once the DOM is available to initialize the app. |
| 115 */ | 123 */ |
| 116 function initialize() { | 124 function initialize() { |
| 117 cr.enablePlatformSpecificCSSRules(); | 125 cr.enablePlatformSpecificCSSRules(); |
| 118 | 126 |
| 119 // Load the current theme colors. | 127 // Load the current theme colors. |
| 120 themeChanged(); | 128 themeChanged(); |
| 121 | 129 |
| 122 dotList = getRequiredElement('dot-list'); | 130 dotList = getRequiredElement('dot-list'); |
| 123 pageList = getRequiredElement('page-list'); | 131 pageList = getRequiredElement('page-list'); |
| 124 trash = getRequiredElement('trash'); | 132 trash = getRequiredElement('trash'); |
| 125 new ntp4.Trash(trash); | 133 new ntp4.Trash(trash); |
| 126 | 134 |
| 127 shownPage = templateData['shown_page_type']; | 135 shownPage = templateData['shown_page_type']; |
| 128 shownPageIndex = templateData['shown_page_index']; | 136 shownPageIndex = templateData['shown_page_index']; |
| 129 | 137 |
| 138 // When a new app has been installed, we will be opened with a hash value |
| 139 // that corresponds to the new app ID. |
| 140 var hash = location.hash; |
| 141 if (hash && hash.indexOf('#app-id=') == 0) { |
| 142 highlightAppId = hash.split('=')[1]; |
| 143 // Clear the hash so if the user bookmarks this page, they'll just get |
| 144 // chrome://newtab/. |
| 145 window.history.replaceState({}, '', '/'); |
| 146 } |
| 147 |
| 130 document.querySelector('#notification button').onclick = function(e) { | 148 document.querySelector('#notification button').onclick = function(e) { |
| 131 hideNotification(); | 149 hideNotification(); |
| 132 }; | 150 }; |
| 133 | 151 |
| 134 // Request data on the apps so we can fill them in. | 152 // Request data on the apps so we can fill them in. |
| 135 // Note that this is kicked off asynchronously. 'getAppsCallback' will be | 153 // Note that this is kicked off asynchronously. 'getAppsCallback' will be |
| 136 // invoked at some point after this function returns. | 154 // invoked at some point after this function returns. |
| 137 chrome.send('getApps'); | 155 chrome.send('getApps'); |
| 138 | 156 |
| 139 // Prevent touch events from triggering any sort of native scrolling | 157 // Prevent touch events from triggering any sort of native scrolling |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 } | 268 } |
| 251 | 269 |
| 252 if (!pageNames || stringListIsEmpty(pageNames)) | 270 if (!pageNames || stringListIsEmpty(pageNames)) |
| 253 pageNames = [localStrings.getString('appDefaultPageName')]; | 271 pageNames = [localStrings.getString('appDefaultPageName')]; |
| 254 | 272 |
| 255 // Sort by launch index | 273 // Sort by launch index |
| 256 apps.sort(function(a, b) { | 274 apps.sort(function(a, b) { |
| 257 return a.app_launch_index - b.app_launch_index; | 275 return a.app_launch_index - b.app_launch_index; |
| 258 }); | 276 }); |
| 259 | 277 |
| 278 // An app to animate (in case it was just installed). |
| 279 var highlightApp; |
| 280 |
| 260 // Add the apps, creating pages as necessary | 281 // Add the apps, creating pages as necessary |
| 261 for (var i = 0; i < apps.length; i++) { | 282 for (var i = 0; i < apps.length; i++) { |
| 262 var app = apps[i]; | 283 var app = apps[i]; |
| 263 var pageIndex = (app.page_index || 0); | 284 var pageIndex = (app.page_index || 0); |
| 264 while (pageIndex >= appsPages.length) { | 285 while (pageIndex >= appsPages.length) { |
| 265 var pageName = ''; | 286 var pageName = ''; |
| 266 if (appsPages.length < pageNames.length) | 287 if (appsPages.length < pageNames.length) |
| 267 pageName = pageNames[appsPages.length]; | 288 pageName = pageNames[appsPages.length]; |
| 268 | 289 |
| 269 var origPageCount = appsPages.length; | 290 var origPageCount = appsPages.length; |
| 270 appendAppsPage(new ntp4.AppsPage(), pageName); | 291 appendAppsPage(new ntp4.AppsPage(), pageName); |
| 271 // Confirm that appsPages is a live object, updated when a new page is | 292 // Confirm that appsPages is a live object, updated when a new page is |
| 272 // added (otherwise we'd have an infinite loop) | 293 // added (otherwise we'd have an infinite loop) |
| 273 assert(appsPages.length == origPageCount + 1, 'expected new page'); | 294 assert(appsPages.length == origPageCount + 1, 'expected new page'); |
| 274 } | 295 } |
| 275 | 296 |
| 276 appsPages[pageIndex].appendApp(app); | 297 if (app.id == highlightAppId) { |
| 298 highlightApp = app; |
| 299 highlightAppId = null; |
| 300 } else { |
| 301 appsPages[pageIndex].appendApp(app); |
| 302 } |
| 277 } | 303 } |
| 278 | 304 |
| 279 ntp4.AppsPage.setPromo(data.showPromo ? data : null); | 305 ntp4.AppsPage.setPromo(data.showPromo ? data : null); |
| 280 | 306 |
| 281 // Tell the slider about the pages | 307 // Tell the slider about the pages |
| 282 updateSliderCards(); | 308 updateSliderCards(); |
| 283 | 309 |
| 310 if (highlightApp) |
| 311 appAdded(highlightApp); |
| 312 |
| 284 // Mark the current page | 313 // Mark the current page |
| 285 dots[cardSlider.currentCard].classList.add('selected'); | 314 dots[cardSlider.currentCard].classList.add('selected'); |
| 286 logEvent('apps.layout: ' + (Date.now() - startTime)); | 315 logEvent('apps.layout: ' + (Date.now() - startTime)); |
| 287 } | 316 } |
| 288 | 317 |
| 289 /** | 318 /** |
| 290 * Called by chrome when a new app has been added to chrome. | 319 * Called by chrome when a new app has been added to chrome. |
| 291 * @param {Object} app A data structure full of relevant information for the | 320 * @param {Object} app A data structure full of relevant information for the |
| 292 * app. | 321 * app. |
| 293 */ | 322 */ |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 // TODO(estade): update the content handlers to use ntp namespace instead of | 710 // TODO(estade): update the content handlers to use ntp namespace instead of |
| 682 // making these global. | 711 // making these global. |
| 683 var assert = ntp4.assert; | 712 var assert = ntp4.assert; |
| 684 var getAppsCallback = ntp4.getAppsCallback; | 713 var getAppsCallback = ntp4.getAppsCallback; |
| 685 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; | 714 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; |
| 686 var themeChanged = ntp4.themeChanged; | 715 var themeChanged = ntp4.themeChanged; |
| 687 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; | 716 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; |
| 688 var setMostVisitedPages = ntp4.setMostVisitedPages; | 717 var setMostVisitedPages = ntp4.setMostVisitedPages; |
| 689 | 718 |
| 690 document.addEventListener('DOMContentLoaded', ntp4.initialize); | 719 document.addEventListener('DOMContentLoaded', ntp4.initialize); |
| OLD | NEW |