| OLD | NEW |
| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 103 |
| 104 /** | 104 /** |
| 105 * If non-null, this is the ID of the app to highlight to the user the next | 105 * If non-null, this is the ID of the app to highlight to the user the next |
| 106 * time getAppsCallback runs. "Highlight" in this case means to switch to | 106 * time getAppsCallback runs. "Highlight" in this case means to switch to |
| 107 * the page and run the new tile animation. | 107 * the page and run the new tile animation. |
| 108 * @type {String} | 108 * @type {String} |
| 109 */ | 109 */ |
| 110 var highlightAppId = null; | 110 var highlightAppId = null; |
| 111 | 111 |
| 112 /** | 112 /** |
| 113 * If non-null, an info bubble for showing messages to the user. It points at |
| 114 * the Most Visited label, and is used to draw more attention to the |
| 115 * navigation dot UI. |
| 116 * @type {!Element|undefined} |
| 117 */ |
| 118 var infoBubble; |
| 119 |
| 120 /** |
| 113 * The time in milliseconds for most transitions. This should match what's | 121 * The time in milliseconds for most transitions. This should match what's |
| 114 * in new_tab.css. Unfortunately there's no better way to try to time | 122 * in new_tab.css. Unfortunately there's no better way to try to time |
| 115 * something to occur until after a transition has completed. | 123 * something to occur until after a transition has completed. |
| 116 * @type {number} | 124 * @type {number} |
| 117 * @const | 125 * @const |
| 118 */ | 126 */ |
| 119 var DEFAULT_TRANSITION_TIME = 500; | 127 var DEFAULT_TRANSITION_TIME = 500; |
| 120 | 128 |
| 121 /** | 129 /** |
| 122 * Invoked at startup once the DOM is available to initialize the app. | 130 * Invoked at startup once the DOM is available to initialize the app. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 CardSlider.EventType.CARD_CHANGED, | 188 CardSlider.EventType.CARD_CHANGED, |
| 181 cardChangedHandler); | 189 cardChangedHandler); |
| 182 | 190 |
| 183 cr.ui.decorate($('recently-closed-menu-button'), ntp4.RecentMenuButton); | 191 cr.ui.decorate($('recently-closed-menu-button'), ntp4.RecentMenuButton); |
| 184 chrome.send('getRecentlyClosedTabs'); | 192 chrome.send('getRecentlyClosedTabs'); |
| 185 | 193 |
| 186 mostVisitedPage = new ntp4.MostVisitedPage(); | 194 mostVisitedPage = new ntp4.MostVisitedPage(); |
| 187 appendTilePage(mostVisitedPage, localStrings.getString('mostvisited')); | 195 appendTilePage(mostVisitedPage, localStrings.getString('mostvisited')); |
| 188 chrome.send('getMostVisited'); | 196 chrome.send('getMostVisited'); |
| 189 | 197 |
| 198 if (localStrings.getString('ntp4_intro_message')) { |
| 199 infoBubble = new cr.ui.Bubble; |
| 200 infoBubble.anchorNode = mostVisitedPage.navigationDot; |
| 201 infoBubble.text = localStrings.getString('ntp4_intro_message'); |
| 202 infoBubble.show(); |
| 203 |
| 204 chrome.send('introMessageSeen'); |
| 205 } |
| 206 |
| 190 bookmarksPage = new ntp4.BookmarksPage(); | 207 bookmarksPage = new ntp4.BookmarksPage(); |
| 191 appendTilePage(bookmarksPage, localStrings.getString('bookmarksPage')); | 208 appendTilePage(bookmarksPage, localStrings.getString('bookmarksPage')); |
| 192 chrome.send('getBookmarks'); | 209 chrome.send('getBookmarks'); |
| 193 } | 210 } |
| 194 | 211 |
| 195 /** | 212 /** |
| 196 * Simple common assertion API | 213 * Simple common assertion API |
| 197 * @param {*} condition The condition to test. Note that this may be used to | 214 * @param {*} condition The condition to test. Note that this may be used to |
| 198 * test whether a value is defined or not, and we don't want to force a | 215 * test whether a value is defined or not, and we don't want to force a |
| 199 * cast to Boolean. | 216 * cast to Boolean. |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 * @param {string} title The title of the tile page. | 416 * @param {string} title The title of the tile page. |
| 400 */ | 417 */ |
| 401 function appendTilePage(page, title) { | 418 function appendTilePage(page, title) { |
| 402 pageList.appendChild(page); | 419 pageList.appendChild(page); |
| 403 | 420 |
| 404 // Make a deep copy of the dot template to add a new one. | 421 // Make a deep copy of the dot template to add a new one. |
| 405 var newDot = new ntp4.NavDot(page, title, false, false); | 422 var newDot = new ntp4.NavDot(page, title, false, false); |
| 406 | 423 |
| 407 dotList.appendChild(newDot); | 424 dotList.appendChild(newDot); |
| 408 page.navigationDot = newDot; | 425 page.navigationDot = newDot; |
| 426 if (infoBubble) |
| 427 window.setTimeout(infoBubble.reposition.bind(infoBubble), 0); |
| 409 | 428 |
| 410 eventTracker.add(page, 'pagelayout', onPageLayout); | 429 eventTracker.add(page, 'pagelayout', onPageLayout); |
| 411 } | 430 } |
| 412 | 431 |
| 413 /** | 432 /** |
| 414 * Appends an apps page into the page list. This is like appendTilePage, | 433 * Appends an apps page into the page list. This is like appendTilePage, |
| 415 * but takes care to insert before the Bookmarks page. | 434 * but takes care to insert before the Bookmarks page. |
| 416 * TODO(csilv): Refactor this function with appendTilePage to avoid | 435 * TODO(csilv): Refactor this function with appendTilePage to avoid |
| 417 * duplication. | 436 * duplication. |
| 418 * | 437 * |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 var page = e.cardSlider.currentCardValue; | 606 var page = e.cardSlider.currentCardValue; |
| 588 if (page.classList.contains('apps-page')) { | 607 if (page.classList.contains('apps-page')) { |
| 589 shownPage = templateData['apps_page_id']; | 608 shownPage = templateData['apps_page_id']; |
| 590 shownPageIndex = getAppsPageIndex(page); | 609 shownPageIndex = getAppsPageIndex(page); |
| 591 } else if (page.classList.contains('most-visited-page')) { | 610 } else if (page.classList.contains('most-visited-page')) { |
| 592 shownPage = templateData['most_visited_page_id']; | 611 shownPage = templateData['most_visited_page_id']; |
| 593 shownPageIndex = 0; | 612 shownPageIndex = 0; |
| 594 } else if (page.classList.contains('bookmarks-page')) { | 613 } else if (page.classList.contains('bookmarks-page')) { |
| 595 shownPage = templateData['bookmarks_page_id']; | 614 shownPage = templateData['bookmarks_page_id']; |
| 596 shownPageIndex = 0; | 615 shownPageIndex = 0; |
| 597 } else if (page.classList.contains('bookmarks-page')) { | |
| 598 shownPage = templateData['bookmarks_page_id']; | |
| 599 shownPageIndex = 0; | |
| 600 } else { | 616 } else { |
| 601 console.error('unknown page selected'); | 617 console.error('unknown page selected'); |
| 602 } | 618 } |
| 603 chrome.send('pageSelected', [shownPage, shownPageIndex]); | 619 chrome.send('pageSelected', [shownPage, shownPageIndex]); |
| 604 | 620 |
| 605 // Update the active dot | 621 // Update the active dot |
| 606 var curDot = dotList.getElementsByClassName('selected')[0]; | 622 var curDot = dotList.getElementsByClassName('selected')[0]; |
| 607 if (curDot) | 623 if (curDot) |
| 608 curDot.classList.remove('selected'); | 624 curDot.classList.remove('selected'); |
| 609 var newPageIndex = e.cardSlider.currentCard; | 625 var newPageIndex = e.cardSlider.currentCard; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 // TODO(estade): update the content handlers to use ntp namespace instead of | 733 // TODO(estade): update the content handlers to use ntp namespace instead of |
| 718 // making these global. | 734 // making these global. |
| 719 var assert = ntp4.assert; | 735 var assert = ntp4.assert; |
| 720 var getAppsCallback = ntp4.getAppsCallback; | 736 var getAppsCallback = ntp4.getAppsCallback; |
| 721 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; | 737 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; |
| 722 var themeChanged = ntp4.themeChanged; | 738 var themeChanged = ntp4.themeChanged; |
| 723 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; | 739 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; |
| 724 var setMostVisitedPages = ntp4.setMostVisitedPages; | 740 var setMostVisitedPages = ntp4.setMostVisitedPages; |
| 725 | 741 |
| 726 document.addEventListener('DOMContentLoaded', ntp4.initialize); | 742 document.addEventListener('DOMContentLoaded', ntp4.initialize); |
| OLD | NEW |