Skip to content

Commit 2d5f8fd

Browse files
committedOct 30, 2019
Version 1.4.0 - Lazy loading and infinite scroll improvements.
1 parent db5707c commit 2d5f8fd

File tree

6 files changed

+41
-39
lines changed

6 files changed

+41
-39
lines changed
 

‎functions.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* The current version of the theme.
1010
*/
11-
define( 'GATHER_VERSION', '1.3.0' );
11+
define( 'GATHER_VERSION', '1.4.0' );
1212

1313
if ( ! function_exists( 'gather_setup' ) ) :
1414
/**
@@ -233,7 +233,7 @@ function gather_scripts() {
233233
);
234234

235235
if ( gather_load_masonry() ) {
236-
wp_enqueue_script( 'masonry' );
236+
wp_enqueue_script( 'masonry' );
237237
}
238238

239239
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {

‎js/theme.js

+31-34
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
*
44
* @since 1.0.0
55
*/
6-
(function($) {
6+
(function($) {
77

8-
var gather = {
8+
var gather = {
99

10-
// Cache selectors
11-
cache: {
10+
// Cache selectors
11+
cache: {
1212
$document: $(document),
1313
$window: $(window),
1414
$postswrap: $('#posts-wrap'),
@@ -114,18 +114,8 @@
114114

115115
var width = document.body.clientWidth;
116116

117-
// So cached selectors can be used in functions
118-
var self = this;
119-
120117
// If body width is less than 510px we'll display as a single column
121118
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-
129119
return;
130120
}
131121

@@ -135,32 +125,39 @@
135125
if ( document.body.clientWidth <= 880 ) {
136126
gutter = 20;
137127
}
128+
129+
var $postswrap = this.cache.$postswrap;
130+
var self = this;
138131

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({
143136
itemSelector: '.module',
137+
transitionDuration: 0,
144138
gutter : gutter
145139
});
146-
self.cache.masonryLoaded = true;
147140
});
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+
);
148148

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');
151153

152-
$( document.body ).on( 'post-load', function () {
154+
$newItems.hide();
155+
$postswrap.append($newItems);
153156

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);
162160
});
163-
164161
});
165162

166163
},
@@ -184,8 +181,8 @@
184181
};
185182
}
186183

187-
};
184+
};
188185

189-
gather.init();
186+
gather.init();
190187

191-
})(jQuery);
188+
})(jQuery);

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gather",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"repository": "https://github.com/DevPress/wpcom-gather",
55
"licence": "GPL",
66
"devDependencies": {

‎readme.txt

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ If you have Grunt installed, just run `npm install` in the theme directory to do
1919

2020
## Change Log
2121

22+
1.4.0
23+
---
24+
25+
* Fix: Improved support for Jetpack Lazy Load and Infinite Scroll
26+
2227
1.3.0
2328
---
2429

‎scss/style.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Theme URI: https://devpress.com/gather
44
Author: DevPress
55
Author URI: https://devpress.com
66
Description: Gather is a highly adaptable theme for displaying products, art, and content. Multiple menu locations, social icons, and widget areas are available. Gather is responsive and looks great on all devices.
7-
Version: 1.3.0
7+
Version: 1.4.0
88
License: GNU General Public License v2 or later
99
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1010
Text Domain: gather

‎style.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.