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