3
3
*
4
4
* @since 1.0.0
5
5
*/
6
- ( function ( $ ) {
6
+ ( function ( $ ) {
7
7
8
- var gather = {
8
+ var gather = {
9
9
10
- // Cache selectors
11
- cache : {
10
+ // Cache selectors
11
+ cache : {
12
12
$document : $ ( document ) ,
13
13
$window : $ ( window ) ,
14
14
$postswrap : $ ( '#posts-wrap' ) ,
114
114
115
115
var width = document . body . clientWidth ;
116
116
117
- // So cached selectors can be used in functions
118
- var self = this ;
119
-
120
117
// If body width is less than 510px we'll display as a single column
121
118
if ( width <= 510 ) {
122
-
123
- // If screen has been resized to below 510, remove masonry.
124
- // This ensures "Load More" button loads properly.
125
- if ( self . cache . masonryLoaded ) {
126
- self . cache . $postswrap . masonry ( ) . masonry ( 'destroy' ) ;
127
- }
128
-
129
119
return ;
130
120
}
131
121
135
125
if ( document . body . clientWidth <= 880 ) {
136
126
gutter = 20 ;
137
127
}
128
+
129
+ var $postswrap = this . cache . $postswrap ;
130
+ var self = this ;
138
131
139
- // Initialize
140
- this . cache . $ postswrap. imagesLoaded ( function ( ) {
141
- self . cache . $postswrap . find ( '.module' ) . css ( { 'margin-right' : 0 } ) ;
142
- self . cache . $postswrap . masonry ( {
132
+ $postswrap . imagesLoaded ( function ( ) {
133
+ $posts = $ postswrap. find ( '.module' ) . css ( { 'margin-right' : 0 } ) . addClass ( 'masonry' ) ;
134
+
135
+ $postswrap . masonry ( {
143
136
itemSelector : '.module' ,
137
+ transitionDuration : 0 ,
144
138
gutter : gutter
145
139
} ) ;
146
- self . cache . masonryLoaded = true ;
147
140
} ) ;
141
+
142
+ // Handle Masonry on Resize
143
+ $ ( document . body ) . on ( 'jetpack-lazy-loaded-image' , self . debounce (
144
+ function ( ) {
145
+ $postswrap . masonry ( 'reloadItems' ) . masonry ( 'layout' ) ;
146
+ } , 200 )
147
+ ) ;
148
148
149
- // For Infinite Scroll
150
- var infinite_count = 0 ;
149
+ // Layout posts that arrive via infinite scroll.
150
+ $ ( document . body ) . on ( 'post-load' , function ( ) {
151
+ var $newItems = $postswrap . find ( '.module' ) . not ( '.masonry' ) ;
152
+ $newItems . css ( { 'margin-right' : 0 } ) . addClass ( 'masonry' ) ;
151
153
152
- $ ( document . body ) . on ( 'post-load' , function ( ) {
154
+ $newItems . hide ( ) ;
155
+ $postswrap . append ( $newItems ) ;
153
156
154
- infinite_count = infinite_count + 1 ;
155
- var $newItems = $ ( '#infinite-view-' + infinite_count ) . not ( '.is--replaced' ) ;
156
- var $elements = $newItems . find ( '.module' ) ;
157
- $elements . hide ( ) ;
158
- self . cache . $postswrap . append ( $elements ) ;
159
- $elements . imagesLoaded ( function ( ) {
160
- self . cache . $postswrap . masonry ( "appended" , $elements , true ) . masonry ( "reloadItems" ) . masonry ( "layout" ) ;
161
- $elements . fadeIn ( ) ;
157
+ $postswrap . imagesLoaded ( function ( ) {
158
+ $postswrap . masonry ( 'appended' , $newItems , true ) . masonry ( 'reloadItems' ) . masonry ( 'layout' ) ;
159
+ $newItems . show ( 200 ) ;
162
160
} ) ;
163
-
164
161
} ) ;
165
162
166
163
} ,
184
181
} ;
185
182
}
186
183
187
- } ;
184
+ } ;
188
185
189
- gather . init ( ) ;
186
+ gather . init ( ) ;
190
187
191
- } ) ( jQuery ) ;
188
+ } ) ( jQuery ) ;
0 commit comments