This repository was archived by the owner on Dec 30, 2018. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -118,6 +118,24 @@ hidden it may not render properly when shown again.
118118
119119When ` showList ` changes from falsey to truthy ` ctrl.reload ` will be called.
120120
121+
122+ ### ` reload-on-resize `
123+
124+ The ` reload-on-resize ` attribute triggers a reload when the masonry element changes
125+ its width, useful when only the parent element is resized (and not the window) and
126+ you want the elements to be rearranged. Without this if the parent is resized then
127+ some blank space may be left on the sides.
128+
129+ * Example:*
130+
131+ ``` html
132+ <masonry reload-on-resize >
133+ <div class =" masonry-brick" >...</div >
134+ <div class =" masonry-brick" >...</div >
135+ </masonry >
136+ ```
137+
138+
121139### ` masonry-options `
122140
123141You can provide [ additional options] ( http://masonry.desandro.com/options.html )
Original file line number Diff line number Diff line change 145145 }
146146 } ) ;
147147 }
148+ var reloadOnResize = scope . $eval ( attrs . reloadOnResize ) ;
149+ if ( reloadOnResize !== false && attrs . reloadOnResize !== undefined ) {
150+ scope . $watch ( function ( ) {
151+ return element . prop ( 'offsetWidth' ) ;
152+ } , function ( newWidth , oldWidth ) {
153+ if ( newWidth != oldWidth ) {
154+ ctrl . reload ( ) ;
155+ }
156+ } ) ;
157+ }
148158
149159 scope . $emit ( 'masonry.created' , element ) ;
150160 scope . $on ( '$destroy' , ctrl . destroy ) ;
Original file line number Diff line number Diff line change @@ -77,6 +77,22 @@ describe 'angular-masonry', ->
7777 expect (@scope .$watch ).not .toHaveBeenCalled ()
7878 )
7979
80+ it ' should setup a $watch when the reload-on-resize is present' , inject (($compile ) =>
81+ sinon .spy (@scope , ' $watch' )
82+ element = angular .element ' <masonry reload-on-resize></masonry>'
83+ element = $compile (element)(@scope )
84+
85+ expect (@scope .$watch ).toHaveBeenCalled ()
86+ )
87+
88+ it ' should not setup a $watch when the reload-on-resize is missing' , inject (($compile ) =>
89+ sinon .spy (@scope , ' $watch' )
90+ element = angular .element ' <masonry></masonry>'
91+ element = $compile (element)(@scope )
92+
93+ expect (@scope .$watch ).not .toHaveBeenCalled ()
94+ )
95+
8096 describe ' MasonryCtrl' , =>
8197 beforeEach inject (($controller , $compile ) =>
8298 @element = angular .element ' <div></div>'
You can’t perform that action at this time.
0 commit comments