| 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 4 | 6 * @fileoverview New tab page 4 |
| 7 * This is the main code for a previous version of the Chrome NTP ("NTP4"). | 7 * This is the main code for a previous version of the Chrome NTP ("NTP4"). |
| 8 * Some parts of this are still used for the chrome://apps page. | 8 * Some parts of this are still used for the chrome://apps page. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 /** | 51 /** |
| 52 * Creates a NewTabView object. NewTabView extends PageListView with | 52 * Creates a NewTabView object. NewTabView extends PageListView with |
| 53 * new tab UI specific logics. | 53 * new tab UI specific logics. |
| 54 * @constructor | 54 * @constructor |
| 55 * @extends {ntp.PageListView} | 55 * @extends {ntp.PageListView} |
| 56 */ | 56 */ |
| 57 function NewTabView() { | 57 function NewTabView() { |
| 58 var pageSwitcherStart; | 58 var pageSwitcherStart; |
| 59 var pageSwitcherEnd; | 59 var pageSwitcherEnd; |
| 60 if (loadTimeData.getValue('showApps')) { | 60 if (loadTimeData.getValue('showApps')) { |
| 61 pageSwitcherStart = /** @type {!ntp.PageSwitcher} */( | 61 pageSwitcherStart = /** @type {!ntp.PageSwitcher} */ ( |
| 62 getRequiredElement('page-switcher-start')); | 62 getRequiredElement('page-switcher-start')); |
| 63 pageSwitcherEnd = /** @type {!ntp.PageSwitcher} */( | 63 pageSwitcherEnd = /** @type {!ntp.PageSwitcher} */ ( |
| 64 getRequiredElement('page-switcher-end')); | 64 getRequiredElement('page-switcher-end')); |
| 65 } | 65 } |
| 66 this.initialize(getRequiredElement('page-list'), | 66 this.initialize( |
| 67 getRequiredElement('dot-list'), | 67 getRequiredElement('page-list'), getRequiredElement('dot-list'), |
| 68 getRequiredElement('card-slider-frame'), | 68 getRequiredElement('card-slider-frame'), getRequiredElement('trash'), |
| 69 getRequiredElement('trash'), | 69 pageSwitcherStart, pageSwitcherEnd); |
| 70 pageSwitcherStart, pageSwitcherEnd); | |
| 71 } | 70 } |
| 72 | 71 |
| 73 // TODO(dbeam): NewTabView is now the only extender of PageListView; these | 72 // TODO(dbeam): NewTabView is now the only extender of PageListView; these |
| 74 // classes should be merged. | 73 // classes should be merged. |
| 75 NewTabView.prototype = {__proto__: ntp.PageListView.prototype}; | 74 NewTabView.prototype = {__proto__: ntp.PageListView.prototype}; |
| 76 | 75 |
| 77 /** | 76 /** |
| 78 * Invoked at startup once the DOM is available to initialize the app. | 77 * Invoked at startup once the DOM is available to initialize the app. |
| 79 */ | 78 */ |
| 80 function onLoad() { | 79 function onLoad() { |
| 81 sectionsToWaitFor = 0; | 80 sectionsToWaitFor = 0; |
| 82 if (loadTimeData.getBoolean('showApps')) { | 81 if (loadTimeData.getBoolean('showApps')) { |
| 83 sectionsToWaitFor++; | 82 sectionsToWaitFor++; |
| 84 if (loadTimeData.getBoolean('showAppLauncherPromo')) { | 83 if (loadTimeData.getBoolean('showAppLauncherPromo')) { |
| 85 $('app-launcher-promo-close-button').addEventListener('click', | 84 $('app-launcher-promo-close-button') |
| 86 function() { chrome.send('stopShowingAppLauncherPromo'); }); | 85 .addEventListener('click', function() { |
| 87 $('apps-promo-learn-more').addEventListener('click', | 86 chrome.send('stopShowingAppLauncherPromo'); |
| 88 function() { chrome.send('onLearnMore'); }); | 87 }); |
| 88 $('apps-promo-learn-more').addEventListener('click', function() { |
| 89 chrome.send('onLearnMore'); |
| 90 }); |
| 89 } | 91 } |
| 90 } | 92 } |
| 91 measureNavDots(); | 93 measureNavDots(); |
| 92 | 94 |
| 93 // Load the current theme colors. | 95 // Load the current theme colors. |
| 94 themeChanged(); | 96 themeChanged(); |
| 95 | 97 |
| 96 newTabView = new NewTabView(); | 98 newTabView = new NewTabView(); |
| 97 | 99 |
| 98 if (!loadTimeData.getBoolean('showWebStoreIcon')) { | 100 if (!loadTimeData.getBoolean('showWebStoreIcon')) { |
| 99 var webStoreIcon = $('chrome-web-store-link'); | 101 var webStoreIcon = $('chrome-web-store-link'); |
| 100 // Not all versions of the NTP have a footer, so this may not exist. | 102 // Not all versions of the NTP have a footer, so this may not exist. |
| 101 if (webStoreIcon) | 103 if (webStoreIcon) |
| 102 webStoreIcon.hidden = true; | 104 webStoreIcon.hidden = true; |
| 103 } else { | 105 } else { |
| 104 var webStoreLink = loadTimeData.getString('webStoreLink'); | 106 var webStoreLink = loadTimeData.getString('webStoreLink'); |
| 105 var url = appendParam(webStoreLink, 'utm_source', 'chrome-ntp-launcher'); | 107 var url = appendParam(webStoreLink, 'utm_source', 'chrome-ntp-launcher'); |
| 106 $('chrome-web-store-link').href = url; | 108 $('chrome-web-store-link').href = url; |
| 107 $('chrome-web-store-link').addEventListener('auxclick', | 109 $('chrome-web-store-link') |
| 108 onChromeWebStoreButtonClick); | 110 .addEventListener('auxclick', onChromeWebStoreButtonClick); |
| 109 $('chrome-web-store-link').addEventListener('click', | 111 $('chrome-web-store-link') |
| 110 onChromeWebStoreButtonClick); | 112 .addEventListener('click', onChromeWebStoreButtonClick); |
| 111 } | 113 } |
| 112 | 114 |
| 113 // We need to wait for all the footer menu setup to be completed before | 115 // We need to wait for all the footer menu setup to be completed before |
| 114 // we can compute its layout. | 116 // we can compute its layout. |
| 115 layoutFooter(); | 117 layoutFooter(); |
| 116 | 118 |
| 117 if (loadTimeData.getString('login_status_message')) { | 119 if (loadTimeData.getString('login_status_message')) { |
| 118 loginBubble = new cr.ui.Bubble; | 120 loginBubble = new cr.ui.Bubble; |
| 119 loginBubble.anchorNode = $('login-container'); | 121 loginBubble.anchorNode = $('login-container'); |
| 120 loginBubble.arrowLocation = cr.ui.ArrowLocation.TOP_END; | 122 loginBubble.arrowLocation = cr.ui.ArrowLocation.TOP_END; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 }); | 156 }); |
| 155 } | 157 } |
| 156 | 158 |
| 157 /** | 159 /** |
| 158 * Launches the chrome web store app with the chrome-ntp-launcher | 160 * Launches the chrome web store app with the chrome-ntp-launcher |
| 159 * source. | 161 * source. |
| 160 * @param {Event} e The click/auxclick event. | 162 * @param {Event} e The click/auxclick event. |
| 161 */ | 163 */ |
| 162 function onChromeWebStoreButtonClick(e) { | 164 function onChromeWebStoreButtonClick(e) { |
| 163 if (e.button > 1) | 165 if (e.button > 1) |
| 164 return; // Ignore buttons other than left and middle. | 166 return; // Ignore buttons other than left and middle. |
| 165 chrome.send('recordAppLaunchByURL', | 167 chrome.send( |
| 166 [encodeURIComponent(this.href), | 168 'recordAppLaunchByURL', |
| 167 ntp.APP_LAUNCH.NTP_WEBSTORE_FOOTER]); | 169 [encodeURIComponent(this.href), ntp.APP_LAUNCH.NTP_WEBSTORE_FOOTER]); |
| 168 } | 170 } |
| 169 | 171 |
| 170 /** | 172 /** |
| 171 * The number of sections to wait on. | 173 * The number of sections to wait on. |
| 172 * @type {number} | 174 * @type {number} |
| 173 */ | 175 */ |
| 174 var sectionsToWaitFor = -1; | 176 var sectionsToWaitFor = -1; |
| 175 | 177 |
| 176 /** | 178 /** |
| 177 * Queued callbacks which lie in wait for all sections to be ready. | 179 * Queued callbacks which lie in wait for all sections to be ready. |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 loginBubble.reposition(); | 300 loginBubble.reposition(); |
| 299 } | 301 } |
| 300 } | 302 } |
| 301 | 303 |
| 302 /** | 304 /** |
| 303 * Show the sync login UI. | 305 * Show the sync login UI. |
| 304 * @param {Event} e The click event. | 306 * @param {Event} e The click event. |
| 305 */ | 307 */ |
| 306 function showSyncLoginUI(e) { | 308 function showSyncLoginUI(e) { |
| 307 var rect = e.currentTarget.getBoundingClientRect(); | 309 var rect = e.currentTarget.getBoundingClientRect(); |
| 308 chrome.send('showSyncLoginUI', | 310 chrome.send( |
| 309 [rect.left, rect.top, rect.width, rect.height]); | 311 'showSyncLoginUI', [rect.left, rect.top, rect.width, rect.height]); |
| 310 } | 312 } |
| 311 | 313 |
| 312 /** | 314 /** |
| 313 * Wrappers to forward the callback to corresponding PageListView member. | 315 * Wrappers to forward the callback to corresponding PageListView member. |
| 314 */ | 316 */ |
| 315 | 317 |
| 316 /** | 318 /** |
| 317 * Called by chrome when a new app has been added to chrome or has been | 319 * Called by chrome when a new app has been added to chrome or has been |
| 318 * enabled if previously disabled. | 320 * enabled if previously disabled. |
| 319 * @param {Object} appData A data structure full of relevant information for | 321 * @param {Object} appData A data structure full of relevant information for |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 setAppToBeHighlighted: setAppToBeHighlighted, | 438 setAppToBeHighlighted: setAppToBeHighlighted, |
| 437 setBookmarkBarAttached: setBookmarkBarAttached, | 439 setBookmarkBarAttached: setBookmarkBarAttached, |
| 438 themeChanged: themeChanged, | 440 themeChanged: themeChanged, |
| 439 updateLogin: updateLogin | 441 updateLogin: updateLogin |
| 440 }; | 442 }; |
| 441 }); | 443 }); |
| 442 | 444 |
| 443 document.addEventListener('DOMContentLoaded', ntp.onLoad); | 445 document.addEventListener('DOMContentLoaded', ntp.onLoad); |
| 444 | 446 |
| 445 var toCssPx = cr.ui.toCssPx; | 447 var toCssPx = cr.ui.toCssPx; |
| OLD | NEW |