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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 if (app.id == highlightAppId) { | 310 if (app.id == highlightAppId) { |
311 highlightApp = app; | 311 highlightApp = app; |
312 highlightAppId = null; | 312 highlightAppId = null; |
313 } else { | 313 } else { |
314 appsPages[pageIndex].appendApp(app); | 314 appsPages[pageIndex].appendApp(app); |
315 } | 315 } |
316 } | 316 } |
317 | 317 |
318 ntp4.AppsPage.setPromo(data.showPromo ? data : null); | 318 ntp4.AppsPage.setPromo(data.showPromo ? data : null); |
319 | 319 |
320 // Tell the slider about the pages | 320 // Tell the slider about the pages. |
321 updateSliderCards(); | 321 updateSliderCards(); |
322 | 322 |
323 if (highlightApp) | 323 if (highlightApp) |
324 appAdded(highlightApp); | 324 appAdded(highlightApp, true); |
325 | 325 |
326 // Mark the current page | 326 // Mark the current page. |
327 dots[cardSlider.currentCard].classList.add('selected'); | 327 cardSlider.currentCardValue.navigationDot.classList.add('selected'); |
Rick Byers
2011/08/23 20:52:13
Looks like you're not using the 'dots' list anymor
Evan Stade
2011/08/25 03:08:56
Done.
| |
328 logEvent('apps.layout: ' + (Date.now() - startTime)); | 328 logEvent('apps.layout: ' + (Date.now() - startTime)); |
329 } | 329 } |
330 | 330 |
331 /** | 331 /** |
332 * Called by chrome when a new app has been added to chrome. | 332 * Called by chrome when a new app has been added to chrome. |
333 * @param {Object} app A data structure full of relevant information for the | 333 * @param {Object} app A data structure full of relevant information for the |
334 * app. | 334 * app. |
335 */ | 335 */ |
336 function appAdded(app) { | 336 function appAdded(app, opt_highlight) { |
337 // If the page is already open when a new app is installed, the hash will | |
338 // be set once again. | |
339 var hash = location.hash; | |
340 if (hash && hash.indexOf('#app-id=') == 0 && app.id == hash.split('=')[1]) { | |
Rick Byers
2011/08/23 20:52:13
the logic to parse the hash is duplicated in initi
Evan Stade
2011/08/25 03:08:56
Done.
| |
341 window.history.replaceState({}, '', '/'); | |
342 opt_highlight = true; | |
343 } | |
344 | |
337 var pageIndex = app.page_index || 0; | 345 var pageIndex = app.page_index || 0; |
338 var page = appsPages[pageIndex]; | 346 var page; |
339 cardSlider.selectCardByValue(page); | 347 if (pageIndex < appsPages.length) { |
348 page = appsPages[pageIndex]; | |
349 } else { | |
350 page = new ntp4.AppsPage(); | |
Rick Byers
2011/08/23 20:52:13
is it not possible for page_index to be more than
Evan Stade
2011/08/25 03:08:56
Done.
| |
351 appendAppsPage(page, ''); | |
352 updateSliderCards(); | |
353 } | |
354 | |
355 if (opt_highlight) | |
356 cardSlider.selectCardByValue(page); | |
340 page.appendApp(app, true); | 357 page.appendApp(app, true); |
341 } | 358 } |
342 | 359 |
343 /** | 360 /** |
344 * Called by chrome when an existing app has been removed/uninstalled from | 361 * Called by chrome when an existing app has been removed/uninstalled from |
345 * chrome. | 362 * chrome. |
346 * @param {Object} appData A data structure full of relevant information for | 363 * @param {Object} appData A data structure full of relevant information for |
347 * the app. | 364 * the app. |
348 */ | 365 */ |
349 function appRemoved(appData) { | 366 function appRemoved(appData) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 */ | 409 */ |
393 function updateSliderCards() { | 410 function updateSliderCards() { |
394 var pageNo = cardSlider.currentCard; | 411 var pageNo = cardSlider.currentCard; |
395 if (pageNo >= tilePages.length) | 412 if (pageNo >= tilePages.length) |
396 pageNo = tilePages.length - 1; | 413 pageNo = tilePages.length - 1; |
397 var pageArray = []; | 414 var pageArray = []; |
398 for (var i = 0; i < tilePages.length; i++) | 415 for (var i = 0; i < tilePages.length; i++) |
399 pageArray[i] = tilePages[i]; | 416 pageArray[i] = tilePages[i]; |
400 cardSlider.setCards(pageArray, pageNo); | 417 cardSlider.setCards(pageArray, pageNo); |
401 | 418 |
402 if (shownPage == templateData['most_visited_page_id']) | 419 if (shownPage == templateData['most_visited_page_id']) { |
403 cardSlider.selectCardByValue(mostVisitedPage); | 420 cardSlider.selectCardByValue(mostVisitedPage); |
404 else if (shownPage == templateData['apps_page_id']) | 421 } else if (shownPage == templateData['apps_page_id']) { |
405 cardSlider.selectCardByValue(appsPages[shownPageIndex]); | 422 cardSlider.selectCardByValue( |
406 else if (shownPage == templateData['bookmarks_page_id']) | 423 appsPages[Math.min(shownPageIndex, appsPages.length - 1)]); |
424 } else if (shownPage == templateData['bookmarks_page_id']) { | |
407 cardSlider.selectCardByValue(bookmarksPage); | 425 cardSlider.selectCardByValue(bookmarksPage); |
426 } | |
408 } | 427 } |
409 | 428 |
410 /** | 429 /** |
411 * Appends a tile page (for bookmarks or most visited). | 430 * Appends a tile page (for bookmarks or most visited). |
412 * | 431 * |
413 * @param {TilePage} page The page element. | 432 * @param {TilePage} page The page element. |
414 * @param {string} title The title of the tile page. | 433 * @param {string} title The title of the tile page. |
415 */ | 434 */ |
416 function appendTilePage(page, title) { | 435 function appendTilePage(page, title) { |
417 pageList.appendChild(page); | 436 pageList.appendChild(page); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
480 $('footer').classList.add('showing-trash-mode'); | 499 $('footer').classList.add('showing-trash-mode'); |
481 } | 500 } |
482 | 501 |
483 /** | 502 /** |
484 * Invoked whenever some app is released | 503 * Invoked whenever some app is released |
485 * @param {Grabber.Event} e The Grabber RELEASE event. | 504 * @param {Grabber.Event} e The Grabber RELEASE event. |
486 */ | 505 */ |
487 function leaveRearrangeMode(e) { | 506 function leaveRearrangeMode(e) { |
488 var tempPage = document.querySelector('.tile-page.temporary'); | 507 var tempPage = document.querySelector('.tile-page.temporary'); |
489 var dot = tempPage.navigationDot; | 508 var dot = tempPage.navigationDot; |
490 if (!tempPage.tileCount) { | 509 if (!tempPage.tileCount && tempPage != cardSlider.currentCardValue) { |
491 dot.animateRemove(); | 510 dot.animateRemove(); |
492 tempPage.parentNode.removeChild(tempPage); | 511 tempPage.parentNode.removeChild(tempPage); |
493 updateSliderCards(); | 512 updateSliderCards(); |
494 } else { | 513 } else { |
495 tempPage.classList.remove('temporary'); | 514 tempPage.classList.remove('temporary'); |
496 saveAppPageName(tempPage, ''); | 515 saveAppPageName(tempPage, ''); |
497 } | 516 } |
498 | 517 |
499 $('footer').classList.remove('showing-trash-mode'); | 518 $('footer').classList.remove('showing-trash-mode'); |
500 } | 519 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
621 shownPageIndex = 0; | 640 shownPageIndex = 0; |
622 } else { | 641 } else { |
623 console.error('unknown page selected'); | 642 console.error('unknown page selected'); |
624 } | 643 } |
625 chrome.send('pageSelected', [shownPage, shownPageIndex]); | 644 chrome.send('pageSelected', [shownPage, shownPageIndex]); |
626 | 645 |
627 // Update the active dot | 646 // Update the active dot |
628 var curDot = dotList.getElementsByClassName('selected')[0]; | 647 var curDot = dotList.getElementsByClassName('selected')[0]; |
629 if (curDot) | 648 if (curDot) |
630 curDot.classList.remove('selected'); | 649 curDot.classList.remove('selected'); |
631 var newPageIndex = e.cardSlider.currentCard; | 650 page.navigationDot.classList.add('selected'); |
632 dots[newPageIndex].classList.add('selected'); | |
633 updatePageSwitchers(); | 651 updatePageSwitchers(); |
634 } | 652 } |
635 | 653 |
636 /** | 654 /** |
637 * Timeout ID. | 655 * Timeout ID. |
638 * @type {number} | 656 * @type {number} |
639 */ | 657 */ |
640 var notificationTimeout_ = 0; | 658 var notificationTimeout_ = 0; |
641 | 659 |
642 /** | 660 /** |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
744 // TODO(estade): update the content handlers to use ntp namespace instead of | 762 // TODO(estade): update the content handlers to use ntp namespace instead of |
745 // making these global. | 763 // making these global. |
746 var assert = ntp4.assert; | 764 var assert = ntp4.assert; |
747 var getAppsCallback = ntp4.getAppsCallback; | 765 var getAppsCallback = ntp4.getAppsCallback; |
748 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; | 766 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; |
749 var themeChanged = ntp4.themeChanged; | 767 var themeChanged = ntp4.themeChanged; |
750 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; | 768 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; |
751 var setMostVisitedPages = ntp4.setMostVisitedPages; | 769 var setMostVisitedPages = ntp4.setMostVisitedPages; |
752 | 770 |
753 document.addEventListener('DOMContentLoaded', ntp4.initialize); | 771 document.addEventListener('DOMContentLoaded', ntp4.initialize); |
OLD | NEW |