From ad854df4e27e952535a0bca20686abaa6cf771db Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Sun, 4 Aug 2013 19:31:21 +0200 Subject: [PATCH] fix(app): enforce new scope for each brick --- src/angular-masonry.js | 5 +++-- test/spec/directive.coffee | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/angular-masonry.js b/src/angular-masonry.js index 1a32e71..6bf9c00 100644 --- a/src/angular-masonry.js +++ b/src/angular-masonry.js @@ -23,7 +23,7 @@ if (!found) { this.scheduleMasonry.apply(null, arguments); } - } + }; // Make sure it's only executed once within a reasonable time-frame in // case multiple elements are removed or added at once. @@ -43,7 +43,7 @@ }); schedule = []; }, 30); - } + }; function defaultLoaded($element) { $element.addClass('loaded'); @@ -116,6 +116,7 @@ return { restrict: 'AC', require: '^masonry', + scope: true, link: function postLink(scope, element, attrs, ctrl) { var id = scope.$id; diff --git a/test/spec/directive.coffee b/test/spec/directive.coffee index 31cbdb1..c1ae115 100644 --- a/test/spec/directive.coffee +++ b/test/spec/directive.coffee @@ -114,3 +114,24 @@ describe 'angular-masonry', -> expect(@appendBrick).toHaveBeenCalledThrice() expect(@removeBrick).toHaveBeenCalledOnce() ) + + describe 'masonry-brick internals', => + beforeEach -> + $.fn.imagesLoaded = (cb) -> cb() + + afterEach -> + delete $.fn.imagesLoaded + + it 'should append three elements to the controller', inject(($compile) => + element = angular.element ''' + +
+
+
+
+ ''' + element = $compile(element)(@scope) + @scope.$digest() + # 2 is resize and one layout, 3 for the elements + expect($.fn.masonry.callCount).toBe(2 + 3) + )