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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 }, | 274 }, |
275 | 275 |
276 /** | 276 /** |
277 * Removes the app tile from the page. Should be called after the app has | 277 * Removes the app tile from the page. Should be called after the app has |
278 * been uninstalled. | 278 * been uninstalled. |
279 */ | 279 */ |
280 remove: function(opt_animate) { | 280 remove: function(opt_animate) { |
281 // Unset the ID immediately, because the app is already gone. But leave | 281 // Unset the ID immediately, because the app is already gone. But leave |
282 // the tile on the page as it animates out. | 282 // the tile on the page as it animates out. |
283 this.id = ''; | 283 this.id = ''; |
284 this.tileCell.doRemove(opt_animate); | 284 |
285 if (opt_animate) { | |
286 var cell = this.tileCell; | |
287 var tilePage = cell.tilePage; | |
288 tilePage.dataList_.splice(cell.index, 1); | |
289 tilePage.animateTileRemoval(cell.index, tilePage.dataList_); | |
290 } else { | |
291 this.tileCell.doRemove(opt_animate); | |
292 } | |
285 }, | 293 }, |
286 | 294 |
287 /** | 295 /** |
288 * Set the URL of the icon from |this.data_|. This won't actually show the | 296 * Set the URL of the icon from |this.data_|. This won't actually show the |
289 * icon until loadIcon() is called (for performance reasons; we don't want | 297 * icon until loadIcon() is called (for performance reasons; we don't want |
290 * to load icons until we have to). | 298 * to load icons until we have to). |
291 */ | 299 */ |
292 setIcon: function() { | 300 setIcon: function() { |
293 var src = this.useSmallIcon_ ? this.data_.icon_small : | 301 var src = this.useSmallIcon_ ? this.data_.icon_small : |
294 this.data_.icon_big; | 302 this.data_.icon_big; |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
573 * @extends {Tile} | 581 * @extends {Tile} |
574 */ | 582 */ |
575 TileClass: App, | 583 TileClass: App, |
576 | 584 |
577 // The config object should be defined by a TilePage subclass if it | 585 // The config object should be defined by a TilePage subclass if it |
578 // wants the non-default behavior. | 586 // wants the non-default behavior. |
579 config: { | 587 config: { |
580 // The width of a cell. | 588 // The width of a cell. |
581 cellWidth: 70, | 589 cellWidth: 70, |
582 // The start margin of a cell (left or right according to text direction). | 590 // The start margin of a cell (left or right according to text direction). |
583 cellMarginStart: 22, | 591 cellMarginStart: 20, |
584 // The maximum number of Tiles to be displayed. | 592 // The maximum number of Tiles to be displayed. |
585 maxTileCount: 20, | 593 maxTileCount: 20, |
586 // Whether the TilePage content will be scrollable. | 594 // Whether the TilePage content will be scrollable. |
587 scrollable: true, | 595 scrollable: true, |
588 }, | 596 }, |
589 | 597 |
590 initialize: function() { | 598 initialize: function() { |
591 TilePage.prototype.initialize.apply(this, arguments); | 599 TilePage.prototype.initialize.apply(this, arguments); |
592 | 600 |
593 this.classList.add('apps-page'); | 601 this.classList.add('apps-page'); |
(...skipping 26 matching lines...) Expand all Loading... | |
620 insertApp: function(data, animate) { | 628 insertApp: function(data, animate) { |
621 var index = this.tiles_.length; | 629 var index = this.tiles_.length; |
622 for (var i = 0; i < this.tiles_.length; i++) { | 630 for (var i = 0; i < this.tiles_.length; i++) { |
623 if (data.title.toLocaleLowerCase() < | 631 if (data.title.toLocaleLowerCase() < |
624 this.tiles_[i].data.title.toLocaleLowerCase()) { | 632 this.tiles_[i].data.title.toLocaleLowerCase()) { |
625 index = i; | 633 index = i; |
626 break; | 634 break; |
627 } | 635 } |
628 } | 636 } |
629 | 637 |
630 var app = new App(); | 638 if (animate) { |
631 app.data = data; | 639 this.dataList_.splice(index, 0, data); |
632 this.addTileAt(app, index); | 640 this.animateTileRestoration(index, this.dataList_); |
633 this.renderGrid_(); | 641 } else { |
642 var app = new App(); | |
643 app.data = data; | |
644 this.addTileAt(app, index); | |
645 this.renderGrid_(); | |
Dan Beam
2012/12/07 05:11:26
I do wonder why adding a tile doesn't automaticall
pedro (no code reviews)
2012/12/08 02:57:29
The goal was being able to add/remove multiple til
| |
646 } | |
634 }, | 647 }, |
635 | 648 |
636 /** | 649 /** |
637 * Handler for 'cardselected' event, fired when |this| is selected. The | 650 * Handler for 'cardselected' event, fired when |this| is selected. The |
638 * first time this is called, we load all the app icons. | 651 * first time this is called, we load all the app icons. |
639 * @private | 652 * @private |
640 */ | 653 */ |
641 onCardSelected_: function(e) { | 654 onCardSelected_: function(e) { |
642 var apps = this.querySelectorAll('.app.icon-loading'); | 655 var apps = this.querySelectorAll('.app.icon-loading'); |
643 for (var i = 0; i < apps.length; i++) { | 656 for (var i = 0; i < apps.length; i++) { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
840 if (app && !app.data.notifications_disabled) | 853 if (app && !app.data.notifications_disabled) |
841 app.setupNotification_(notification); | 854 app.setupNotification_(notification); |
842 } | 855 } |
843 | 856 |
844 return { | 857 return { |
845 appNotificationChanged: appNotificationChanged, | 858 appNotificationChanged: appNotificationChanged, |
846 AppsPage: AppsPage, | 859 AppsPage: AppsPage, |
847 launchAppAfterEnable: launchAppAfterEnable, | 860 launchAppAfterEnable: launchAppAfterEnable, |
848 }; | 861 }; |
849 }); | 862 }); |
OLD | NEW |