Skip to content
This repository was archived by the owner on Dec 30, 2018. It is now read-only.

Commit ad854df

Browse files
committed
fix(app): enforce new scope for each brick
1 parent 65a98af commit ad854df

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/angular-masonry.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
if (!found) {
2424
this.scheduleMasonry.apply(null, arguments);
2525
}
26-
}
26+
};
2727

2828
// Make sure it's only executed once within a reasonable time-frame in
2929
// case multiple elements are removed or added at once.
@@ -43,7 +43,7 @@
4343
});
4444
schedule = [];
4545
}, 30);
46-
}
46+
};
4747

4848
function defaultLoaded($element) {
4949
$element.addClass('loaded');
@@ -116,6 +116,7 @@
116116
return {
117117
restrict: 'AC',
118118
require: '^masonry',
119+
scope: true,
119120
link: function postLink(scope, element, attrs, ctrl) {
120121
var id = scope.$id;
121122

test/spec/directive.coffee

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,24 @@ describe 'angular-masonry', ->
114114
expect(@appendBrick).toHaveBeenCalledThrice()
115115
expect(@removeBrick).toHaveBeenCalledOnce()
116116
)
117+
118+
describe 'masonry-brick internals', =>
119+
beforeEach ->
120+
$.fn.imagesLoaded = (cb) -> cb()
121+
122+
afterEach ->
123+
delete $.fn.imagesLoaded
124+
125+
it 'should append three elements to the controller', inject(($compile) =>
126+
element = angular.element '''
127+
<masonry>
128+
<div class="masonry-brick"></div>
129+
<div class="masonry-brick"></div>
130+
<div class="masonry-brick"></div>
131+
</masonry>
132+
'''
133+
element = $compile(element)(@scope)
134+
@scope.$digest()
135+
# 2 is resize and one layout, 3 for the elements
136+
expect($.fn.masonry.callCount).toBe(2 + 3)
137+
)

0 commit comments

Comments
 (0)