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

Side by Side 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: Moved suggestions before apps, fixed already present js bug, alphabetised .css 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 PageListView implementation. 6 * @fileoverview PageListView implementation.
7 * PageListView manages page list, dot list, switcher buttons and handles apps 7 * PageListView manages page list, dot list, switcher buttons and handles apps
8 * pages callbacks from backend. 8 * pages callbacks from backend.
9 * 9 *
10 * Note that you need to have AppLauncherHandler in your WebUI to use this code. 10 * Note that you need to have AppLauncherHandler in your WebUI to use this code.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 */ 52 */
53 tilePages: undefined, 53 tilePages: undefined,
54 54
55 /** 55 /**
56 * A list of all 'apps-page' elements. 56 * A list of all 'apps-page' elements.
57 * @type {!NodeList|undefined} 57 * @type {!NodeList|undefined}
58 */ 58 */
59 appsPages: undefined, 59 appsPages: undefined,
60 60
61 /** 61 /**
62 * The Suggestions page.
63 * @type {!Element|undefined}
64 */
65 suggestionsPage: undefined,
66
67 /**
62 * The Most Visited page. 68 * The Most Visited page.
63 * @type {!Element|undefined} 69 * @type {!Element|undefined}
64 */ 70 */
65 mostVisitedPage: undefined, 71 mostVisitedPage: undefined,
66 72
67 /** 73 /**
68 * The 'dots-list' element. 74 * The 'dots-list' element.
69 * @type {!Element|undefined} 75 * @type {!Element|undefined}
70 */ 76 */
71 dotList: undefined, 77 dotList: undefined,
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 * 196 *
191 * @param {TilePage} page The page element. 197 * @param {TilePage} page The page element.
192 * @param {string} title The title of the tile page. 198 * @param {string} title The title of the tile page.
193 * @param {bool} titleIsEditable If true, the title can be changed. 199 * @param {bool} titleIsEditable If true, the title can be changed.
194 * @param {TilePage} opt_refNode Optional reference node to insert in front 200 * @param {TilePage} opt_refNode Optional reference node to insert in front
195 * of. 201 * of.
196 * When opt_refNode is falsey, |page| will just be appended to the end of 202 * When opt_refNode is falsey, |page| will just be appended to the end of
197 * the page list. 203 * the page list.
198 */ 204 */
199 appendTilePage: function(page, title, titleIsEditable, opt_refNode) { 205 appendTilePage: function(page, title, titleIsEditable, opt_refNode) {
206 if (typeof ntp4.SuggestionsPage != 'undefined' &&
Evan Stade 2012/02/24 23:28:01 this is a hack.
GeorgeY 2012/02/25 01:30:55 I will not argue with you what is a hack or not he
207 page instanceof ntp4.SuggestionsPage &&
208 typeof this.appsPages != 'undefined' && this.appsPages.length > 0) {
209 // Add suggestion page before the apps page(s).
210 opt_refNode = this.appsPages[0];
211 }
200 if (opt_refNode) { 212 if (opt_refNode) {
201 var refIndex = this.getTilePageIndex(opt_refNode); 213 var refIndex = this.getTilePageIndex(opt_refNode);
202 this.cardSlider.insertCardAtIndex(page, refIndex); 214 this.cardSlider.addCardAtIndex(page, refIndex);
203 } else { 215 } else {
204 this.cardSlider.appendCard(page); 216 this.cardSlider.appendCard(page);
205 } 217 }
206 218
207 // Remember special MostVisitedPage. 219 // Remember special MostVisitedPage.
208 if (typeof ntp4.MostVisitedPage != 'undefined' && 220 if (typeof ntp4.MostVisitedPage != 'undefined' &&
209 page instanceof ntp4.MostVisitedPage) { 221 page instanceof ntp4.MostVisitedPage) {
210 assert(this.tilePages.length == 1, 222 assert(this.tilePages.length == 1,
211 'MostVisitedPage should be added as first tile page'); 223 'MostVisitedPage should be added as first tile page');
212 this.mostVisitedPage = page; 224 this.mostVisitedPage = page;
213 } 225 }
214 226
227 if (typeof ntp4.SuggestionsPage != 'undefined' &&
228 page instanceof ntp4.SuggestionsPage) {
229 this.suggestionsPage = page;
230 }
231
215 // If we're appending an AppsPage and it's a temporary page, animate it. 232 // If we're appending an AppsPage and it's a temporary page, animate it.
216 var animate = page instanceof ntp4.AppsPage && 233 var animate = page instanceof ntp4.AppsPage &&
217 page.classList.contains('temporary'); 234 page.classList.contains('temporary');
218 // Make a deep copy of the dot template to add a new one. 235 // Make a deep copy of the dot template to add a new one.
219 var newDot = new ntp4.NavDot(page, title, titleIsEditable, animate); 236 var newDot = new ntp4.NavDot(page, title, titleIsEditable, animate);
220 page.navigationDot = newDot; 237 page.navigationDot = newDot;
221 this.dotList.insertBefore(newDot, 238 this.dotList.insertBefore(newDot,
222 opt_refNode ? opt_refNode.navigationDot : null); 239 opt_refNode ? opt_refNode.navigationDot : null);
223 // Set a tab index on the first dot. 240 // Set a tab index on the first dot.
224 if (this.dotList.dots.length == 1) 241 if (this.dotList.dots.length == 1)
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 switch (this.shownPage) { 439 switch (this.shownPage) {
423 case templateData['apps_page_id']: 440 case templateData['apps_page_id']:
424 this.cardSlider.selectCardByValue( 441 this.cardSlider.selectCardByValue(
425 this.appsPages[Math.min(this.shownPageIndex, 442 this.appsPages[Math.min(this.shownPageIndex,
426 this.appsPages.length - 1)]); 443 this.appsPages.length - 1)]);
427 break; 444 break;
428 case templateData['most_visited_page_id']: 445 case templateData['most_visited_page_id']:
429 if (this.mostVisitedPage) 446 if (this.mostVisitedPage)
430 this.cardSlider.selectCardByValue(this.mostVisitedPage); 447 this.cardSlider.selectCardByValue(this.mostVisitedPage);
431 break; 448 break;
449 case templateData['suggestions_page_id']:
450 if (this.suggestionsPage)
451 this.cardSlider.selectCardByValue(this.suggestionsPage);
452 break;
432 } 453 }
433 }, 454 },
434 455
435 /** 456 /**
436 * Called whenever tiles should be re-arranging themselves out of the way 457 * Called whenever tiles should be re-arranging themselves out of the way
437 * of a moving or insert tile. 458 * of a moving or insert tile.
438 */ 459 */
439 enterRearrangeMode: function() { 460 enterRearrangeMode: function() {
440 var tempPage = new ntp4.AppsPage(); 461 var tempPage = new ntp4.AppsPage();
441 tempPage.classList.add('temporary'); 462 tempPage.classList.add('temporary');
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 557
537 // Don't change shownPage until startup is done (and page changes actually 558 // Don't change shownPage until startup is done (and page changes actually
538 // reflect user actions). 559 // reflect user actions).
539 if (!this.isStartingUp_()) { 560 if (!this.isStartingUp_()) {
540 if (page.classList.contains('apps-page')) { 561 if (page.classList.contains('apps-page')) {
541 this.shownPage = templateData.apps_page_id; 562 this.shownPage = templateData.apps_page_id;
542 this.shownPageIndex = this.getAppsPageIndex(page); 563 this.shownPageIndex = this.getAppsPageIndex(page);
543 } else if (page.classList.contains('most-visited-page')) { 564 } else if (page.classList.contains('most-visited-page')) {
544 this.shownPage = templateData.most_visited_page_id; 565 this.shownPage = templateData.most_visited_page_id;
545 this.shownPageIndex = 0; 566 this.shownPageIndex = 0;
567 } else if (page.classList.contains('suggestions-page')) {
568 this.shownPage = templateData.suggestions_page_id;
569 this.shownPageIndex = 0;
546 } else { 570 } else {
547 console.error('unknown page selected'); 571 console.error('unknown page selected');
548 } 572 }
549 chrome.send('pageSelected', [this.shownPage, this.shownPageIndex]); 573 chrome.send('pageSelected', [this.shownPage, this.shownPageIndex]);
550 } 574 }
551 575
552 // Update the active dot 576 // Update the active dot
553 var curDot = this.dotList.getElementsByClassName('selected')[0]; 577 var curDot = this.dotList.getElementsByClassName('selected')[0];
554 if (curDot) 578 if (curDot)
555 curDot.classList.remove('selected'); 579 curDot.classList.remove('selected');
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 if (page.navigationDot) 686 if (page.navigationDot)
663 page.navigationDot.remove(opt_animate); 687 page.navigationDot.remove(opt_animate);
664 this.cardSlider.removeCard(page); 688 this.cardSlider.removeCard(page);
665 }, 689 },
666 }; 690 };
667 691
668 return { 692 return {
669 PageListView: PageListView 693 PageListView: PageListView
670 }; 694 };
671 }); 695 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698