| 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 New tab page | 6 * @fileoverview New tab page |
| 7 * This is the main code for the new tab page. NewTabView manages page list, | 7 * This is the main code for the new tab page. NewTabView manages page list, |
| 8 * dot list and handles apps pages callbacks from backend. It also handles | 8 * dot list and handles apps pages callbacks from backend. It also handles |
| 9 * the layout of the Bottom Panel and the global UI states of the New Tab Page. | 9 * the layout of the Bottom Panel and the global UI states of the New Tab Page. |
| 10 */ | 10 */ |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 page.navigationDot = newDot; | 361 page.navigationDot = newDot; |
| 362 this.dotList.insertBefore(newDot, | 362 this.dotList.insertBefore(newDot, |
| 363 opt_refNode ? opt_refNode.navigationDot : null); | 363 opt_refNode ? opt_refNode.navigationDot : null); |
| 364 // Set a tab index on the first dot. | 364 // Set a tab index on the first dot. |
| 365 if (this.dotList.dots.length == 1) | 365 if (this.dotList.dots.length == 1) |
| 366 newDot.tabIndex = 3; | 366 newDot.tabIndex = 3; |
| 367 }, | 367 }, |
| 368 | 368 |
| 369 /** | 369 /** |
| 370 * Called by chrome when an app has changed positions. | 370 * Called by chrome when an app has changed positions. |
| 371 * @param {Object} appData The data for the app. This contains page and | 371 * @param {Object} data The data for the app. This contains page and |
| 372 * position indices. | 372 * position indices. |
| 373 */ | 373 */ |
| 374 appMoved: function(appData) { | 374 appMoved: function(data) { |
| 375 assert(loadTimeData.getBoolean('showApps')); | 375 assert(loadTimeData.getBoolean('showApps')); |
| 376 | 376 |
| 377 var app = $(appData.id); | 377 var app = $(data.id); |
| 378 assert(app, 'trying to move an app that doesn\'t exist'); | 378 assert(app, 'trying to move an app that doesn\'t exist'); |
| 379 app.remove(false); | 379 app.remove(false); |
| 380 | 380 |
| 381 this.appsPage.insertApp(appData, false); | 381 this.appsPage.insertApp(data, false); |
| 382 }, | 382 }, |
| 383 | 383 |
| 384 /** | 384 /** |
| 385 * Called by chrome when an existing app has been disabled or | 385 * Called by chrome when an existing app has been disabled or |
| 386 * removed/uninstalled from chrome. | 386 * removed/uninstalled from chrome. |
| 387 * @param {Object} appData A data structure full of relevant information for | 387 * @param {Object} data A data structure full of relevant information for |
| 388 * the app. | 388 * the app. |
| 389 * @param {boolean} isUninstall True if the app is being uninstalled; | 389 * @param {boolean} isUninstall True if the app is being uninstalled; |
| 390 * false if the app is being disabled. | 390 * false if the app is being disabled. |
| 391 * @param {boolean} fromPage True if the removal was from the current page. | 391 * @param {boolean} fromPage True if the removal was from the current page. |
| 392 */ | 392 */ |
| 393 appRemoved: function(appData, isUninstall, fromPage) { | 393 appRemoved: function(data, isUninstall, fromPage) { |
| 394 assert(loadTimeData.getBoolean('showApps')); | 394 assert(loadTimeData.getBoolean('showApps')); |
| 395 | 395 |
| 396 var app = $(appData.id); | 396 var app = $(data.id); |
| 397 assert(app, 'trying to remove an app that doesn\'t exist'); | 397 assert(app, 'trying to remove an app that doesn\'t exist'); |
| 398 | 398 |
| 399 if (!isUninstall) | 399 if (!isUninstall) |
| 400 app.replaceAppData(appData); | 400 app.replaceAppData(data); |
| 401 else | 401 else |
| 402 app.remove(!!fromPage); | 402 app.remove(!!fromPage); |
| 403 }, | 403 }, |
| 404 | 404 |
| 405 /** | 405 /** |
| 406 * @return {boolean} If the page is still starting up. | 406 * @return {boolean} If the page is still starting up. |
| 407 * @private | 407 * @private |
| 408 */ | 408 */ |
| 409 isStartingUp_: function() { | 409 isStartingUp_: function() { |
| 410 return document.documentElement.classList.contains('starting-up'); | 410 return document.documentElement.classList.contains('starting-up'); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 | 481 |
| 482 if (!this.appsLoaded_) { | 482 if (!this.appsLoaded_) { |
| 483 this.appsLoaded_ = true; | 483 this.appsLoaded_ = true; |
| 484 cr.dispatchSimpleEvent(document, 'sectionready', true, true); | 484 cr.dispatchSimpleEvent(document, 'sectionready', true, true); |
| 485 } | 485 } |
| 486 }, | 486 }, |
| 487 | 487 |
| 488 /** | 488 /** |
| 489 * Called by chrome when a new app has been added to chrome or has been | 489 * Called by chrome when a new app has been added to chrome or has been |
| 490 * enabled if previously disabled. | 490 * enabled if previously disabled. |
| 491 * @param {Object} appData A data structure full of relevant information for | 491 * @param {Object} data A data structure full of relevant information for |
| 492 * the app. | 492 * the app. |
| 493 * @param {boolean=} opt_highlight Whether the app about to be added should | 493 * @param {boolean=} opt_highlight Whether the app about to be added should |
| 494 * be highlighted. | 494 * be highlighted. |
| 495 */ | 495 */ |
| 496 appAdded: function(appData, opt_highlight) { | 496 appAdded: function(data, opt_highlight) { |
| 497 assert(loadTimeData.getBoolean('showApps')); | 497 assert(loadTimeData.getBoolean('showApps')); |
| 498 | 498 |
| 499 if (appData.id == this.highlightAppId) { | 499 if (data.id == this.highlightAppId) { |
| 500 opt_highlight = true; | 500 opt_highlight = true; |
| 501 this.highlightAppId = null; | 501 this.highlightAppId = null; |
| 502 } | 502 } |
| 503 | 503 |
| 504 var pageIndex = appData.page_index || 0; | 504 var pageIndex = data.page_index || 0; |
| 505 | 505 |
| 506 var app = $(appData.id); | 506 var app = $(data.id); |
| 507 if (app) { | 507 if (app) { |
| 508 app.replaceAppData(appData); | 508 app.replaceAppData(data); |
| 509 } else if (opt_highlight) { | 509 } else if (opt_highlight) { |
| 510 this.appsPage.insertAndHighlightApp(appData); | 510 this.appsPage.insertAndHighlightApp(data); |
| 511 this.setShownPage_(loadTimeData.getInteger('apps_page_id'), | 511 this.setShownPage_(loadTimeData.getInteger('apps_page_id'), |
| 512 appData.page_index); | 512 data.page_index); |
| 513 } else { | 513 } else { |
| 514 this.appsPage.insertApp(appData, false); | 514 this.appsPage.insertApp(data, false); |
| 515 } | 515 } |
| 516 }, | 516 }, |
| 517 | 517 |
| 518 /** | 518 /** |
| 519 * Callback invoked by chrome whenever an app preference changes. | 519 * Callback invoked by chrome whenever an app preference changes. |
| 520 * @param {Object} data An object with all the data on available | 520 * @param {Object} data An object with all the data on available |
| 521 * applications. | 521 * applications. |
| 522 */ | 522 */ |
| 523 appsPrefChangedCallback: function(data) { | 523 appsPrefChangedCallback: function(data) { |
| 524 assert(loadTimeData.getBoolean('showApps')); | 524 assert(loadTimeData.getBoolean('showApps')); |
| 525 | 525 |
| 526 for (var i = 0; i < data.apps.length; ++i) { | 526 for (var i = 0; i < data.apps.length; ++i) { |
| 527 $(data.apps[i].id).appData = data.apps[i]; | 527 $(data.apps[i].id).data = data.apps[i]; |
| 528 } | 528 } |
| 529 }, | 529 }, |
| 530 | 530 |
| 531 /** | 531 /** |
| 532 * Invoked whenever the pages in page-list have changed so that the | 532 * Invoked whenever the pages in page-list have changed so that the |
| 533 * CardSlider knows about the new elements. | 533 * CardSlider knows about the new elements. |
| 534 */ | 534 */ |
| 535 updateSliderCards: function() { | 535 updateSliderCards: function() { |
| 536 var pageNo = Math.max(0, Math.min(this.cardSlider.currentCard, | 536 var pageNo = Math.max(0, Math.min(this.cardSlider.currentCard, |
| 537 this.tilePages.length - 1)); | 537 this.tilePages.length - 1)); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 }, | 665 }, |
| 666 | 666 |
| 667 /** | 667 /** |
| 668 * Listener for offline status change events. Updates apps that are | 668 * Listener for offline status change events. Updates apps that are |
| 669 * not offline-enabled to be grayscale if the browser is offline. | 669 * not offline-enabled to be grayscale if the browser is offline. |
| 670 * @private | 670 * @private |
| 671 */ | 671 */ |
| 672 updateOfflineEnabledApps_: function() { | 672 updateOfflineEnabledApps_: function() { |
| 673 var apps = document.querySelectorAll('.app'); | 673 var apps = document.querySelectorAll('.app'); |
| 674 for (var i = 0; i < apps.length; ++i) { | 674 for (var i = 0; i < apps.length; ++i) { |
| 675 if (apps[i].appData.enabled && !apps[i].appData.offline_enabled) { | 675 if (apps[i].data.enabled && !apps[i].data.offline_enabled) { |
| 676 apps[i].setIcon(); | 676 apps[i].setIcon(); |
| 677 apps[i].loadIcon(); | 677 apps[i].loadIcon(); |
| 678 } | 678 } |
| 679 } | 679 } |
| 680 }, | 680 }, |
| 681 | 681 |
| 682 /** | 682 /** |
| 683 * Returns the index of a given tile page. | 683 * Returns the index of a given tile page. |
| 684 * @param {TilePage} page The TilePage we wish to find. | 684 * @param {TilePage} page The TilePage we wish to find. |
| 685 * @return {number} The index of |page| or -1 if it is not in the | 685 * @return {number} The index of |page| or -1 if it is not in the |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1157 setRecentlyClosedTabs: noop, | 1157 setRecentlyClosedTabs: noop, |
| 1158 showNotification: showNotification, | 1158 showNotification: showNotification, |
| 1159 themeChanged: themeChanged, | 1159 themeChanged: themeChanged, |
| 1160 updateLogin: noop, | 1160 updateLogin: noop, |
| 1161 }; | 1161 }; |
| 1162 }); | 1162 }); |
| 1163 | 1163 |
| 1164 document.addEventListener('DOMContentLoaded', ntp.onLoad); | 1164 document.addEventListener('DOMContentLoaded', ntp.onLoad); |
| 1165 | 1165 |
| 1166 var toCssPx = cr.ui.toCssPx; | 1166 var toCssPx = cr.ui.toCssPx; |
| OLD | NEW |