Index: chrome/browser/resources/ntp4/new_tab.js |
diff --git a/chrome/browser/resources/ntp4/new_tab.js b/chrome/browser/resources/ntp4/new_tab.js |
index 981476b0de196da0602a2ae280859b4947626b68..039e3c83954f18519c875c51d1d081c1de68818a 100644 |
--- a/chrome/browser/resources/ntp4/new_tab.js |
+++ b/chrome/browser/resources/ntp4/new_tab.js |
@@ -146,9 +146,10 @@ cr.define('ntp4', function() { |
var DEFAULT_TRANSITION_TIME = 500; |
/** |
- * Invoked at startup once the DOM is available to initialize the app. |
+ * Sets up the app using given config. |
+ * @param {Object} config Config object. |
*/ |
- function initialize() { |
+ function setup(config) { |
cr.enablePlatformSpecificCSSRules(); |
// Load the current theme colors. |
@@ -162,8 +163,8 @@ cr.define('ntp4', function() { |
trash = getRequiredElement('trash'); |
new ntp4.Trash(trash); |
- shownPage = templateData['shown_page_type']; |
- shownPageIndex = templateData['shown_page_index']; |
+ shownPage = config.shownPage; |
+ shownPageIndex = config.shownPageIndex; |
// Request data on the apps so we can fill them in. |
// Note that this is kicked off asynchronously. 'getAppsCallback' will be |
@@ -179,14 +180,18 @@ cr.define('ntp4', function() { |
tilePages = pageList.getElementsByClassName('tile-page'); |
appsPages = pageList.getElementsByClassName('apps-page'); |
- pageSwitcherStart = getRequiredElement('page-switcher-start'); |
- ntp4.initializePageSwitcher(pageSwitcherStart); |
- pageSwitcherEnd = getRequiredElement('page-switcher-end'); |
- ntp4.initializePageSwitcher(pageSwitcherEnd); |
+ if (config.supportsPageSwitchers) { |
Evan Stade
2011/11/03 16:42:14
this seems like a heck of a lot of if configs, esp
|
+ pageSwitcherStart = getRequiredElement('page-switcher-start'); |
+ ntp4.initializePageSwitcher(pageSwitcherStart); |
+ pageSwitcherEnd = getRequiredElement('page-switcher-end'); |
+ ntp4.initializePageSwitcher(pageSwitcherEnd); |
+ } |
- notificationContainer = getRequiredElement('notification-container'); |
- notificationContainer.addEventListener( |
- 'webkitTransitionEnd', onNotificationTransitionEnd); |
+ if (config.supportsNotification) { |
+ notificationContainer = getRequiredElement('notification-container'); |
+ notificationContainer.addEventListener( |
+ 'webkitTransitionEnd', onNotificationTransitionEnd); |
+ } |
// Initialize the cardSlider without any cards at the moment |
var sliderFrame = getRequiredElement('card-slider-frame'); |
@@ -204,13 +209,17 @@ cr.define('ntp4', function() { |
CardSlider.EventType.CARD_CHANGED, |
cardChangedHandler); |
- cr.ui.decorate($('recently-closed-menu-button'), ntp4.RecentMenuButton); |
- chrome.send('getRecentlyClosedTabs'); |
+ if (config.supportsRecentlyClosed) { |
+ cr.ui.decorate($('recently-closed-menu-button'), ntp4.RecentMenuButton); |
+ chrome.send('getRecentlyClosedTabs'); |
+ } |
- mostVisitedPage = new ntp4.MostVisitedPage(); |
- appendTilePage(mostVisitedPage, localStrings.getString('mostvisited'), |
- false); |
- chrome.send('getMostVisited'); |
+ if (config.supportsMostVisited) { |
+ mostVisitedPage = new ntp4.MostVisitedPage(); |
+ appendTilePage(mostVisitedPage, localStrings.getString('mostvisited'), |
+ false); |
+ chrome.send('getMostVisited'); |
+ } |
if (localStrings.getString('login_status_message')) { |
Evan Stade
2011/11/03 16:42:14
seems this should also be toggled by supportsSyncL
|
loginBubble = new cr.ui.Bubble; |
@@ -260,8 +269,7 @@ cr.define('ntp4', function() { |
infoBubble.show(); |
} |
- var bookmarkFeatures = localStrings.getString('bookmark_features'); |
- if (bookmarkFeatures == 'true') { |
+ if (config.supportsBookmarks) { |
bookmarksPage = new ntp4.BookmarksPage(); |
appendTilePage(bookmarksPage, localStrings.getString('bookmarksPage'), |
false); |
@@ -276,13 +284,15 @@ cr.define('ntp4', function() { |
chrome.send('notificationPromoViewed'); |
} |
- var loginContainer = getRequiredElement('login-container'); |
- loginContainer.addEventListener('click', function() { |
- var rect = loginContainer.getBoundingClientRect(); |
- chrome.send('showSyncLoginUI', |
- [rect.left, rect.top, rect.width, rect.height]); |
- }); |
- chrome.send('initializeSyncLogin'); |
+ if (config.supportsSyncLogin) { |
+ var loginContainer = getRequiredElement('login-container'); |
+ loginContainer.addEventListener('click', function() { |
+ var rect = loginContainer.getBoundingClientRect(); |
+ chrome.send('showSyncLoginUI', |
+ [rect.left, rect.top, rect.width, rect.height]); |
+ }); |
+ chrome.send('initializeSyncLogin'); |
+ } |
} |
/** |
@@ -711,6 +721,9 @@ cr.define('ntp4', function() { |
* layout of the current card. |
*/ |
function updatePageSwitchers() { |
+ if (!pageSwitcherStart || !pageSwitcherEnd) |
+ return; |
+ |
var page = cardSlider.currentCardValue; |
pageSwitcherStart.hidden = !page || (cardSlider.currentCard == 0); |
@@ -748,7 +761,11 @@ cr.define('ntp4', function() { |
// TODO(estade): rename newtab.css to new_tab_theme.css |
function themeChanged(hasAttribution) { |
- $('themecss').href = 'chrome://theme/css/newtab.css?' + Date.now(); |
+ var themecss = $('themecss'); |
+ if (!themecss) |
+ return; |
+ |
+ themecss.href = 'chrome://theme/css/newtab.css?' + Date.now(); |
if (typeof hasAttribution != 'undefined') |
document.documentElement.setAttribute('hasattribution', hasAttribution); |
updateLogo(); |
@@ -998,7 +1015,6 @@ cr.define('ntp4', function() { |
getAppsCallback: getAppsCallback, |
getAppsPageIndex: getAppsPageIndex, |
getCardSlider: getCardSlider, |
- initialize: initialize, |
isRTL: isRTL, |
leaveRearrangeMode: leaveRearrangeMode, |
saveAppPageName: saveAppPageName, |
@@ -1007,6 +1023,7 @@ cr.define('ntp4', function() { |
setMostVisitedPages: setMostVisitedPages, |
setRecentlyClosedTabs: setRecentlyClosedTabs, |
setStripeColor: setStripeColor, |
+ setup: setup, |
showNotification: showNotification, |
themeChanged: themeChanged, |
updateLogin: updateLogin, |
@@ -1025,6 +1042,5 @@ var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; |
var setMostVisitedPages = ntp4.setMostVisitedPages; |
var updateLogin = ntp4.updateLogin; |
-document.addEventListener('DOMContentLoaded', ntp4.initialize); |
window.addEventListener('online', ntp4.updateOfflineEnabledApps); |
window.addEventListener('offline', ntp4.updateOfflineEnabledApps); |