| 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 cr.define('ntp', function() { | 5 cr.define('ntp', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 var Tile = ntp.Tile; | 8 var Tile = ntp.Tile; |
| 9 var TilePage = ntp.TilePage; | 9 var TilePage = ntp.TilePage; |
| 10 var APP_LAUNCH = ntp.APP_LAUNCH; | 10 var APP_LAUNCH = ntp.APP_LAUNCH; |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 * Reference to the Tile subclass that will be used to create the tiles. | 569 * Reference to the Tile subclass that will be used to create the tiles. |
| 570 * @constructor | 570 * @constructor |
| 571 * @extends {Tile} | 571 * @extends {Tile} |
| 572 */ | 572 */ |
| 573 TileClass: App, | 573 TileClass: App, |
| 574 | 574 |
| 575 // The config object should be defined by a TilePage subclass if it | 575 // The config object should be defined by a TilePage subclass if it |
| 576 // wants the non-default behavior. | 576 // wants the non-default behavior. |
| 577 config: { | 577 config: { |
| 578 // The width of a cell. | 578 // The width of a cell. |
| 579 cellWidth: 77, | 579 cellWidth: 70, |
| 580 // The start margin of a cell (left or right according to text direction). | 580 // The start margin of a cell (left or right according to text direction). |
| 581 cellMarginStart: 12, | 581 cellMarginStart: 12, |
| 582 // The maximum number of Tiles to be displayed. | 582 // The maximum number of Tiles to be displayed. |
| 583 maxTileCount: 20 | 583 maxTileCount: 20, |
| 584 // Whether the TilePage content will be scrollable. |
| 585 scrollable: true, |
| 584 }, | 586 }, |
| 585 | 587 |
| 586 initialize: function() { | 588 initialize: function() { |
| 589 TilePage.prototype.initialize.apply(this, arguments); |
| 590 |
| 587 this.classList.add('apps-page'); | 591 this.classList.add('apps-page'); |
| 588 | 592 |
| 589 this.addEventListener('cardselected', this.onCardSelected_); | 593 this.addEventListener('cardselected', this.onCardSelected_); |
| 590 // Add event listeners for two events, so we can temporarily suppress | 594 // Add event listeners for two events, so we can temporarily suppress |
| 591 // the app notification bubbles when the app card slides in and out of | 595 // the app notification bubbles when the app card slides in and out of |
| 592 // view. | 596 // view. |
| 593 this.addEventListener('carddeselected', this.onCardDeselected_); | 597 this.addEventListener('carddeselected', this.onCardDeselected_); |
| 594 this.addEventListener('cardSlider:card_change_ended', | 598 this.addEventListener('cardSlider:card_change_ended', |
| 595 this.onCardChangeEnded_); | 599 this.onCardChangeEnded_); |
| 596 | 600 |
| 597 this.addEventListener('tilePage:tile_added', this.onTileAdded_); | 601 this.addEventListener('tilePage:tile_added', this.onTileAdded_); |
| 598 | |
| 599 this.content_.addEventListener('scroll', this.onScroll_.bind(this)); | |
| 600 }, | 602 }, |
| 601 | 603 |
| 602 /** | 604 /** |
| 603 * Highlight a newly installed app as it's added to the NTP. | 605 * Highlight a newly installed app as it's added to the NTP. |
| 604 * @param {Object} appData The data object that describes the app. | 606 * @param {Object} appData The data object that describes the app. |
| 605 */ | 607 */ |
| 606 insertAndHighlightApp: function(appData) { | 608 insertAndHighlightApp: function(appData) { |
| 607 ntp.getCardSlider().selectCardByValue(this); | 609 ntp.getCardSlider().selectCardByValue(this); |
| 608 this.content_.scrollTop = this.content_.scrollHeight; | |
| 609 this.insertApp(appData, true); | 610 this.insertApp(appData, true); |
| 610 }, | 611 }, |
| 611 | 612 |
| 612 /** | 613 /** |
| 613 * Similar to appendApp, but it respects the app_launch_ordinal field of | 614 * Inserts an App into the TilePage, preserving the alphabetical order. |
| 614 * |appData|. | |
| 615 * @param {Object} appData The data that describes the app. | 615 * @param {Object} appData The data that describes the app. |
| 616 * @param {boolean} animate Whether to animate the insertion. | 616 * @param {boolean} animate Whether to animate the insertion. |
| 617 */ | 617 */ |
| 618 insertApp: function(appData, animate) { | 618 insertApp: function(appData, animate) { |
| 619 var index = this.tiles_.length; | 619 var index = this.tiles_.length; |
| 620 for (var i = 0; i < this.tiles_.length; i++) { | 620 for (var i = 0; i < this.tiles_.length; i++) { |
| 621 if (appData.app_launch_ordinal < | 621 if (appData.title.toLocaleLowerCase() < |
| 622 this.tiles_[i].appData.app_launch_ordinal) { | 622 this.tiles_[i].appData.title.toLocaleLowerCase()) { |
| 623 index = i; | 623 index = i; |
| 624 break; | 624 break; |
| 625 } | 625 } |
| 626 } | 626 } |
| 627 | 627 |
| 628 this.addTileAt(new App(appData), index); | 628 var app = new App(appData); |
| 629 this.addTileAt(app, index); |
| 629 this.renderGrid_(); | 630 this.renderGrid_(); |
| 630 }, | 631 }, |
| 631 | 632 |
| 632 /** | 633 /** |
| 633 * Handler for 'cardselected' event, fired when |this| is selected. The | 634 * Handler for 'cardselected' event, fired when |this| is selected. The |
| 634 * first time this is called, we load all the app icons. | 635 * first time this is called, we load all the app icons. |
| 635 * @private | 636 * @private |
| 636 */ | 637 */ |
| 637 onCardSelected_: function(e) { | 638 onCardSelected_: function(e) { |
| 638 var apps = this.querySelectorAll('.app.icon-loading'); | 639 var apps = this.querySelectorAll('.app.icon-loading'); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 */ | 678 */ |
| 678 onCardDeselected_: function(e) { | 679 onCardDeselected_: function(e) { |
| 679 for (var i = 0; i < this.tiles_.length; i++) { | 680 for (var i = 0; i < this.tiles_.length; i++) { |
| 680 var app = this.tiles_[i]; | 681 var app = this.tiles_[i]; |
| 681 assert(app instanceof App); | 682 assert(app instanceof App); |
| 682 if (app.currentBubbleShowing_) | 683 if (app.currentBubbleShowing_) |
| 683 app.currentBubbleShowing_.suppressed = true; | 684 app.currentBubbleShowing_.suppressed = true; |
| 684 } | 685 } |
| 685 }, | 686 }, |
| 686 | 687 |
| 687 /** | 688 /** @override */ |
| 688 * A handler for when the apps page is scrolled (then we need to reposition | 689 onScroll: function() { |
| 689 * the bubbles. | 690 TilePage.prototype.onScroll.apply(this, arguments); |
| 690 * @private | 691 |
| 691 */ | |
| 692 onScroll_: function(e) { | |
| 693 if (!this.selected) | |
| 694 return; | |
| 695 for (var i = 0; i < this.tiles_.length; i++) { | 692 for (var i = 0; i < this.tiles_.length; i++) { |
| 696 var app = this.tiles_[i]; | 693 var app = this.tiles_[i]; |
| 697 assert(app instanceof App); | 694 assert(app instanceof App); |
| 698 if (app.currentBubbleShowing_) | 695 if (app.currentBubbleShowing_) |
| 699 app.currentBubbleShowing_.resizeAndReposition(); | 696 app.currentBubbleShowing_.resizeAndReposition(); |
| 700 } | 697 } |
| 701 }, | 698 }, |
| 702 | 699 |
| 703 /** @override */ | 700 /** @override */ |
| 704 doDragOver: function(e) { | 701 doDragOver: function(e) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 if (app && !app.appData.notifications_disabled) | 837 if (app && !app.appData.notifications_disabled) |
| 841 app.setupNotification_(notification); | 838 app.setupNotification_(notification); |
| 842 } | 839 } |
| 843 | 840 |
| 844 return { | 841 return { |
| 845 appNotificationChanged: appNotificationChanged, | 842 appNotificationChanged: appNotificationChanged, |
| 846 AppsPage: AppsPage, | 843 AppsPage: AppsPage, |
| 847 launchAppAfterEnable: launchAppAfterEnable, | 844 launchAppAfterEnable: launchAppAfterEnable, |
| 848 }; | 845 }; |
| 849 }); | 846 }); |
| OLD | NEW |