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 | 8 |
9 /** | 9 /** |
10 * The maximum gap from the edge of the scrolling area which will display | 10 * The maximum gap from the edge of the scrolling area which will display |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
481 tile.data = data; | 481 tile.data = data; |
482 } | 482 } |
483 }, | 483 }, |
484 | 484 |
485 /** | 485 /** |
486 * Sets the dataList that will be used to create Tiles. This method will | 486 * Sets the dataList that will be used to create Tiles. This method will |
487 * create/remove necessary/unnecessary tiles, render the grid when the | 487 * create/remove necessary/unnecessary tiles, render the grid when the |
488 * number of tiles has changed, and finally will call |updateTiles_| which | 488 * number of tiles has changed, and finally will call |updateTiles_| which |
489 * will in turn render the individual tiles. | 489 * will in turn render the individual tiles. |
490 * @param {Array} dataList The array of data. | 490 * @param {Array} dataList The array of data. |
491 * @param {boolean=} opt_create Whether to create tiles. | |
491 */ | 492 */ |
492 setDataList: function(dataList) { | 493 setDataList: function(dataList, opt_create) { |
493 this.dataList_ = dataList.slice(0, this.config.maxTileCount); | 494 this.dataList_ = dataList.slice(0, this.config.maxTileCount); |
494 | 495 |
496 opt_create = typeof opt_create == 'undefined' ? true : opt_create; | |
Dan Beam
2012/12/07 05:08:56
nit: I generally think it's better to have `undefi
pedro (no code reviews)
2012/12/08 02:57:29
I went ahead and implemented your previous suggest
| |
497 if (!opt_create) | |
498 return; | |
499 | |
495 var dataListLength = this.dataList_.length; | 500 var dataListLength = this.dataList_.length; |
496 var tileCount = this.tileCount; | 501 var tileCount = this.tileCount; |
497 // Create or remove tiles if necessary. | 502 // Create or remove tiles if necessary. |
498 if (tileCount < dataListLength) { | 503 if (tileCount < dataListLength) { |
499 this.createTiles_(dataListLength - tileCount); | 504 this.createTiles_(dataListLength - tileCount); |
500 } else if (tileCount > dataListLength) { | 505 } else if (tileCount > dataListLength) { |
501 var tiles = this.tiles_; | 506 var tiles = this.tiles_; |
502 while (tiles.length > dataListLength) { | 507 while (tiles.length > dataListLength) { |
503 var previousLength = tiles.length; | 508 var previousLength = tiles.length; |
504 // It doesn't matter which tiles are being removed here because | 509 // It doesn't matter which tiles are being removed here because |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
847 | 852 |
848 var repositioningStartIndex = index; | 853 var repositioningStartIndex = index; |
849 var repositioningEndIndex = tileCount - (extraTileData ? 1 : 0); | 854 var repositioningEndIndex = tileCount - (extraTileData ? 1 : 0); |
850 | 855 |
851 this.initializeRepositioningAnimation_(index, repositioningEndIndex); | 856 this.initializeRepositioningAnimation_(index, repositioningEndIndex); |
852 | 857 |
853 var restoredData = newDataList[index]; | 858 var restoredData = newDataList[index]; |
854 var tileBeingRestored = createTile(this, restoredData); | 859 var tileBeingRestored = createTile(this, restoredData); |
855 tileCells[index].appendChild(tileBeingRestored); | 860 tileCells[index].appendChild(tileBeingRestored); |
856 | 861 |
857 var extraTile = extraCell.tile; | 862 if (this.config.scrollable) |
863 this.content_.scrollTop = tileCells[index].offsetTop; | |
864 | |
865 var extraTile; | |
866 if (extraCell) | |
867 extraTile = extraCell.tile; | |
858 | 868 |
859 this.executeRepositioningAnimation_(tileBeingRestored, extraTile, | 869 this.executeRepositioningAnimation_(tileBeingRestored, extraTile, |
860 repositioningStartIndex, repositioningEndIndex, false); | 870 repositioningStartIndex, repositioningEndIndex, false); |
861 | 871 |
862 // Cleans up the animation. | 872 // Cleans up the animation. |
863 var onPositioningTransitionEnd = function(e) { | 873 var onPositioningTransitionEnd = function(e) { |
864 var propertyName = e.propertyName; | 874 var propertyName = e.propertyName; |
865 if (!(propertyName == '-webkit-transform' || | 875 if (!(propertyName == '-webkit-transform' || |
866 propertyName == 'opacity')) { | 876 propertyName == 'opacity')) { |
867 return; | 877 return; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
948 * @param {number} endIndex Index of the last tile to be repositioned. | 958 * @param {number} endIndex Index of the last tile to be repositioned. |
949 * @param {boolean} isRemoving Whether the tile is being removed. | 959 * @param {boolean} isRemoving Whether the tile is being removed. |
950 * @private | 960 * @private |
951 */ | 961 */ |
952 executeRepositioningAnimation_: function(targetTile, extraTile, startIndex, | 962 executeRepositioningAnimation_: function(targetTile, extraTile, startIndex, |
953 endIndex, isRemoving) { | 963 endIndex, isRemoving) { |
954 targetTile.classList.add('target-tile'); | 964 targetTile.classList.add('target-tile'); |
955 | 965 |
956 // Alternate the visualization of the target and extra tiles. | 966 // Alternate the visualization of the target and extra tiles. |
957 fadeTile(targetTile, !isRemoving); | 967 fadeTile(targetTile, !isRemoving); |
958 fadeTile(extraTile, isRemoving); | 968 if (extraTile) |
969 fadeTile(extraTile, isRemoving); | |
959 | 970 |
960 // Move tiles to the new position. | 971 // Move tiles to the new position. |
961 var tiles = this.tiles_; | 972 var tiles = this.tiles_; |
962 var positionDiff = isRemoving ? -1 : 1; | 973 var positionDiff = isRemoving ? -1 : 1; |
963 for (var i = startIndex; i < endIndex; i++) { | 974 for (var i = startIndex; i < endIndex; i++) { |
964 var position = this.getTilePosition_(i + positionDiff); | 975 var position = this.getTilePosition_(i + positionDiff); |
965 this.moveTileTo_(tiles[i], position.left, position.top); | 976 this.moveTileTo_(tiles[i], position.left, position.top); |
966 } | 977 } |
967 }, | 978 }, |
968 | 979 |
(...skipping 14 matching lines...) Expand all Loading... | |
983 targetTile.classList.remove('target-tile'); | 994 targetTile.classList.remove('target-tile'); |
984 | 995 |
985 // Move tiles back to relative position. | 996 // Move tiles back to relative position. |
986 var tiles = this.tiles_; | 997 var tiles = this.tiles_; |
987 var tileCells = this.querySelectorAll('.tile-cell'); | 998 var tileCells = this.querySelectorAll('.tile-cell'); |
988 var positionDiff = isRemoving ? -1 : 1; | 999 var positionDiff = isRemoving ? -1 : 1; |
989 for (var i = startIndex; i < endIndex; i++) { | 1000 for (var i = startIndex; i < endIndex; i++) { |
990 var tile = tiles[i]; | 1001 var tile = tiles[i]; |
991 this.resetTilePosition_(tile); | 1002 this.resetTilePosition_(tile); |
992 tile.style.zIndex = ''; | 1003 tile.style.zIndex = ''; |
993 tileCells[i + positionDiff].assign(tile); | 1004 var tileCell = tileCells[i + positionDiff]; |
1005 if (tileCell) | |
1006 tileCell.assign(tile); | |
994 } | 1007 } |
995 }, | 1008 }, |
996 | 1009 |
997 /** | 1010 /** |
998 * Animates the display of columns. | 1011 * Animates the display of columns. |
999 * @param {number} col The column number. | 1012 * @param {number} col The column number. |
1000 * @param {boolean} show Whether or not to show the row. | 1013 * @param {boolean} show Whether or not to show the row. |
1001 */ | 1014 */ |
1002 showTileCols_: function(col, show) { | 1015 showTileCols_: function(col, show) { |
1003 var prop = show ? 'remove' : 'add'; | 1016 var prop = show ? 'remove' : 'add'; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1095 tile.scrollTop; | 1108 tile.scrollTop; |
1096 tile.classList.remove(className); | 1109 tile.classList.remove(className); |
1097 } | 1110 } |
1098 } | 1111 } |
1099 | 1112 |
1100 return { | 1113 return { |
1101 Tile: Tile, | 1114 Tile: Tile, |
1102 TilePage: TilePage, | 1115 TilePage: TilePage, |
1103 }; | 1116 }; |
1104 }); | 1117 }); |
OLD | NEW |