Skip to content

Commit

Permalink
use events to call parent functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Flynn committed Jun 22, 2016
1 parent cf8249f commit a671eb3
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/angular-masonry-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,41 @@
});

scope.update();

scope.$on('ngMasonry.update', function () {
scope.update();
});

scope.$on('ngMasonry.removeBrick', function () {
scope.removeBrick();
});

scope.$on('ngMasonry.appendBricks', function (el) {
scope.appendBricks(el);
});
}
};
}]).directive('masonryTile', function() {
return {
restrict: 'AC',
link: function(scope, elem) {
elem.css('visibility', 'hidden');
var master = elem.parent('*[masonry]:first').scope(),
update = master.update,
removeBrick = master.removeBrick,
appendBricks = master.appendBricks;
var update = function () {
scope.$emit('ngMasonry.update');
};
var removeBrick = function () {
scope.$emit('ngMasonry.removeBrick');
};
var appendBricks = function (el) {
scope.$emit('ngMasonry.appendBricks', el);
};

if (update) {
imagesLoaded( elem.get(0), update);
imagesLoaded(elem.get(0), update);
elem.ready(update);
}
if (appendBricks) {
imagesLoaded( elem.get(0), appendBricks(elem));
imagesLoaded(elem.get(0), appendBricks(elem));
}
scope.$on('$destroy', function() {
if (removeBrick) {
Expand Down

0 comments on commit a671eb3

Please sign in to comment.