Skip to content

Commit

Permalink
Fixed issue with undefined post_count when loading Ajax Load More w…
Browse files Browse the repository at this point in the history
…ith Ajax/HTTP request.
  • Loading branch information
dcooney committed Feb 15, 2024
1 parent 4d73cf8 commit 81b80ac
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 38 deletions.
7 changes: 6 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: infinite scroll, load more, ajax, lazy load, endless scroll, infinite scro
Requires at least: 5.0
Requires PHP: 5.6
Tested up to: 6.4
Stable tag: 7.0.2
Stable tag: 7.0.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -260,6 +260,11 @@ How to install Ajax Load More.

== Changelog ==

= 7.0.3 - February 15, 2024 =
* FIX: Added fix for Paging add-on scrolling to top of listing on initial page load when `paging_scroll` was `true`.
* FIX: Fixed issue with undefined `post_count` when loading Ajax Load More with Ajax/HTTP request.


= 7.0.2 - February 8, 2024 =
* NEW: Added 'alm_licensing_sslverify' hook to allow users to disable SSL verification when checking for updates.
* NEW: Added new Paging add-on parameter `paging_container_classes` used for adding CSS classes to the paging HTML container.
Expand Down
6 changes: 3 additions & 3 deletions ajax-load-more.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
* Author: Darren Cooney
* Twitter: @KaptonKaos
* Author URI: https://connekthq.com
* Version: 7.0.2
* Version: 7.0.3
* License: GPL
* Copyright: Darren Cooney & Connekt Media
*
* @package AjaxLoadMore
*/

define( 'ALM_VERSION', '7.0.2' );
define( 'ALM_RELEASE', 'February 8, 2024' );
define( 'ALM_VERSION', '7.0.3' );
define( 'ALM_RELEASE', 'February 15, 2024' );
define( 'ALM_STORE_URL', 'https://connekthq.com' );

// Plugin installation helpers.
Expand Down
2 changes: 1 addition & 1 deletion build/frontend/ajax-load-more.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => '645de9921ce43595fcba');
<?php return array('dependencies' => array(), 'version' => '41bf2ff3e240f56330fa');
34 changes: 22 additions & 12 deletions build/frontend/ajax-load-more.js
Original file line number Diff line number Diff line change
Expand Up @@ -8912,15 +8912,23 @@ function pagingCreateParams(alm) {
*
* @param {Object} alm The alm object.
* @param {boolean} alm_is_filtering Is ALM filtering.
* @param {boolean} init Is first run.
*/
function pagingComplete(alm, alm_is_filtering = false) {
function pagingComplete(alm, alm_is_filtering = false, init = false) {
const { main, AjaxLoadMore, last_loaded } = alm;

main.classList.remove('alm-loading');
AjaxLoadMore.triggerAddons(alm);

if (typeof almOnPagingComplete === 'function') {
window.almOnPagingComplete(alm); // Callback: Paging Add-on Complete
if (init) {
if (typeof almPagingComplete === 'function') {
window.almPagingComplete();
}
} else {
// Dispatch almOnPagingComplete callback when not alm.init.
if (typeof almOnPagingComplete === 'function') {
window.almOnPagingComplete(alm); // Callback: Paging Add-on Complete.
}
}

if (alm_is_filtering && alm.addons.filters && typeof almFiltersAddonComplete === 'function') {
Expand Down Expand Up @@ -11392,7 +11400,12 @@ let alm_is_filtering = false;
alm.master_id = alm.master_id.replace(/-/g, '_');

// Localized <script/> variables.
alm.localize = window[alm.master_id + '_vars'];
alm.localized_var = `${alm.master_id}_vars`;
alm.localize = window[alm.localized_var];
if (!alm.localize) {
window[alm.localized_var] = {}; // Create empty object if not defined.
alm.localize = window[alm.localized_var];
}

// Add ALM object to the global window scope.
window[alm.master_id] = alm; // e.g. window.ajax_load_more or window.ajax_load_more_{id}
Expand Down Expand Up @@ -12032,7 +12045,7 @@ let alm_is_filtering = false;

// Paging -> Images Loaded: Run complete callbacks and checks.
ajax_load_more_imagesLoaded(paging_container, async function () {
pagingComplete(alm, alm_is_filtering);
pagingComplete(alm, alm_is_filtering, true);
alm_is_filtering = false;
});
}
Expand Down Expand Up @@ -12086,16 +12099,13 @@ let alm_is_filtering = false;
setFocus(alm, alm.last_loaded[0], total, alm_is_filtering);
}

// Remove filtering class
alm.main.classList.remove('alm-is-filtering');
alm.main.classList.remove('alm-is-filtering'); // Remove filtering class.

if (alm.init) {
// Add loaded class to main container on initial page load.
alm.main.classList.add('alm-is-loaded');
alm.main.classList.add('alm-is-loaded'); // Add loaded class to main container.
}

// Set init flag
alm.init = false;
alm.init = false; // Set init flag.
};

/**
Expand Down Expand Up @@ -12620,7 +12630,7 @@ let alm_is_filtering = false;
alm.AjaxLoadMore.setLocalizedVar = function (name = '', value = '') {
if (alm?.localize && name !== '' && value !== '') {
alm.localize[name] = value; // Set ALM localize var.
window[alm.master_id + '_vars'][name] = value; // Update vars.
window[alm.localized_var][name] = value; // Update vars.
}
};

Expand Down
2 changes: 1 addition & 1 deletion build/frontend/ajax-load-more.min.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => 'bb1ef978a625416f2552');
<?php return array('dependencies' => array(), 'version' => '43a8d323e2c43bc0fa4f');
2 changes: 1 addition & 1 deletion build/frontend/ajax-load-more.min.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions lang/ajax-load-more.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# This file is distributed under the GPL.
msgid ""
msgstr ""
"Project-Id-Version: Ajax Load More 7.0.2\n"
"Project-Id-Version: Ajax Load More 7.0.3\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/ajax-load-more\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2024-02-08T16:41:03+00:00\n"
"POT-Creation-Date: 2024-02-15T17:37:15+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.9.0\n"
"X-Domain: ajax-load-more\n"
Expand Down Expand Up @@ -73,7 +73,7 @@ msgstr ""
#: admin/admin.php:122
#: admin/admin.php:130
#: admin/views/settings.php:9
#: ajax-load-more.php:305
#: ajax-load-more.php:310
msgid "Settings"
msgstr ""

Expand Down Expand Up @@ -402,7 +402,7 @@ msgstr ""
#: admin/functions/settings.php:374
#: admin/shortcode-builder/shortcode-builder.php:168
#: admin/shortcode-builder/shortcode-builder.php:387
#: ajax-load-more.php:400
#: ajax-load-more.php:405
msgid "Load More"
msgstr ""

Expand Down Expand Up @@ -2719,15 +2719,15 @@ msgstr ""
msgid "Reset"
msgstr ""

#: ajax-load-more.php:282
#: ajax-load-more.php:287
msgid "Error creating repeater template directory"
msgstr ""

#: ajax-load-more.php:383
#: ajax-load-more.php:388
msgid "Viewing {post_count} of {total_posts} results."
msgstr ""

#: ajax-load-more.php:384
#: ajax-load-more.php:389
msgid "No results found."
msgstr ""

Expand Down
14 changes: 11 additions & 3 deletions src/frontend/js/addons/paging.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,23 @@ export function pagingCreateParams(alm) {
*
* @param {Object} alm The alm object.
* @param {boolean} alm_is_filtering Is ALM filtering.
* @param {boolean} init Is first run.
*/
export function pagingComplete(alm, alm_is_filtering = false) {
export function pagingComplete(alm, alm_is_filtering = false, init = false) {
const { main, AjaxLoadMore, last_loaded } = alm;

main.classList.remove('alm-loading');
AjaxLoadMore.triggerAddons(alm);

if (typeof almOnPagingComplete === 'function') {
window.almOnPagingComplete(alm); // Callback: Paging Add-on Complete
if (init) {
if (typeof almPagingComplete === 'function') {
window.almPagingComplete();
}
} else {
// Dispatch almOnPagingComplete callback when not alm.init.
if (typeof almOnPagingComplete === 'function') {
window.almOnPagingComplete(alm); // Callback: Paging Add-on Complete.
}
}

if (alm_is_filtering && alm.addons.filters && typeof almFiltersAddonComplete === 'function') {
Expand Down
20 changes: 11 additions & 9 deletions src/frontend/js/ajax-load-more.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ let alm_is_filtering = false;
alm.master_id = alm.master_id.replace(/-/g, '_');

// Localized <script/> variables.
alm.localize = window[alm.master_id + '_vars'];
alm.localized_var = `${alm.master_id}_vars`;
alm.localize = window[alm.localized_var];
if (!alm.localize) {
window[alm.localized_var] = {}; // Create empty object if not defined.
alm.localize = window[alm.localized_var];
}

// Add ALM object to the global window scope.
window[alm.master_id] = alm; // e.g. window.ajax_load_more or window.ajax_load_more_{id}
Expand Down Expand Up @@ -743,7 +748,7 @@ let alm_is_filtering = false;

// Paging -> Images Loaded: Run complete callbacks and checks.
imagesLoaded(paging_container, async function () {
pagingComplete(alm, alm_is_filtering);
pagingComplete(alm, alm_is_filtering, true);
alm_is_filtering = false;
});
}
Expand Down Expand Up @@ -797,16 +802,13 @@ let alm_is_filtering = false;
setFocus(alm, alm.last_loaded[0], total, alm_is_filtering);
}

// Remove filtering class
alm.main.classList.remove('alm-is-filtering');
alm.main.classList.remove('alm-is-filtering'); // Remove filtering class.

if (alm.init) {
// Add loaded class to main container on initial page load.
alm.main.classList.add('alm-is-loaded');
alm.main.classList.add('alm-is-loaded'); // Add loaded class to main container.
}

// Set init flag
alm.init = false;
alm.init = false; // Set init flag.
};

/**
Expand Down Expand Up @@ -1331,7 +1333,7 @@ let alm_is_filtering = false;
alm.AjaxLoadMore.setLocalizedVar = function (name = '', value = '') {
if (alm?.localize && name !== '' && value !== '') {
alm.localize[name] = value; // Set ALM localize var.
window[alm.master_id + '_vars'][name] = value; // Update vars.
window[alm.localized_var][name] = value; // Update vars.
}
};

Expand Down

0 comments on commit 81b80ac

Please sign in to comment.