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

Unified Diff: chrome/browser/resources/ntp4/page_list_view.js

Issue 9358031: Added new adaptive "Suggest" tab on the New Tab Page, behing the flag, for the experiments. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed bug in card_slider.js which prevented correct card be selected in dome cases Created 8 years, 10 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/ntp4/page_list_view.js
diff --git a/chrome/browser/resources/ntp4/page_list_view.js b/chrome/browser/resources/ntp4/page_list_view.js
index fc50b56a7d14b807ff730242e542133f30d31ca9..9db9da5cc4515f0fcae9d1e34a9f194eb09db2f9 100644
--- a/chrome/browser/resources/ntp4/page_list_view.js
+++ b/chrome/browser/resources/ntp4/page_list_view.js
@@ -59,6 +59,12 @@ cr.define('ntp4', function() {
appsPages: undefined,
/**
+ * The Suggestions page.
+ * @type {!Element|undefined}
+ */
+ suggestionsPage: undefined,
+
+ /**
* The Most Visited page.
* @type {!Element|undefined}
*/
@@ -199,7 +205,7 @@ cr.define('ntp4', function() {
appendTilePage: function(page, title, titleIsEditable, opt_refNode) {
if (opt_refNode) {
var refIndex = this.getTilePageIndex(opt_refNode);
- this.cardSlider.insertCardAtIndex(page, refIndex);
+ this.cardSlider.addCardAtIndex(page, refIndex);
} else {
this.cardSlider.appendCard(page);
}
@@ -212,6 +218,11 @@ cr.define('ntp4', function() {
this.mostVisitedPage = page;
}
+ if (typeof ntp4.SuggestionsPage != 'undefined' &&
+ page instanceof ntp4.SuggestionsPage) {
+ this.suggestionsPage = page;
+ }
+
// If we're appending an AppsPage and it's a temporary page, animate it.
var animate = page instanceof ntp4.AppsPage &&
page.classList.contains('temporary');
@@ -319,6 +330,16 @@ cr.define('ntp4', function() {
// An app to animate (in case it was just installed).
var highlightApp;
+ // If there are any pages after the apps, add new pages before them.
+ var nextPageAfterApps = null;
+ for (var i = 1; i < this.tilePages.length; ++i) {
+ if (this.tilePages[i - 1] instanceof ntp4.AppsPage &&
+ !(this.tilePages[i] instanceof ntp4.AppsPage)) {
+ nextPageAfterApps = this.tilePages[i];
+ break;
+ }
+ }
Dan Beam 2012/02/28 20:14:24 easier to understand, IMO: var lastAppsPage = thi
GeorgeY 2012/02/28 21:17:42 there is a bug in your code: this.appsPages.length
Dan Beam 2012/02/28 22:30:12 A bug in example code doesn't make your code clear
GeorgeY 2012/02/29 00:15:45 What i meant is that if the 3 line code is buggy,
+
// Add the apps, creating pages as necessary
for (var i = 0; i < apps.length; i++) {
var app = apps[i];
@@ -329,7 +350,8 @@ cr.define('ntp4', function() {
pageName = pageNames[this.appsPages.length];
var origPageCount = this.appsPages.length;
- this.appendTilePage(new ntp4.AppsPage(), pageName, true);
+ this.appendTilePage(new ntp4.AppsPage(), pageName, true,
+ nextPageAfterApps);
// Confirm that appsPages is a live object, updated when a new page is
// added (otherwise we'd have an infinite loop)
assert(this.appsPages.length == origPageCount + 1,
@@ -429,6 +451,10 @@ cr.define('ntp4', function() {
if (this.mostVisitedPage)
this.cardSlider.selectCardByValue(this.mostVisitedPage);
break;
+ case templateData['suggestions_page_id']:
+ if (this.suggestionsPage)
+ this.cardSlider.selectCardByValue(this.suggestionsPage);
+ break;
}
},
@@ -527,6 +553,21 @@ cr.define('ntp4', function() {
},
/**
+ * Returns the first Apps page object in pageList, so pages could be added
+ * before that.
+ * @return {page} First Apps page object in pageList or null.
+ */
+ getFirstAppsPage: function() {
Dan Beam 2012/02/28 20:14:24 You don't use this anywhere and this can be accomp
GeorgeY 2012/02/28 21:17:42 Yes it is used. See suggestions_page.js
+ if (typeof this.tilePages == 'undefined')
+ return null;
+ for (var i = 0; i < this.tilePages.length; ++i) {
+ if (this.tilePages[i] instanceof ntp4.AppsPage)
+ return this.tilePages[i];
+ }
+ return null;
+ },
+
+ /**
* Handler for cardSlider:card_changed events from this.cardSlider.
* @param {Event} e The cardSlider:card_changed event.
* @private
@@ -543,6 +584,9 @@ cr.define('ntp4', function() {
} else if (page.classList.contains('most-visited-page')) {
this.shownPage = templateData.most_visited_page_id;
this.shownPageIndex = 0;
+ } else if (page.classList.contains('suggestions-page')) {
+ this.shownPage = templateData.suggestions_page_id;
+ this.shownPageIndex = 0;
} else {
console.error('unknown page selected');
}

Powered by Google App Engine
This is Rietveld 408576698