This repository was archived by the owner on Dec 30, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,24 @@ doesn't actually make use of images.
98
98
</masonry >
99
99
```
100
100
101
+ ### ` reload-on-show `
102
+
103
+ The ` reload-on-show ` attribute triggers a reload when the masonry element (or an
104
+ ancestor element) is shown after being hidden, useful when using ` ng-show ` or
105
+ ` ng-hide ` . Without this if the viewport is resized while the masonry element is
106
+ hidden it may not render properly when shown again.
107
+
108
+ * Example:*
109
+
110
+ ``` html
111
+ <masonry reload-on-show ng-show =" showList" >
112
+ <div class =" masonry-brick" >...</div >
113
+ <div class =" masonry-brick" >...</div >
114
+ </masonry >
115
+ ```
116
+
117
+ When ` showList ` changes from falsey to truthy ` ctrl.reload ` will be called.
118
+
101
119
### ` masonry-options `
102
120
103
121
You can provide [ additional options] ( http://masonry.desandro.com/options.html )
Original file line number Diff line number Diff line change 135
135
ctrl . loadImages = loadImages !== false ;
136
136
var preserveOrder = scope . $eval ( attrs . preserveOrder ) ;
137
137
ctrl . preserveOrder = ( preserveOrder !== false && attrs . preserveOrder !== undefined ) ;
138
+ var reloadOnShow = scope . $eval ( attrs . reloadOnShow ) ;
139
+ if ( reloadOnShow !== false && attrs . reloadOnShow !== undefined ) {
140
+ scope . $watch ( function ( ) {
141
+ return element . prop ( 'offsetParent' ) ;
142
+ } , function ( isVisible , wasVisible ) {
143
+ if ( isVisible && ! wasVisible ) {
144
+ ctrl . reload ( ) ;
145
+ }
146
+ } ) ;
147
+ }
138
148
139
149
scope . $emit ( 'masonry.created' , element ) ;
140
150
scope . $on ( '$destroy' , ctrl . destroy ) ;
Original file line number Diff line number Diff line change @@ -61,6 +61,22 @@ describe 'angular-masonry', ->
61
61
expect (call .args [0 ].isOriginLeft ).toBeTruthy ()
62
62
)
63
63
64
+ it ' should setup a $watch when the reload-on-show is present' , inject (($compile ) =>
65
+ sinon .spy (@scope , ' $watch' )
66
+ element = angular .element ' <masonry reload-on-show></masonry>'
67
+ element = $compile (element)(@scope )
68
+
69
+ expect (@scope .$watch ).toHaveBeenCalled ()
70
+ )
71
+
72
+ it ' should not setup a $watch when the reload-on-show is missing' , inject (($compile ) =>
73
+ sinon .spy (@scope , ' $watch' )
74
+ element = angular .element ' <masonry></masonry>'
75
+ element = $compile (element)(@scope )
76
+
77
+ expect (@scope .$watch ).not .toHaveBeenCalled ()
78
+ )
79
+
64
80
describe ' MasonryCtrl' , =>
65
81
beforeEach inject (($controller , $compile ) =>
66
82
@element = angular .element ' <div></div>'
You can’t perform that action at this time.
0 commit comments