Skip to content

Commit

Permalink
Merge pull request klederson#2 from joeflynn/master
Browse files Browse the repository at this point in the history
use events to call parent functions
  • Loading branch information
Joe Flynn authored Jun 22, 2016
2 parents 8b46ef5 + a671eb3 commit bf2069a
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 bf2069a

Please sign in to comment.