Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1001)

Side by Side Diff: chrome/browser/resources/ntp4/new_tab.js

Issue 8423055: [Aura] Initial app list webui. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix chromeos bot compilation error Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 /** 139 /**
140 * The time in milliseconds for most transitions. This should match what's 140 * The time in milliseconds for most transitions. This should match what's
141 * in new_tab.css. Unfortunately there's no better way to try to time 141 * in new_tab.css. Unfortunately there's no better way to try to time
142 * something to occur until after a transition has completed. 142 * something to occur until after a transition has completed.
143 * @type {number} 143 * @type {number}
144 * @const 144 * @const
145 */ 145 */
146 var DEFAULT_TRANSITION_TIME = 500; 146 var DEFAULT_TRANSITION_TIME = 500;
147 147
148 /** 148 /**
149 * Invoked at startup once the DOM is available to initialize the app. 149 * Sets up the app using given config.
150 * @param {Object} config Config object.
150 */ 151 */
151 function initialize() { 152 function setup(config) {
152 cr.enablePlatformSpecificCSSRules(); 153 cr.enablePlatformSpecificCSSRules();
153 154
154 // Load the current theme colors. 155 // Load the current theme colors.
155 themeChanged(); 156 themeChanged();
156 157
157 dotList = getRequiredElement('dot-list'); 158 dotList = getRequiredElement('dot-list');
158 dotList.addEventListener('keydown', onDotListKeyDown); 159 dotList.addEventListener('keydown', onDotListKeyDown);
159 navDots = dotList.getElementsByClassName('dot'); 160 navDots = dotList.getElementsByClassName('dot');
160 161
161 pageList = getRequiredElement('page-list'); 162 pageList = getRequiredElement('page-list');
162 trash = getRequiredElement('trash'); 163 trash = getRequiredElement('trash');
163 new ntp4.Trash(trash); 164 new ntp4.Trash(trash);
164 165
165 shownPage = templateData['shown_page_type']; 166 shownPage = config.shownPage;
166 shownPageIndex = templateData['shown_page_index']; 167 shownPageIndex = config.shownPageIndex;
167 168
168 // Request data on the apps so we can fill them in. 169 // Request data on the apps so we can fill them in.
169 // Note that this is kicked off asynchronously. 'getAppsCallback' will be 170 // Note that this is kicked off asynchronously. 'getAppsCallback' will be
170 // invoked at some point after this function returns. 171 // invoked at some point after this function returns.
171 chrome.send('getApps'); 172 chrome.send('getApps');
172 173
173 document.addEventListener('keydown', onKeyDown); 174 document.addEventListener('keydown', onKeyDown);
174 // Prevent touch events from triggering any sort of native scrolling 175 // Prevent touch events from triggering any sort of native scrolling
175 document.addEventListener('touchmove', function(e) { 176 document.addEventListener('touchmove', function(e) {
176 e.preventDefault(); 177 e.preventDefault();
177 }, true); 178 }, true);
178 179
179 tilePages = pageList.getElementsByClassName('tile-page'); 180 tilePages = pageList.getElementsByClassName('tile-page');
180 appsPages = pageList.getElementsByClassName('apps-page'); 181 appsPages = pageList.getElementsByClassName('apps-page');
181 182
182 pageSwitcherStart = getRequiredElement('page-switcher-start'); 183 if (config.supportsPageSwitchers) {
Evan Stade 2011/11/03 16:42:14 this seems like a heck of a lot of if configs, esp
183 ntp4.initializePageSwitcher(pageSwitcherStart); 184 pageSwitcherStart = getRequiredElement('page-switcher-start');
184 pageSwitcherEnd = getRequiredElement('page-switcher-end'); 185 ntp4.initializePageSwitcher(pageSwitcherStart);
185 ntp4.initializePageSwitcher(pageSwitcherEnd); 186 pageSwitcherEnd = getRequiredElement('page-switcher-end');
187 ntp4.initializePageSwitcher(pageSwitcherEnd);
188 }
186 189
187 notificationContainer = getRequiredElement('notification-container'); 190 if (config.supportsNotification) {
188 notificationContainer.addEventListener( 191 notificationContainer = getRequiredElement('notification-container');
189 'webkitTransitionEnd', onNotificationTransitionEnd); 192 notificationContainer.addEventListener(
193 'webkitTransitionEnd', onNotificationTransitionEnd);
194 }
190 195
191 // Initialize the cardSlider without any cards at the moment 196 // Initialize the cardSlider without any cards at the moment
192 var sliderFrame = getRequiredElement('card-slider-frame'); 197 var sliderFrame = getRequiredElement('card-slider-frame');
193 cardSlider = new CardSlider(sliderFrame, pageList, sliderFrame.offsetWidth); 198 cardSlider = new CardSlider(sliderFrame, pageList, sliderFrame.offsetWidth);
194 cardSlider.initialize(); 199 cardSlider.initialize();
195 200
196 // Ensure the slider is resized appropriately with the window 201 // Ensure the slider is resized appropriately with the window
197 window.addEventListener('resize', function() { 202 window.addEventListener('resize', function() {
198 cardSlider.resize(sliderFrame.offsetWidth); 203 cardSlider.resize(sliderFrame.offsetWidth);
199 updatePageSwitchers(); 204 updatePageSwitchers();
200 }); 205 });
201 206
202 // Handle the page being changed 207 // Handle the page being changed
203 pageList.addEventListener( 208 pageList.addEventListener(
204 CardSlider.EventType.CARD_CHANGED, 209 CardSlider.EventType.CARD_CHANGED,
205 cardChangedHandler); 210 cardChangedHandler);
206 211
207 cr.ui.decorate($('recently-closed-menu-button'), ntp4.RecentMenuButton); 212 if (config.supportsRecentlyClosed) {
208 chrome.send('getRecentlyClosedTabs'); 213 cr.ui.decorate($('recently-closed-menu-button'), ntp4.RecentMenuButton);
214 chrome.send('getRecentlyClosedTabs');
215 }
209 216
210 mostVisitedPage = new ntp4.MostVisitedPage(); 217 if (config.supportsMostVisited) {
211 appendTilePage(mostVisitedPage, localStrings.getString('mostvisited'), 218 mostVisitedPage = new ntp4.MostVisitedPage();
212 false); 219 appendTilePage(mostVisitedPage, localStrings.getString('mostvisited'),
213 chrome.send('getMostVisited'); 220 false);
221 chrome.send('getMostVisited');
222 }
214 223
215 if (localStrings.getString('login_status_message')) { 224 if (localStrings.getString('login_status_message')) {
Evan Stade 2011/11/03 16:42:14 seems this should also be toggled by supportsSyncL
216 loginBubble = new cr.ui.Bubble; 225 loginBubble = new cr.ui.Bubble;
217 loginBubble.anchorNode = $('login-container'); 226 loginBubble.anchorNode = $('login-container');
218 loginBubble.setArrowLocation(cr.ui.ArrowLocation.TOP_END); 227 loginBubble.setArrowLocation(cr.ui.ArrowLocation.TOP_END);
219 loginBubble.bubbleAlignment = 228 loginBubble.bubbleAlignment =
220 cr.ui.BubbleAlignment.BUBBLE_EDGE_TO_ANCHOR_EDGE; 229 cr.ui.BubbleAlignment.BUBBLE_EDGE_TO_ANCHOR_EDGE;
221 loginBubble.deactivateToDismissDelay = 2000; 230 loginBubble.deactivateToDismissDelay = 2000;
222 loginBubble.setCloseButtonVisible(false); 231 loginBubble.setCloseButtonVisible(false);
223 232
224 var bubbleContent = $('login-status-bubble-contents'); 233 var bubbleContent = $('login-status-bubble-contents');
225 loginBubble.content = bubbleContent; 234 loginBubble.content = bubbleContent;
(...skipping 27 matching lines...) Expand all
253 infoBubble.content = bubbleContent; 262 infoBubble.content = bubbleContent;
254 bubbleContent.hidden = false; 263 bubbleContent.hidden = false;
255 264
256 var learnMoreLink = infoBubble.querySelector('a'); 265 var learnMoreLink = infoBubble.querySelector('a');
257 learnMoreLink.href = localStrings.getString('ntp4_intro_url'); 266 learnMoreLink.href = localStrings.getString('ntp4_intro_url');
258 learnMoreLink.onclick = infoBubble.hide.bind(infoBubble); 267 learnMoreLink.onclick = infoBubble.hide.bind(infoBubble);
259 268
260 infoBubble.show(); 269 infoBubble.show();
261 } 270 }
262 271
263 var bookmarkFeatures = localStrings.getString('bookmark_features'); 272 if (config.supportsBookmarks) {
264 if (bookmarkFeatures == 'true') {
265 bookmarksPage = new ntp4.BookmarksPage(); 273 bookmarksPage = new ntp4.BookmarksPage();
266 appendTilePage(bookmarksPage, localStrings.getString('bookmarksPage'), 274 appendTilePage(bookmarksPage, localStrings.getString('bookmarksPage'),
267 false); 275 false);
268 chrome.send('getBookmarksData'); 276 chrome.send('getBookmarksData');
269 } 277 }
270 278
271 var serverpromo = localStrings.getString('serverpromo'); 279 var serverpromo = localStrings.getString('serverpromo');
Evan Stade 2011/11/03 16:42:14 and I don't think you want this either
272 if (serverpromo) { 280 if (serverpromo) {
273 showNotification(parseHtmlSubset(serverpromo), [], function() { 281 showNotification(parseHtmlSubset(serverpromo), [], function() {
274 chrome.send('closeNotificationPromo'); 282 chrome.send('closeNotificationPromo');
275 }, 60000); 283 }, 60000);
276 chrome.send('notificationPromoViewed'); 284 chrome.send('notificationPromoViewed');
277 } 285 }
278 286
279 var loginContainer = getRequiredElement('login-container'); 287 if (config.supportsSyncLogin) {
280 loginContainer.addEventListener('click', function() { 288 var loginContainer = getRequiredElement('login-container');
281 var rect = loginContainer.getBoundingClientRect(); 289 loginContainer.addEventListener('click', function() {
282 chrome.send('showSyncLoginUI', 290 var rect = loginContainer.getBoundingClientRect();
283 [rect.left, rect.top, rect.width, rect.height]); 291 chrome.send('showSyncLoginUI',
284 }); 292 [rect.left, rect.top, rect.width, rect.height]);
285 chrome.send('initializeSyncLogin'); 293 });
294 chrome.send('initializeSyncLogin');
295 }
286 } 296 }
287 297
288 /** 298 /**
289 * Simple common assertion API 299 * Simple common assertion API
290 * @param {*} condition The condition to test. Note that this may be used to 300 * @param {*} condition The condition to test. Note that this may be used to
291 * test whether a value is defined or not, and we don't want to force a 301 * test whether a value is defined or not, and we don't want to force a
292 * cast to Boolean. 302 * cast to Boolean.
293 * @param {string=} opt_message A message to use in any error. 303 * @param {string=} opt_message A message to use in any error.
294 */ 304 */
295 function assert(condition, opt_message) { 305 function assert(condition, opt_message) {
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 } 714 }
705 715
706 updatePageSwitchers(); 716 updatePageSwitchers();
707 } 717 }
708 718
709 /** 719 /**
710 * Adjusts the size and position of the page switchers according to the 720 * Adjusts the size and position of the page switchers according to the
711 * layout of the current card. 721 * layout of the current card.
712 */ 722 */
713 function updatePageSwitchers() { 723 function updatePageSwitchers() {
724 if (!pageSwitcherStart || !pageSwitcherEnd)
725 return;
726
714 var page = cardSlider.currentCardValue; 727 var page = cardSlider.currentCardValue;
715 728
716 pageSwitcherStart.hidden = !page || (cardSlider.currentCard == 0); 729 pageSwitcherStart.hidden = !page || (cardSlider.currentCard == 0);
717 pageSwitcherEnd.hidden = !page || 730 pageSwitcherEnd.hidden = !page ||
718 (cardSlider.currentCard == cardSlider.cardCount - 1); 731 (cardSlider.currentCard == cardSlider.cardCount - 1);
719 732
720 if (!page) 733 if (!page)
721 return; 734 return;
722 735
723 var pageSwitcherLeft = isRTL() ? pageSwitcherEnd : pageSwitcherStart; 736 var pageSwitcherLeft = isRTL() ? pageSwitcherEnd : pageSwitcherStart;
(...skipping 17 matching lines...) Expand all
741 * Returns the index of the given page. 754 * Returns the index of the given page.
742 * @param {AppsPage} page The AppsPage for we wish to find. 755 * @param {AppsPage} page The AppsPage for we wish to find.
743 * @return {number} The index of |page|, or -1 if it is not here. 756 * @return {number} The index of |page|, or -1 if it is not here.
744 */ 757 */
745 function getAppsPageIndex(page) { 758 function getAppsPageIndex(page) {
746 return Array.prototype.indexOf.call(appsPages, page); 759 return Array.prototype.indexOf.call(appsPages, page);
747 } 760 }
748 761
749 // TODO(estade): rename newtab.css to new_tab_theme.css 762 // TODO(estade): rename newtab.css to new_tab_theme.css
750 function themeChanged(hasAttribution) { 763 function themeChanged(hasAttribution) {
751 $('themecss').href = 'chrome://theme/css/newtab.css?' + Date.now(); 764 var themecss = $('themecss');
765 if (!themecss)
766 return;
767
768 themecss.href = 'chrome://theme/css/newtab.css?' + Date.now();
752 if (typeof hasAttribution != 'undefined') 769 if (typeof hasAttribution != 'undefined')
753 document.documentElement.setAttribute('hasattribution', hasAttribution); 770 document.documentElement.setAttribute('hasattribution', hasAttribution);
754 updateLogo(); 771 updateLogo();
755 updateAttribution(); 772 updateAttribution();
756 } 773 }
757 774
758 /** 775 /**
759 * Sets the proper image for the logo at the bottom left. 776 * Sets the proper image for the logo at the bottom left.
760 */ 777 */
761 function updateLogo() { 778 function updateLogo() {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 bookmarkImportEnded: bookmarkImportEnded, 1008 bookmarkImportEnded: bookmarkImportEnded,
992 bookmarkNodeAdded: bookmarkNodeAdded, 1009 bookmarkNodeAdded: bookmarkNodeAdded,
993 bookmarkNodeChanged: bookmarkNodeChanged, 1010 bookmarkNodeChanged: bookmarkNodeChanged,
994 bookmarkNodeChildrenReordered: bookmarkNodeChildrenReordered, 1011 bookmarkNodeChildrenReordered: bookmarkNodeChildrenReordered,
995 bookmarkNodeMoved: bookmarkNodeMoved, 1012 bookmarkNodeMoved: bookmarkNodeMoved,
996 bookmarkNodeRemoved: bookmarkNodeRemoved, 1013 bookmarkNodeRemoved: bookmarkNodeRemoved,
997 enterRearrangeMode: enterRearrangeMode, 1014 enterRearrangeMode: enterRearrangeMode,
998 getAppsCallback: getAppsCallback, 1015 getAppsCallback: getAppsCallback,
999 getAppsPageIndex: getAppsPageIndex, 1016 getAppsPageIndex: getAppsPageIndex,
1000 getCardSlider: getCardSlider, 1017 getCardSlider: getCardSlider,
1001 initialize: initialize,
1002 isRTL: isRTL, 1018 isRTL: isRTL,
1003 leaveRearrangeMode: leaveRearrangeMode, 1019 leaveRearrangeMode: leaveRearrangeMode,
1004 saveAppPageName: saveAppPageName, 1020 saveAppPageName: saveAppPageName,
1005 setAppToBeHighlighted: setAppToBeHighlighted, 1021 setAppToBeHighlighted: setAppToBeHighlighted,
1006 setBookmarksData: setBookmarksData, 1022 setBookmarksData: setBookmarksData,
1007 setMostVisitedPages: setMostVisitedPages, 1023 setMostVisitedPages: setMostVisitedPages,
1008 setRecentlyClosedTabs: setRecentlyClosedTabs, 1024 setRecentlyClosedTabs: setRecentlyClosedTabs,
1009 setStripeColor: setStripeColor, 1025 setStripeColor: setStripeColor,
1026 setup: setup,
1010 showNotification: showNotification, 1027 showNotification: showNotification,
1011 themeChanged: themeChanged, 1028 themeChanged: themeChanged,
1012 updateLogin: updateLogin, 1029 updateLogin: updateLogin,
1013 updateOfflineEnabledApps: updateOfflineEnabledApps 1030 updateOfflineEnabledApps: updateOfflineEnabledApps
1014 }; 1031 };
1015 }); 1032 });
1016 1033
1017 // publish ntp globals 1034 // publish ntp globals
1018 // TODO(estade): update the content handlers to use ntp namespace instead of 1035 // TODO(estade): update the content handlers to use ntp namespace instead of
1019 // making these global. 1036 // making these global.
1020 var assert = ntp4.assert; 1037 var assert = ntp4.assert;
1021 var getAppsCallback = ntp4.getAppsCallback; 1038 var getAppsCallback = ntp4.getAppsCallback;
1022 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; 1039 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback;
1023 var themeChanged = ntp4.themeChanged; 1040 var themeChanged = ntp4.themeChanged;
1024 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; 1041 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs;
1025 var setMostVisitedPages = ntp4.setMostVisitedPages; 1042 var setMostVisitedPages = ntp4.setMostVisitedPages;
1026 var updateLogin = ntp4.updateLogin; 1043 var updateLogin = ntp4.updateLogin;
1027 1044
1028 document.addEventListener('DOMContentLoaded', ntp4.initialize);
1029 window.addEventListener('online', ntp4.updateOfflineEnabledApps); 1045 window.addEventListener('online', ntp4.updateOfflineEnabledApps);
1030 window.addEventListener('offline', ntp4.updateOfflineEnabledApps); 1046 window.addEventListener('offline', ntp4.updateOfflineEnabledApps);
OLDNEW
« no previous file with comments | « chrome/browser/resources/ntp4/new_tab.html ('k') | chrome/browser/resources/ntp4/new_tab_init.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698