Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

fix(gridlist): Tile removal now supports ngAnimate #1560

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions src/components/gridList/gridList.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,21 +270,16 @@ function GridListDirective($interpolate, $mdConstant, $mdGridLayout, $mdMedia, $
}

function getTileElements() {
// element[0].querySelectorAll(':scope > md-grid-tile') would be
// preferred, but is not yet widely supported.
return Array.prototype.slice.call(element[0].childNodes)
.filter(function(child) {
return child.tagName == 'MD-GRID-TILE';
});
return ctrl.tiles.map(function(tile) { return tile.element });
}

function getTileSpans() {
return ctrl.tiles.map(function(tileAttrs) {
return ctrl.tiles.map(function(tile) {
return {
row: parseInt(
$mdMedia.getResponsiveAttribute(tileAttrs, 'md-rowspan'), 10) || 1,
$mdMedia.getResponsiveAttribute(tile.attrs, 'md-rowspan'), 10) || 1,
col: parseInt(
$mdMedia.getResponsiveAttribute(tileAttrs, 'md-colspan'), 10) || 1
$mdMedia.getResponsiveAttribute(tile.attrs, 'md-colspan'), 10) || 1
};
});
}
Expand Down Expand Up @@ -340,17 +335,18 @@ function GridListController($timeout) {
}

GridListController.prototype = {
addTile: function(tileAttrs, idx) {
addTile: function(tileElement, tileAttrs, idx) {
var tile = { element: tileElement, attrs: tileAttrs };
if (angular.isUndefined(idx)) {
this.tiles.push(tileAttrs);
this.tiles.push(tile);
} else {
this.tiles.splice(idx, 0, tileAttrs);
this.tiles.splice(idx, 0, tile);
}
this.invalidateLayout();
},

removeTile: function(tileAttrs) {
var idx = this.tiles.indexOf(tileAttrs);
removeTile: function(tileElement, tileAttrs) {
var idx = this._findTileIndex(tileAttrs);
if (idx === -1) {
return;
}
Expand All @@ -372,6 +368,15 @@ GridListController.prototype = {
} finally {
this.invalidated = false;
}
},

_findTileIndex: function(tileAttrs) {
for (var i = 0; i < this.tiles.length; i++) {
if (this.tiles[i].attrs == tileAttrs) {
return i;
}
}
return -1;
}
}

Expand Down Expand Up @@ -636,6 +641,7 @@ function GridTileDirective($mdMedia) {
require: '^mdGridList',
template: '<figure ng-transclude></figure>',
transclude: true,
scope: {},
link: postLink
};

Expand All @@ -650,10 +656,10 @@ function GridTileDirective($mdMedia) {
// Tile registration/deregistration
// TODO(shyndman): Kind of gross to access parent scope like this.
// Consider other options.
gridCtrl.addTile(attrs, scope.$parent.$index);
gridCtrl.addTile(element, attrs, scope.$parent.$index);
scope.$on('$destroy', function() {
unwatchAttrs();
gridCtrl.removeTile(attrs);
gridCtrl.removeTile(element, attrs);
});
}
}
Expand Down