| 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 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 Loading... |
| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 } | 211 } |
| 206 | 212 |
| 207 // Remember special MostVisitedPage. | 213 // Remember special MostVisitedPage. |
| 208 if (typeof ntp4.MostVisitedPage != 'undefined' && | 214 if (typeof ntp4.MostVisitedPage != 'undefined' && |
| 209 page instanceof ntp4.MostVisitedPage) { | 215 page instanceof ntp4.MostVisitedPage) { |
| 210 assert(this.tilePages.length == 1, | 216 assert(this.tilePages.length == 1, |
| 211 'MostVisitedPage should be added as first tile page'); | 217 'MostVisitedPage should be added as first tile page'); |
| 212 this.mostVisitedPage = page; | 218 this.mostVisitedPage = page; |
| 213 } | 219 } |
| 214 | 220 |
| 221 if (typeof ntp4.SuggestionsPage != 'undefined' && |
| 222 page instanceof ntp4.SuggestionsPage) { |
| 223 this.suggestionsPage = page; |
| 224 } |
| 225 |
| 215 // If we're appending an AppsPage and it's a temporary page, animate it. | 226 // If we're appending an AppsPage and it's a temporary page, animate it. |
| 216 var animate = page instanceof ntp4.AppsPage && | 227 var animate = page instanceof ntp4.AppsPage && |
| 217 page.classList.contains('temporary'); | 228 page.classList.contains('temporary'); |
| 218 // Make a deep copy of the dot template to add a new one. | 229 // Make a deep copy of the dot template to add a new one. |
| 219 var newDot = new ntp4.NavDot(page, title, titleIsEditable, animate); | 230 var newDot = new ntp4.NavDot(page, title, titleIsEditable, animate); |
| 220 page.navigationDot = newDot; | 231 page.navigationDot = newDot; |
| 221 this.dotList.insertBefore(newDot, | 232 this.dotList.insertBefore(newDot, |
| 222 opt_refNode ? opt_refNode.navigationDot : null); | 233 opt_refNode ? opt_refNode.navigationDot : null); |
| 223 // Set a tab index on the first dot. | 234 // Set a tab index on the first dot. |
| 224 if (this.dotList.dots.length == 1) | 235 if (this.dotList.dots.length == 1) |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 switch (this.shownPage) { | 420 switch (this.shownPage) { |
| 410 case templateData['apps_page_id']: | 421 case templateData['apps_page_id']: |
| 411 this.cardSlider.selectCardByValue( | 422 this.cardSlider.selectCardByValue( |
| 412 this.appsPages[Math.min(this.shownPageIndex, | 423 this.appsPages[Math.min(this.shownPageIndex, |
| 413 this.appsPages.length - 1)]); | 424 this.appsPages.length - 1)]); |
| 414 break; | 425 break; |
| 415 case templateData['most_visited_page_id']: | 426 case templateData['most_visited_page_id']: |
| 416 if (this.mostVisitedPage) | 427 if (this.mostVisitedPage) |
| 417 this.cardSlider.selectCardByValue(this.mostVisitedPage); | 428 this.cardSlider.selectCardByValue(this.mostVisitedPage); |
| 418 break; | 429 break; |
| 430 case templateData['suggested_page_id']: |
| 431 if (this.suggestionsPage) |
| 432 this.cardSlider.selectCardByValue(this.suggestionsPage); |
| 433 break; |
| 419 } | 434 } |
| 420 }, | 435 }, |
| 421 | 436 |
| 422 /** | 437 /** |
| 423 * Called whenever tiles should be re-arranging themselves out of the way | 438 * Called whenever tiles should be re-arranging themselves out of the way |
| 424 * of a moving or insert tile. | 439 * of a moving or insert tile. |
| 425 */ | 440 */ |
| 426 enterRearrangeMode: function() { | 441 enterRearrangeMode: function() { |
| 427 var tempPage = new ntp4.AppsPage(); | 442 var tempPage = new ntp4.AppsPage(); |
| 428 tempPage.classList.add('temporary'); | 443 tempPage.classList.add('temporary'); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 | 538 |
| 524 // Don't change shownPage until startup is done (and page changes actually | 539 // Don't change shownPage until startup is done (and page changes actually |
| 525 // reflect user actions). | 540 // reflect user actions). |
| 526 if (!this.isStartingUp_()) { | 541 if (!this.isStartingUp_()) { |
| 527 if (page.classList.contains('apps-page')) { | 542 if (page.classList.contains('apps-page')) { |
| 528 this.shownPage = templateData.apps_page_id; | 543 this.shownPage = templateData.apps_page_id; |
| 529 this.shownPageIndex = this.getAppsPageIndex(page); | 544 this.shownPageIndex = this.getAppsPageIndex(page); |
| 530 } else if (page.classList.contains('most-visited-page')) { | 545 } else if (page.classList.contains('most-visited-page')) { |
| 531 this.shownPage = templateData.most_visited_page_id; | 546 this.shownPage = templateData.most_visited_page_id; |
| 532 this.shownPageIndex = 0; | 547 this.shownPageIndex = 0; |
| 548 } else if (page.classList.contains('suggested-page')) { |
| 549 this.shownPage = templateData.suggested_page_id; |
| 550 this.shownPageIndex = 0; |
| 533 } else { | 551 } else { |
| 534 console.error('unknown page selected'); | 552 console.error('unknown page selected'); |
| 535 } | 553 } |
| 536 chrome.send('pageSelected', [this.shownPage, this.shownPageIndex]); | 554 chrome.send('pageSelected', [this.shownPage, this.shownPageIndex]); |
| 537 } | 555 } |
| 538 | 556 |
| 539 // Update the active dot | 557 // Update the active dot |
| 540 var curDot = this.dotList.getElementsByClassName('selected')[0]; | 558 var curDot = this.dotList.getElementsByClassName('selected')[0]; |
| 541 if (curDot) | 559 if (curDot) |
| 542 curDot.classList.remove('selected'); | 560 curDot.classList.remove('selected'); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 if (page.navigationDot) | 667 if (page.navigationDot) |
| 650 page.navigationDot.remove(opt_animate); | 668 page.navigationDot.remove(opt_animate); |
| 651 this.cardSlider.removeCard(page); | 669 this.cardSlider.removeCard(page); |
| 652 }, | 670 }, |
| 653 }; | 671 }; |
| 654 | 672 |
| 655 return { | 673 return { |
| 656 PageListView: PageListView | 674 PageListView: PageListView |
| 657 }; | 675 }; |
| 658 }); | 676 }); |
| OLD | NEW |