From 7103974794d831fcab581ccb00572851e7158a39 Mon Sep 17 00:00:00 2001 From: Darren Cooney Date: Wed, 3 May 2023 10:25:16 -0400 Subject: [PATCH 01/18] Updated cache functionality to make it easier to load cache data. --- ajax-load-more.php | 76 +++++++++++++++--------------- core/dist/js/ajax-load-more.js | 42 +++++------------ core/src/js/ajax-load-more.js | 38 ++++----------- core/src/js/helpers/queryParams.js | 1 - 4 files changed, 58 insertions(+), 99 deletions(-) diff --git a/ajax-load-more.php b/ajax-load-more.php index d35f3e5..0af4bcf 100755 --- a/ajax-load-more.php +++ b/ajax-load-more.php @@ -14,6 +14,15 @@ * @package AjaxLoadMore */ +/* + +STARTED: +- Cache update. + +TODO: + +*/ + define( 'ALM_VERSION', '5.6.0.5' ); define( 'ALM_RELEASE', 'April 3, 2023' ); define( 'ALM_STORE_URL', 'https://connekthq.com' ); @@ -431,7 +440,7 @@ public function alm_query_posts() { $filters_startpage = isset( $params['filters_startpage'] ) && $is_filters ? $params['filters_startpage'] : 0; // Cache. - $cache_id = isset( $params['cache_id'] ) ? $params['cache_id'] : ''; + $cache_id = isset( $params['cache_id'] ) && ! empty( $params['cache_id'] ) ? $params['cache_id'] : false; $cache_logged_in = isset( $params['cache_logged_in'] ) ? $params['cache_logged_in'] : false; $do_create_cache = $cache_logged_in === 'true' && is_user_logged_in() ? false : true; @@ -539,6 +548,30 @@ public function alm_query_posts() { */ $args['alm_query'] = $single_post ? 'single_posts' : 'alm'; + // MD5 hash of $args. + $md5_hash = md5( wp_json_encode( $args ) ); + + /** + * Cache Add-on. + * Check for cached data before running WP_Query. + */ + if ( $cache_id && has_filter( 'alm_cache_get_cache_file' ) && $query_type !== 'totalposts' ) { + $cache_data = apply_filters( 'alm_cache_get_cache_file', $cache_id, $md5_hash ); + + if ( $cache_data ) { + wp_send_json( + [ + 'html' => $cache_data, + 'meta' => [ + 'postcount' => 5, + 'totalposts' => 10, + 'debug' => false, + ], + ] + ); + } + } + /** * Custom WP_Query. * @@ -566,19 +599,6 @@ public function alm_query_posts() { $alm_loop_count = 0; } - /** - * Cache Add-on hook - Create cache directory + info .txt file. - */ - if ( ! empty( $cache_id ) && has_action( 'alm_cache_create_dir' ) && $do_create_cache ) { - apply_filters( 'alm_cache_create_dir', $cache_id, $canonical_url ); - - // Filters || WooCommerce Cache Support. - if ( $is_filters && has_filter( 'alm_cache_create_nested_id' ) ) { - $cache_id = apply_filters( 'alm_cache_create_nested_id', $cache_id ); - apply_filters( 'alm_cache_create_dir', $cache_id, $_SERVER['HTTP_REFERER'] ); - } - } - if ( $query_type === 'totalposts' ) { // Paging add-on. wp_send_json( @@ -643,32 +663,14 @@ public function alm_query_posts() { $data = ob_get_clean(); /** - * Cache Add-on hook - If Cache is enabled, check the cache file + * Cache Add-on. + * Create the cache file. * - * @param string $cache_id ID of the ALM cache - * @param boolean $do_create_cache Should cache be created for this user * @since 3.2.1 */ - if ( ! empty( $cache_id ) && has_action( 'alm_cache_installed' ) && $do_create_cache ) { - if ( $single_post ) { - // Single Post Cache. - apply_filters( 'alm_previous_post_cache_file', $cache_id, $single_post_id, $data ); - - } else { - // Standard Cache. - - // Filters. - $startpage = $is_filters ? $filters_startpage : $seo_start_page; - - // Filters and Preloaded. - // - add 2 pages to maintain paging compatibility when returning to the same listing via filter. - // - set $page to $startpage. - if ( $is_filters && $preloaded === 'true' ) { - $startpage = $startpage + 1; // phpcs:ignore - $page = $page + 1; // phpcs:ignore - } - apply_filters( 'alm_cache_file', $cache_id, $page, $startpage, $data, $preloaded ); - } + if ( $cache_id && has_action( 'alm_cache_create_file' ) && $do_create_cache ) { + $cache_name = $single_post ? $single_post_id : $md5_hash; + apply_filters( 'alm_cache_create_file', $cache_id, $cache_name, $canonical_url, $data ); } $return = [ diff --git a/core/dist/js/ajax-load-more.js b/core/dist/js/ajax-load-more.js index df1d6e6..adbb0b8 100644 --- a/core/dist/js/ajax-load-more.js +++ b/core/dist/js/ajax-load-more.js @@ -423,7 +423,7 @@ function elementorCreateParams(alm) { // Parse Container Settings alm.addons.elementor_target = alm.addons.elementor_settings.target; - alm.addons.elementor_element = alm.addons.elementor_settings.target ? document.querySelector('.elementor-widget-wrap ' + alm.addons.elementor_settings.target) : ''; + alm.addons.elementor_element = alm.addons.elementor_settings.target ? document.querySelector('.elementor-element ' + alm.addons.elementor_settings.target) : ''; alm.addons.elementor_widget = elementorGetWidgetType(alm.addons.elementor_element); // Masonry @@ -2223,26 +2223,8 @@ var alm_is_filtering = false; } } - // Cache - if (alm.addons.cache === 'true' && !alm.addons.cache_logged_in) { - var cache_page = (0, _getCacheUrl2.default)(alm); - if (cache_page) { - _axios2.default.get(cache_page).then(function (response) { - // Exists - alm.AjaxLoadMore.success(response.data, true); - }).catch(function (error) { - // Error || Page does not yet exist - // console.log(error); - alm.AjaxLoadMore.ajax(); - }); - } else { - // Standard ALM query - alm.AjaxLoadMore.ajax(); - } - } else { - // Standard ALM query - alm.AjaxLoadMore.ajax(); - } + // Standard ALM query + alm.AjaxLoadMore.ajax(); }; /** @@ -2352,18 +2334,17 @@ var alm_is_filtering = false; }; } - // REST API + // Dispatch Ajax request. if (alm.extensions.restapi) { + // REST API alm.AjaxLoadMore.restapi(alm, action, queryType); - } - // Tabs - else if (alm.addons.tabs) { - alm.AjaxLoadMore.tabs(alm); - } + } else if (alm.addons.tabs) { + // Tabs + alm.AjaxLoadMore.tabs(alm); + } else { // Standard ALM - else { - alm.AjaxLoadMore.adminajax(alm, action, queryType); - } + alm.AjaxLoadMore.adminajax(alm, action, queryType); + } }; /** @@ -5268,7 +5249,6 @@ function almGetAjaxParams(alm, action, queryType) { }; // Addons & Extensions - if (alm.theme_repeater) { data.theme_repeater = alm.theme_repeater; } diff --git a/core/src/js/ajax-load-more.js b/core/src/js/ajax-load-more.js index 9751d61..512f9ad 100755 --- a/core/src/js/ajax-load-more.js +++ b/core/src/js/ajax-load-more.js @@ -646,29 +646,8 @@ let alm_is_filtering = false; } } - // Cache - if (alm.addons.cache === 'true' && !alm.addons.cache_logged_in) { - const cache_page = getCacheUrl(alm); - if (cache_page) { - axios - .get(cache_page) - .then((response) => { - // Exists - alm.AjaxLoadMore.success(response.data, true); - }) - .catch(function (error) { - // Error || Page does not yet exist - // console.log(error); - alm.AjaxLoadMore.ajax(); - }); - } else { - // Standard ALM query - alm.AjaxLoadMore.ajax(); - } - } else { - // Standard ALM query - alm.AjaxLoadMore.ajax(); - } + // Standard ALM query + alm.AjaxLoadMore.ajax(); }; /** @@ -776,16 +755,15 @@ let alm_is_filtering = false; }; } - // REST API + // Dispatch Ajax request. if (alm.extensions.restapi) { + // REST API alm.AjaxLoadMore.restapi(alm, action, queryType); - } - // Tabs - else if (alm.addons.tabs) { + } else if (alm.addons.tabs) { + // Tabs alm.AjaxLoadMore.tabs(alm); - } - // Standard ALM - else { + } else { + // Standard ALM alm.AjaxLoadMore.adminajax(alm, action, queryType); } }; diff --git a/core/src/js/helpers/queryParams.js b/core/src/js/helpers/queryParams.js index ffba4f0..a92127f 100755 --- a/core/src/js/helpers/queryParams.js +++ b/core/src/js/helpers/queryParams.js @@ -24,7 +24,6 @@ export function almGetAjaxParams(alm, action, queryType) { }; // Addons & Extensions - if (alm.theme_repeater) { data.theme_repeater = alm.theme_repeater; } From 5546ea9c09ce76b1410ee4b398bdded6d606ced1 Mon Sep 17 00:00:00 2001 From: Darren Cooney Date: Thu, 4 May 2023 07:53:36 -0400 Subject: [PATCH 02/18] Adding cache 2.0 minimum requirement --- ajax-load-more.php | 35 ++++++++++--- core/classes/class-alm-shortcode.php | 21 ++++---- core/dist/js/ajax-load-more.js | 68 +++++++++----------------- core/src/js/ajax-load-more.js | 73 ++++++++++------------------ 4 files changed, 88 insertions(+), 109 deletions(-) diff --git a/ajax-load-more.php b/ajax-load-more.php index 0af4bcf..507c0df 100755 --- a/ajax-load-more.php +++ b/ajax-load-more.php @@ -15,11 +15,30 @@ */ /* - +CACHE UPDATES: STARTED: - Cache update. TODO: +- Filters [DONE] +- Paging [DONE] +- SEO [DONE] +- Nextpage +- Comments +- ACF +- Terms +- Single Posts + +- Update cache admin screen. Expand/Collapse files. +- Ensure backward compatibility. + + + +CHANGES +* NOTICE: Ajax Load More 6.0 is a major update and includes a number of breaking changes. Please review the documentation before updating. +* NOTICE: Cache add-on < 2.0 is no longer supported. Please update to the latest version of the Cache add-on. + +* UPDATE: Adding required functionality for the Cache 2.0 update. This introduces a new cache structure using MD5 hash for cache URLs. */ @@ -557,14 +576,14 @@ public function alm_query_posts() { */ if ( $cache_id && has_filter( 'alm_cache_get_cache_file' ) && $query_type !== 'totalposts' ) { $cache_data = apply_filters( 'alm_cache_get_cache_file', $cache_id, $md5_hash ); - - if ( $cache_data ) { + if ( $cache_data && $cache_data['html'] ) { wp_send_json( [ - 'html' => $cache_data, + 'html' => $cache_data['html'], 'meta' => [ - 'postcount' => 5, - 'totalposts' => 10, + 'postcount' => $cache_data['count'], + 'totalposts' => $cache_data['total'], + 'type' => 'cache', 'debug' => false, ], ] @@ -670,7 +689,7 @@ public function alm_query_posts() { */ if ( $cache_id && has_action( 'alm_cache_create_file' ) && $do_create_cache ) { $cache_name = $single_post ? $single_post_id : $md5_hash; - apply_filters( 'alm_cache_create_file', $cache_id, $cache_name, $canonical_url, $data ); + apply_filters( 'alm_cache_create_file', $cache_id, $cache_name, $canonical_url, $data, $alm_current, $alm_found_posts ); } $return = [ @@ -678,6 +697,7 @@ public function alm_query_posts() { 'meta' => [ 'postcount' => $alm_post_count, 'totalposts' => $alm_found_posts, + 'type' => 'standard', 'debug' => $debug, ], ]; @@ -695,6 +715,7 @@ public function alm_query_posts() { 'meta' => [ 'postcount' => 0, 'totalposts' => 0, + 'type' => 'standard', 'debug' => $debug, ], ]; diff --git a/core/classes/class-alm-shortcode.php b/core/classes/class-alm-shortcode.php index c49df54..3f54512 100755 --- a/core/classes/class-alm-shortcode.php +++ b/core/classes/class-alm-shortcode.php @@ -851,17 +851,18 @@ public static function alm_render_shortcode( $atts ) { // Cache Add-on. $alm_auto_cache = isset( $_GET['alm_auto_cache'] ) ? true : false; if ( has_action( 'alm_cache_installed' ) && $cache === 'true' ) { - $cache_return = apply_filters( - 'alm_cache_shortcode', - $cache, - $cache_id, - $options - ); - if ( $alm_auto_cache ) { - // Disable paging if auto generate cache active. - $paging = false; + // Confirm cache version is 1.0.0 or greater. + $cache_version_check = defined( 'ALM_CACHE_VERSION' ) && version_compare( ALM_CACHE_VERSION, '2.0.0', '>=' ); + if ( $cache_version_check ) { + $cache_return = apply_filters( + 'alm_cache_shortcode', + $cache, + $cache_id, + $options + ); + $paging = $alm_auto_cache ? false : $paging; // Disable paging if auto generate cache active. + $ajaxloadmore .= wp_kses_post( $cache_return ); } - $ajaxloadmore .= wp_kses_post( $cache_return ); } // CTA Add-on. diff --git a/core/dist/js/ajax-load-more.js b/core/dist/js/ajax-load-more.js index adbb0b8..e2b3f68 100644 --- a/core/dist/js/ajax-load-more.js +++ b/core/dist/js/ajax-load-more.js @@ -2417,7 +2417,7 @@ var alm_is_filtering = false; // Standard Query if (queryType === 'standard') { - alm.AjaxLoadMore.success(data, false); + alm.AjaxLoadMore.success(data); } else if (queryType === 'totalpages' && alm.addons.paging && alm.addons.nextpage) { // Next Page and Paging if (typeof almBuildPagination === 'function') { @@ -2476,7 +2476,7 @@ var alm_is_filtering = false; totalposts: 1 } }; - alm.AjaxLoadMore.success(obj, false); // Send data + alm.AjaxLoadMore.success(obj); // Send data // Callback to Tabs add-on if (typeof almTabLoaded === 'function') { @@ -2544,7 +2544,7 @@ var alm_is_filtering = false; totalposts: totalposts } }; - alm.AjaxLoadMore.success(obj, false); // Send data + alm.AjaxLoadMore.success(obj); // Send data }).catch(function (error) { // Error alm.AjaxLoadMore.error(error, 'restapi'); @@ -2563,16 +2563,14 @@ var alm_is_filtering = false; /** * Success function after loading data. * - * @param {object} data The results of the Ajax request. - * @param {boolean} is_cache Are results of the Ajax request coming from cache? + * @param {object} data The results of the Ajax request. * @since 2.6.0 */ - alm.AjaxLoadMore.success = function (data, is_cache) { + alm.AjaxLoadMore.success = function (data) { var _this = this; if (alm.addons.single_post) { - // Get previous page data - alm.AjaxLoadMore.getSinglePost(); + alm.AjaxLoadMore.getSinglePost(); // Get previous post data } var isPaged = false; @@ -2588,34 +2586,28 @@ var alm_is_filtering = false; var pagingContent = alm.listing.querySelector('.alm-paging-content'); var html = void 0, - meta = void 0, total = void 0; - if (is_cache) { - // If Cache, do not look for json data as we won't be querying the DB. - html = data; - } else { - // Standard ALM query results - html = data.html; - meta = data.meta; - total = meta ? parseInt(meta.postcount) : parseInt(alm.posts_per_page); - - var totalposts = typeof meta !== 'undefined' ? meta.totalposts : alm.posts_per_page * 5; - alm.totalposts = alm.addons.preloaded === 'true' ? totalposts - alm.addons.preloaded_amount : totalposts; - alm.posts = alm.addons.paging ? total : alm.posts + total; - alm.debug = meta.debug ? meta.debug : ''; - - if (!meta) { - // Display warning if `meta` is missing. - console.warn('Ajax Load More: Unable to access `meta` object in Ajax response. There may be an issue in your Repeater Template or another hook causing interference.'); - } + html = data.html; + var meta = data.meta; + + total = meta ? parseInt(meta.postcount) : parseInt(alm.posts_per_page); + + var totalposts = typeof meta !== 'undefined' ? meta.totalposts : alm.posts_per_page * 5; + alm.totalposts = alm.addons.preloaded === 'true' ? totalposts - alm.addons.preloaded_amount : totalposts; + alm.posts = alm.addons.paging ? total : alm.posts + total; + alm.debug = meta.debug ? meta.debug : ''; + + if (!meta) { + // Display warning if `meta` is missing. + console.warn('Ajax Load More: Unable to access `meta` object in Ajax response. There may be an issue in your Repeater Template or another hook causing interference.'); } // Set alm.html as plain text return alm.html = html; // If cache, get the length of the html object - total = is_cache ? (0, _almDomParser2.default)(html).length : total; + // total = is_cache ? almDomParser(html).length : total; // First Run Only if (alm.init) { @@ -3076,6 +3068,7 @@ var alm_is_filtering = false; window.almFiltersAddonComplete(el); } } + alm_is_filtering = false; // Tabs Complete @@ -3088,23 +3081,8 @@ var alm_is_filtering = false; } // ALM Done - if (!alm.addons.cache) { - // Not Cache & Single Post - if (alm.posts >= alm.totalposts && !alm.addons.single_post) { - alm.AjaxLoadMore.triggerDone(); - } - } else { - // Cache - if (alm.addons.nextpage && alm.localize) { - // Nextpage - if (parseInt(alm.localize.page) === parseInt(alm.localize.total_posts)) { - alm.AjaxLoadMore.triggerDone(); - } - } else { - if (total < parseInt(alm.posts_per_page)) { - alm.AjaxLoadMore.triggerDone(); - } - } + if (alm.posts >= alm.totalposts && !alm.addons.single_post) { + alm.AjaxLoadMore.triggerDone(); } // End ALM Done }); diff --git a/core/src/js/ajax-load-more.js b/core/src/js/ajax-load-more.js index 512f9ad..d74d702 100755 --- a/core/src/js/ajax-load-more.js +++ b/core/src/js/ajax-load-more.js @@ -840,7 +840,7 @@ let alm_is_filtering = false; // Standard Query if (queryType === 'standard') { - alm.AjaxLoadMore.success(data, false); + alm.AjaxLoadMore.success(data); } else if (queryType === 'totalpages' && alm.addons.paging && alm.addons.nextpage) { // Next Page and Paging if (typeof almBuildPagination === 'function') { @@ -902,7 +902,7 @@ let alm_is_filtering = false; totalposts: 1, }, }; - alm.AjaxLoadMore.success(obj, false); // Send data + alm.AjaxLoadMore.success(obj); // Send data // Callback to Tabs add-on if (typeof almTabLoaded === 'function') { @@ -969,7 +969,7 @@ let alm_is_filtering = false; totalposts: totalposts, }, }; - alm.AjaxLoadMore.success(obj, false); // Send data + alm.AjaxLoadMore.success(obj); // Send data }) .catch(function (error) { // Error @@ -989,14 +989,12 @@ let alm_is_filtering = false; /** * Success function after loading data. * - * @param {object} data The results of the Ajax request. - * @param {boolean} is_cache Are results of the Ajax request coming from cache? + * @param {object} data The results of the Ajax request. * @since 2.6.0 */ - alm.AjaxLoadMore.success = function (data, is_cache) { + alm.AjaxLoadMore.success = function (data) { if (alm.addons.single_post) { - // Get previous page data - alm.AjaxLoadMore.getSinglePost(); + alm.AjaxLoadMore.getSinglePost(); // Get previous post data } let isPaged = false; @@ -1011,35 +1009,30 @@ let alm_is_filtering = false; // Paging container let pagingContent = alm.listing.querySelector('.alm-paging-content'); - let html, meta, total; + let html, total; - if (is_cache) { - // If Cache, do not look for json data as we won't be querying the DB. - html = data; - } else { - // Standard ALM query results - html = data.html; - meta = data.meta; - total = meta ? parseInt(meta.postcount) : parseInt(alm.posts_per_page); - - let totalposts = typeof meta !== 'undefined' ? meta.totalposts : alm.posts_per_page * 5; - alm.totalposts = alm.addons.preloaded === 'true' ? totalposts - alm.addons.preloaded_amount : totalposts; - alm.posts = alm.addons.paging ? total : alm.posts + total; - alm.debug = meta.debug ? meta.debug : ''; - - if (!meta) { - // Display warning if `meta` is missing. - console.warn( - 'Ajax Load More: Unable to access `meta` object in Ajax response. There may be an issue in your Repeater Template or another hook causing interference.' - ); - } + html = data.html; + const meta = data.meta; + + total = meta ? parseInt(meta.postcount) : parseInt(alm.posts_per_page); + + let totalposts = typeof meta !== 'undefined' ? meta.totalposts : alm.posts_per_page * 5; + alm.totalposts = alm.addons.preloaded === 'true' ? totalposts - alm.addons.preloaded_amount : totalposts; + alm.posts = alm.addons.paging ? total : alm.posts + total; + alm.debug = meta.debug ? meta.debug : ''; + + if (!meta) { + // Display warning if `meta` is missing. + console.warn( + 'Ajax Load More: Unable to access `meta` object in Ajax response. There may be an issue in your Repeater Template or another hook causing interference.' + ); } // Set alm.html as plain text return alm.html = html; // If cache, get the length of the html object - total = is_cache ? almDomParser(html).length : total; + // total = is_cache ? almDomParser(html).length : total; // First Run Only if (alm.init) { @@ -1452,6 +1445,7 @@ let alm_is_filtering = false; window.almFiltersAddonComplete(el); } } + alm_is_filtering = false; // Tabs Complete @@ -1464,23 +1458,8 @@ let alm_is_filtering = false; } // ALM Done - if (!alm.addons.cache) { - // Not Cache & Single Post - if (alm.posts >= alm.totalposts && !alm.addons.single_post) { - alm.AjaxLoadMore.triggerDone(); - } - } else { - // Cache - if (alm.addons.nextpage && alm.localize) { - // Nextpage - if (parseInt(alm.localize.page) === parseInt(alm.localize.total_posts)) { - alm.AjaxLoadMore.triggerDone(); - } - } else { - if (total < parseInt(alm.posts_per_page)) { - alm.AjaxLoadMore.triggerDone(); - } - } + if (alm.posts >= alm.totalposts && !alm.addons.single_post) { + alm.AjaxLoadMore.triggerDone(); } // End ALM Done }); From 92d31c077ffafb6e691f979d893bb86b6a4a578f Mon Sep 17 00:00:00 2001 From: Darren Cooney Date: Fri, 5 May 2023 13:47:04 -0400 Subject: [PATCH 03/18] Updated cache compatibility --- ajax-load-more.php | 55 ++++++++++++++-------------- core/classes/class-alm-shortcode.php | 24 +++++++----- core/dist/js/ajax-load-more.js | 34 ++++++++++------- core/src/js/ajax-load-more.js | 35 +++++++++++------- 4 files changed, 82 insertions(+), 66 deletions(-) diff --git a/ajax-load-more.php b/ajax-load-more.php index 507c0df..c284010 100755 --- a/ajax-load-more.php +++ b/ajax-load-more.php @@ -15,28 +15,39 @@ */ /* -CACHE UPDATES: +ADD-ON Updates: +- FILTERS: + - Fix issue with decimal values in range slider. +- Next Page +- Cache +- Comments + +Extension Updates +- Terms +- ACF + STARTED: - Cache update. -TODO: +CACHE TODO: - Filters [DONE] - Paging [DONE] - SEO [DONE] -- Nextpage -- Comments -- ACF -- Terms +- Nextpage [DONE] +- Terms [DONE] +- ACF [DONE] +- Comments [DONE] - Single Posts +- Users [DONE] - Update cache admin screen. Expand/Collapse files. - Ensure backward compatibility. -CHANGES +Plugin CHANGES * NOTICE: Ajax Load More 6.0 is a major update and includes a number of breaking changes. Please review the documentation before updating. -* NOTICE: Cache add-on < 2.0 is no longer supported. Please update to the latest version of the Cache add-on. +* NOTICE: Cache add-on < 2.0 is no longer supported. Please update to the latest version of the Cache add-on to use Cache functionality. * UPDATE: Adding required functionality for the Cache 2.0 update. This introduces a new cache structure using MD5 hash for cache URLs. @@ -567,27 +578,17 @@ public function alm_query_posts() { */ $args['alm_query'] = $single_post ? 'single_posts' : 'alm'; - // MD5 hash of $args. - $md5_hash = md5( wp_json_encode( $args ) ); + // MD5 hash of query $args. + $md5_hash = $cache_id ? md5( wp_json_encode( $args ) ) : ''; /** * Cache Add-on. * Check for cached data before running WP_Query. */ - if ( $cache_id && has_filter( 'alm_cache_get_cache_file' ) && $query_type !== 'totalposts' ) { - $cache_data = apply_filters( 'alm_cache_get_cache_file', $cache_id, $md5_hash ); - if ( $cache_data && $cache_data['html'] ) { - wp_send_json( - [ - 'html' => $cache_data['html'], - 'meta' => [ - 'postcount' => $cache_data['count'], - 'totalposts' => $cache_data['total'], - 'type' => 'cache', - 'debug' => false, - ], - ] - ); + if ( $cache_id && method_exists( 'ALMCache', 'get_cache_file' ) && $query_type !== 'totalposts' ) { + $cache_data = ALMCache::get_cache_file( $cache_id, $md5_hash ); + if ( $cache_data ) { + wp_send_json( $cache_data ); } } @@ -684,12 +685,10 @@ public function alm_query_posts() { /** * Cache Add-on. * Create the cache file. - * - * @since 3.2.1 */ - if ( $cache_id && has_action( 'alm_cache_create_file' ) && $do_create_cache ) { + if ( $cache_id && method_exists( 'ALMCache', 'create_cache_file' ) && $do_create_cache ) { $cache_name = $single_post ? $single_post_id : $md5_hash; - apply_filters( 'alm_cache_create_file', $cache_id, $cache_name, $canonical_url, $data, $alm_current, $alm_found_posts ); + ALMCache::create_cache_file( $cache_id, $cache_name, $canonical_url, $data, $alm_current, $alm_found_posts ); } $return = [ diff --git a/core/classes/class-alm-shortcode.php b/core/classes/class-alm-shortcode.php index 3f54512..db7947a 100755 --- a/core/classes/class-alm-shortcode.php +++ b/core/classes/class-alm-shortcode.php @@ -32,9 +32,16 @@ class ALM_SHORTCODE { * @since 2.10.1 */ public static function alm_render_shortcode( $atts ) { - global $post; // Global $post obj. - $options = get_option( 'alm_settings' ); // Get ALM options. + + // Initial variables. + self::$counter++; // ALM counter. + $slug = apply_filters( 'alm_page_slug', alm_get_page_slug( $post ) ); // Define page slug. + $post_id = apply_filters( 'alm_page_id', alm_get_page_id( $post ) ); // Define post ID. + $wp_posts_per_page = get_option( 'posts_per_page' ); // Global Posts Per Page. + + // Get ALM options. + $options = get_option( 'alm_settings' ); /** * Override default ALM Settings. @@ -42,12 +49,9 @@ public static function alm_render_shortcode( $atts ) { * * @return array $options Options array. */ - $options = has_filter( 'alm_settings' ) ? apply_filters( 'alm_settings', $options ) : $options; - - self::$counter++; // Counter. - $slug = apply_filters( 'alm_page_slug', alm_get_page_slug( $post ) ); // Define page slug. - $post_id = apply_filters( 'alm_page_id', alm_get_page_id( $post ) ); // Define post ID. - $wp_posts_per_page = get_option( 'posts_per_page' ); // Global Posts Per Page. + $options = has_filter( 'alm_settings' ) ? apply_filters( 'alm_settings', $options ) : $options; + $options['post_id'] = $post_id; // Add post ID to options array. + $options['slug'] = $slug; // Add post slug to options array. // Custom CSS for Layouts - Only run this once. if ( has_action( 'alm_layouts_custom_css' ) ) { @@ -851,8 +855,8 @@ public static function alm_render_shortcode( $atts ) { // Cache Add-on. $alm_auto_cache = isset( $_GET['alm_auto_cache'] ) ? true : false; if ( has_action( 'alm_cache_installed' ) && $cache === 'true' ) { - // Confirm cache version is 1.0.0 or greater. - $cache_version_check = defined( 'ALM_CACHE_VERSION' ) && version_compare( ALM_CACHE_VERSION, '2.0.0', '>=' ); + // Confirm cache version is 2.0 or greater. + $cache_version_check = defined( 'ALM_CACHE_VERSION' ) && version_compare( ALM_CACHE_VERSION, '2.0', '>=' ); if ( $cache_version_check ) { $cache_return = apply_filters( 'alm_cache_shortcode', diff --git a/core/dist/js/ajax-load-more.js b/core/dist/js/ajax-load-more.js index e2b3f68..a5098e7 100644 --- a/core/dist/js/ajax-load-more.js +++ b/core/dist/js/ajax-load-more.js @@ -1659,7 +1659,7 @@ var alm_is_filtering = false; alm.integration = {}; alm.window = window; alm.page = 0; - alm.posts = 0; + alm.postcount = 0; alm.totalposts = 0; alm.proceed = false; alm.disable_ajax = false; @@ -1789,7 +1789,7 @@ var alm_is_filtering = false; alm.addons.nextpage_scroll = alm.listing.dataset.nextpageScroll; alm.addons.nextpage_pageviews = alm.listing.dataset.nextpagePageviews; alm.addons.nextpage_post_id = alm.listing.dataset.nextpagePostId; - alm.addons.nextpage_startpage = alm.listing.dataset.nextpageStartpage; + alm.addons.nextpage_startpage = parseInt(alm.listing.dataset.nextpageStartpage); alm.addons.nextpage_title_template = alm.listing.dataset.nextpageTitleTemplate; } @@ -2585,18 +2585,14 @@ var alm_is_filtering = false; // Paging container var pagingContent = alm.listing.querySelector('.alm-paging-content'); - var html = void 0, - total = void 0; - - html = data.html; + var html = data.html; + var total = meta ? parseInt(meta.postcount) : parseInt(alm.posts_per_page); var meta = data.meta; - total = meta ? parseInt(meta.postcount) : parseInt(alm.posts_per_page); - + // Get current post counts. var totalposts = typeof meta !== 'undefined' ? meta.totalposts : alm.posts_per_page * 5; alm.totalposts = alm.addons.preloaded === 'true' ? totalposts - alm.addons.preloaded_amount : totalposts; - alm.posts = alm.addons.paging ? total : alm.posts + total; - alm.debug = meta.debug ? meta.debug : ''; + alm.postcount = alm.addons.paging ? total : alm.postcount + total; if (!meta) { // Display warning if `meta` is missing. @@ -3080,11 +3076,21 @@ var alm_is_filtering = false; } } - // ALM Done - if (alm.posts >= alm.totalposts && !alm.addons.single_post) { - alm.AjaxLoadMore.triggerDone(); + /** + * ALM Done. + */ + if (!alm.addons.single_post) { + if (alm.addons.nextpage) { + // Nextpage. + if (alm.postcount + alm.addons.nextpage_startpage >= alm.totalposts) { + alm.AjaxLoadMore.triggerDone(); + } + } else { + if (alm.postcount >= alm.totalposts) { + alm.AjaxLoadMore.triggerDone(); + } + } } - // End ALM Done }); // End ALM Loaded diff --git a/core/src/js/ajax-load-more.js b/core/src/js/ajax-load-more.js index d74d702..6c67350 100755 --- a/core/src/js/ajax-load-more.js +++ b/core/src/js/ajax-load-more.js @@ -80,7 +80,7 @@ let alm_is_filtering = false; alm.integration = {}; alm.window = window; alm.page = 0; - alm.posts = 0; + alm.postcount = 0; alm.totalposts = 0; alm.proceed = false; alm.disable_ajax = false; @@ -210,7 +210,7 @@ let alm_is_filtering = false; alm.addons.nextpage_scroll = alm.listing.dataset.nextpageScroll; alm.addons.nextpage_pageviews = alm.listing.dataset.nextpagePageviews; alm.addons.nextpage_post_id = alm.listing.dataset.nextpagePostId; - alm.addons.nextpage_startpage = alm.listing.dataset.nextpageStartpage; + alm.addons.nextpage_startpage = parseInt(alm.listing.dataset.nextpageStartpage); alm.addons.nextpage_title_template = alm.listing.dataset.nextpageTitleTemplate; } @@ -1009,17 +1009,14 @@ let alm_is_filtering = false; // Paging container let pagingContent = alm.listing.querySelector('.alm-paging-content'); - let html, total; - - html = data.html; + let html = data.html; + let total = meta ? parseInt(meta.postcount) : parseInt(alm.posts_per_page); const meta = data.meta; - total = meta ? parseInt(meta.postcount) : parseInt(alm.posts_per_page); - - let totalposts = typeof meta !== 'undefined' ? meta.totalposts : alm.posts_per_page * 5; + // Get current post counts. + const totalposts = typeof meta !== 'undefined' ? meta.totalposts : alm.posts_per_page * 5; alm.totalposts = alm.addons.preloaded === 'true' ? totalposts - alm.addons.preloaded_amount : totalposts; - alm.posts = alm.addons.paging ? total : alm.posts + total; - alm.debug = meta.debug ? meta.debug : ''; + alm.postcount = alm.addons.paging ? total : alm.postcount + total; if (!meta) { // Display warning if `meta` is missing. @@ -1457,11 +1454,21 @@ let alm_is_filtering = false; } } - // ALM Done - if (alm.posts >= alm.totalposts && !alm.addons.single_post) { - alm.AjaxLoadMore.triggerDone(); + /** + * ALM Done. + */ + if (!alm.addons.single_post) { + if (alm.addons.nextpage) { + // Nextpage. + if (alm.postcount + alm.addons.nextpage_startpage >= alm.totalposts) { + alm.AjaxLoadMore.triggerDone(); + } + } else { + if (alm.postcount >= alm.totalposts) { + alm.AjaxLoadMore.triggerDone(); + } + } } - // End ALM Done }); // End ALM Loaded From 72bbe4bf2a0ac15185f6cfd2795e6d7579281ba8 Mon Sep 17 00:00:00 2001 From: Darren Cooney Date: Sun, 7 May 2023 08:36:42 -0400 Subject: [PATCH 04/18] Updated to pass MD5 hash for cache pagenames --- ajax-load-more.php | 20 +- core/dist/js/ajax-load-more.js | 1861 +++++++++++++++++++--------- core/src/js/addons/cache.js | 99 +- core/src/js/ajax-load-more.js | 57 +- core/src/js/helpers/getCacheUrl.js | 79 -- core/src/js/helpers/queryParams.js | 56 +- package.json | 6 +- 7 files changed, 1427 insertions(+), 751 deletions(-) delete mode 100755 core/src/js/helpers/getCacheUrl.js diff --git a/ajax-load-more.php b/ajax-load-more.php index c284010..a6e8ce2 100755 --- a/ajax-load-more.php +++ b/ajax-load-more.php @@ -15,6 +15,10 @@ */ /* +IN Progress: +- Started creating the cache slug in the JavaScript and passing it to the PHP using CryptoJS. + + ADD-ON Updates: - FILTERS: - Fix issue with decimal values in range slider. @@ -25,6 +29,7 @@ Extension Updates - Terms - ACF +- USERS STARTED: - Cache update. @@ -38,12 +43,16 @@ - ACF [DONE] - Comments [DONE] - Single Posts + - Soltion for target loading cache. Working with Repeater Template. - Users [DONE] - Update cache admin screen. Expand/Collapse files. - Ensure backward compatibility. +Issues: +- ACF not working with Paging - https://wpdev.local/acf-repeater-field/ + Plugin CHANGES * NOTICE: Ajax Load More 6.0 is a major update and includes a number of breaking changes. Please review the documentation before updating. @@ -470,7 +479,8 @@ public function alm_query_posts() { $filters_startpage = isset( $params['filters_startpage'] ) && $is_filters ? $params['filters_startpage'] : 0; // Cache. - $cache_id = isset( $params['cache_id'] ) && ! empty( $params['cache_id'] ) ? $params['cache_id'] : false; + $cache_id = isset( $params['cache_id'] ) && $params['cache_id'] ? $params['cache_id'] : false; + $cache_slug = isset( $params['cache_slug'] ) && $params['cache_slug'] ? $params['cache_slug'] : ''; $cache_logged_in = isset( $params['cache_logged_in'] ) ? $params['cache_logged_in'] : false; $do_create_cache = $cache_logged_in === 'true' && is_user_logged_in() ? false : true; @@ -578,15 +588,12 @@ public function alm_query_posts() { */ $args['alm_query'] = $single_post ? 'single_posts' : 'alm'; - // MD5 hash of query $args. - $md5_hash = $cache_id ? md5( wp_json_encode( $args ) ) : ''; - /** * Cache Add-on. * Check for cached data before running WP_Query. */ if ( $cache_id && method_exists( 'ALMCache', 'get_cache_file' ) && $query_type !== 'totalposts' ) { - $cache_data = ALMCache::get_cache_file( $cache_id, $md5_hash ); + $cache_data = ALMCache::get_cache_file( $cache_id, $cache_slug ); if ( $cache_data ) { wp_send_json( $cache_data ); } @@ -687,8 +694,7 @@ public function alm_query_posts() { * Create the cache file. */ if ( $cache_id && method_exists( 'ALMCache', 'create_cache_file' ) && $do_create_cache ) { - $cache_name = $single_post ? $single_post_id : $md5_hash; - ALMCache::create_cache_file( $cache_id, $cache_name, $canonical_url, $data, $alm_current, $alm_found_posts ); + ALMCache::create_cache_file( $cache_id, $cache_slug, $canonical_url, $data, $alm_current, $alm_found_posts ); } $return = [ diff --git a/core/dist/js/ajax-load-more.js b/core/dist/js/ajax-load-more.js index a5098e7..f8b95ee 100644 --- a/core/dist/js/ajax-load-more.js +++ b/core/dist/js/ajax-load-more.js @@ -100,17 +100,40 @@ var ajaxloadmore = Object.defineProperty(exports, "__esModule", { value: true }); +exports.getCacheSlug = getCacheSlug; exports.createCacheFile = createCacheFile; exports.wooCache = wooCache; +exports.getCacheUrl = getCacheUrl; var _axios = __webpack_require__(/*! axios */ "./node_modules/axios/index.js"); var _axios2 = _interopRequireDefault(_axios); +var _filters = __webpack_require__(/*! ../addons/filters */ "./core/src/js/addons/filters.js"); + +var _md = __webpack_require__(/*! crypto-js/md5 */ "./node_modules/crypto-js/md5.js"); + +var _md2 = _interopRequireDefault(_md); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +/** + * Create unique cache slug from query params. + * + * @param {object} alm The ALM object. + * @param {object} data The data object. + * @return {object} Modified data object. + */ +function getCacheSlug(alm, data) { + if (alm.addons.nextpage) { + return 'page-' + (alm.page + alm.addons.nextpage_startpage); + } else { + return (0, _md2.default)(JSON.stringify(data)).toString(); + } +} + /** * Create a single post cache file. * @@ -136,7 +159,7 @@ function createCacheFile(alm, content) { formData.append('name', name); formData.append('html', content.trim()); - _axios2.default.post(alm_localize.ajaxurl, formData).then(function (response) { + _axios2.default.post(alm_localize.ajaxurl, formData).then(function () { console.log('Cache created for: ' + alm.canonical_url); }); } @@ -144,8 +167,8 @@ function createCacheFile(alm, content) { /** * Create a WooCommerce cache file. * - * @param {Object} alm - * @param {String} content + * @param {object} alm The ALM object. + * @param {string} content The content to cache. * @since 5.3.1 */ function wooCache(alm, content) { @@ -167,6 +190,82 @@ function wooCache(alm, content) { }); } +/** + * Generate the cache page URL for GET request + * + * @param {object} alm The ALM object. + * @since 5.0 + * @supports Standard, SEO, Filters, Nextpage, Single Posts + */ +function getCacheUrl(alm) { + if (!alm) { + return false; + } + + var firstpage = '1'; + var cache_url = ''; + var ext = '.html'; + var path = alm.addons.cache_path + alm.addons.cache_id; + + // SEO Add-on + if (alm.init && alm.addons.seo && alm.isPaged) { + // If request is a paged URL (e.g. /page/3/) + cache_url = path + '/page-' + firstpage + '-' + alm.start_page + ext; + } + + // Filters + else if (alm.addons.filters) { + var filtersPath = (0, _filters.parseQuerystring)(path); + + if (alm.init && alm.isPaged) { + // First run & Paged + cache_url = filtersPath + '/page-' + firstpage + '-' + alm.addons.filters_startpage + ext; + } else { + var page = alm.page + 1; + + if (alm.addons.preloaded === 'true') { + // Preloaded + Filters + page = alm.page + 2; + } + cache_url = filtersPath + '/page-' + page + ext; + } + } + + // Nextpage + else if (alm.addons.nextpage) { + var nextpage_cache_url = void 0; + if (alm.addons.paging) { + nextpage_cache_url = parseInt(alm.page) + 1; + } else { + nextpage_cache_url = parseInt(alm.page) + 2; + if (alm.isPaged) { + // If the request a paged URL (/page/3/) + nextpage_cache_url = parseInt(alm.page) + parseInt(alm.addons.nextpage_startpage) + 1; + } + } + + cache_url = path + '/page-' + nextpage_cache_url + ext; + } + + // Single Post + else if (alm.addons.single_post) { + cache_url = path + '/' + alm.addons.single_post_id + ext; + } + + // Comments & Preloaded + else if (alm.addons.comments === 'true' && alm.addons.preloaded === 'true') { + // When using comments we need to increase the current page by 2 + cache_url = path + '/page-' + (alm.page + 2) + ext; + } + + // Standard URL request + else { + cache_url = path + '/page-' + (alm.page + 1) + ext; + } + + return cache_url; +} + /***/ }), /***/ "./core/src/js/addons/elementor.js": @@ -1450,14 +1549,6 @@ Object.defineProperty(exports, "__esModule", { }); exports.click = exports.render = exports.getOffset = exports.almScroll = exports.start = exports.tab = exports.tracking = exports.getTotalRemaining = exports.getTotalPosts = exports.getPostCount = exports.reset = exports.filter = undefined; -var _axios = __webpack_require__(/*! axios */ "./node_modules/axios/index.js"); - -var _axios2 = _interopRequireDefault(_axios); - -var _smoothscrollPolyfill = __webpack_require__(/*! smoothscroll-polyfill */ "./node_modules/smoothscroll-polyfill/dist/smoothscroll.js"); - -var _smoothscrollPolyfill2 = _interopRequireDefault(_smoothscrollPolyfill); - __webpack_require__(/*! ./helpers/helpers */ "./core/src/js/helpers/helpers.js"); var _cache = __webpack_require__(/*! ./addons/cache */ "./core/src/js/addons/cache.js"); @@ -1480,10 +1571,6 @@ var _almDomParser = __webpack_require__(/*! ./helpers/almDomParser */ "./core/sr var _almDomParser2 = _interopRequireDefault(_almDomParser); -var _getCacheUrl = __webpack_require__(/*! ./helpers/getCacheUrl */ "./core/src/js/helpers/getCacheUrl.js"); - -var _getCacheUrl2 = _interopRequireDefault(_getCacheUrl); - var _getParameterByName = __webpack_require__(/*! ./helpers/getParameterByName */ "./core/src/js/helpers/getParameterByName.js"); var _getParameterByName2 = _interopRequireDefault(_getParameterByName); @@ -1558,6 +1645,10 @@ var _getTotals = __webpack_require__(/*! ./helpers/getTotals */ "./core/src/js/h var _getTotals2 = _interopRequireDefault(_getTotals); +var _axios = __webpack_require__(/*! axios */ "./node_modules/axios/index.js"); + +var _axios2 = _interopRequireDefault(_axios); + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; @@ -1604,32 +1695,20 @@ function _asyncToGenerator(fn) { }return step("next"); }); }; -} +} // ALM Modules -/** - * Ajax Load More - * https://connekthq.com/plugins/ajax-load-more/ - * Author: Darren Cooney - * Twitter: @KaptonKaos, @ajaxloadmore, @connekthq - * Copyright Connekt Media - https://connekthq.com - */ +//import commentReplyFix from './helpers/commentReplyFix'; -// Polyfills -__webpack_require__(/*! @babel/polyfill/noConflict */ "./node_modules/@babel/polyfill/noConflict.js"); -__webpack_require__(/*! focus-options-polyfill */ "./node_modules/focus-options-polyfill/index.js"); -__webpack_require__(/*! ./helpers/polyfills.js */ "./core/src/js/helpers/polyfills.js"); // External Modules var qs = __webpack_require__(/*! qs */ "./node_modules/qs/lib/index.js"); var imagesLoaded = __webpack_require__(/*! imagesloaded */ "./node_modules/imagesloaded/imagesloaded.js"); -// Smooth scrolling polyfill _axios2.default.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; -_smoothscrollPolyfill2.default.polyfill(); - -// ALM Modules - -//import commentReplyFix from './helpers/commentReplyFix'; +// Polyfills +__webpack_require__(/*! @babel/polyfill/noConflict */ "./node_modules/@babel/polyfill/noConflict.js"); +__webpack_require__(/*! focus-options-polyfill */ "./node_modules/focus-options-polyfill/index.js"); +__webpack_require__(/*! ./helpers/polyfills.js */ "./core/src/js/helpers/polyfills.js"); // Global filtering state. var alm_is_filtering = false; @@ -1770,8 +1849,7 @@ var alm_is_filtering = false; if (alm.addons.cache === 'true') { alm.addons.cache_id = alm.listing.dataset.cacheId; alm.addons.cache_path = alm.listing.dataset.cachePath; - alm.addons.cache_logged_in = alm.listing.dataset.cacheLoggedIn; - alm.addons.cache_logged_in = alm.addons.cache_logged_in === undefined ? false : alm.addons.cache_logged_in; + alm.addons.cache_logged_in = alm.listing.dataset.cacheLoggedIn ? alm.listing.dataset.cacheLoggedIn : false; } // CTA add-on @@ -2196,15 +2274,14 @@ var alm_is_filtering = false; * @since 2.0.0 */ alm.AjaxLoadMore.loadPosts = function () { - if (typeof almOnChange === 'function') { - window.almOnChange(alm); - } - - // Check for ajax blocker. if (alm.disable_ajax) { return; } + if (typeof almOnChange === 'function') { + window.almOnChange(alm); + } + alm.loading = true; (0, _placeholder.showPlaceholder)(alm); @@ -2337,7 +2414,7 @@ var alm_is_filtering = false; // Dispatch Ajax request. if (alm.extensions.restapi) { // REST API - alm.AjaxLoadMore.restapi(alm, action, queryType); + alm.AjaxLoadMore.restapi(alm); } else if (alm.addons.tabs) { // Tabs alm.AjaxLoadMore.tabs(alm); @@ -2368,11 +2445,11 @@ var alm_is_filtering = false; return config; }); - // Get Ajax URL + // Get Ajax URL. var ajaxURL = alm_localize.ajaxurl; - // Get data params - var params = queryParams.almGetAjaxParams(alm, action, queryType); // [./helpers/queryParams.js + // Get query params. + var params = queryParams.getAjaxParams(alm, action, queryType); // Single Posts Add-on // If has `single_post_target`, adjust the Ajax URL to the post URL. @@ -2496,10 +2573,10 @@ var alm_is_filtering = false; * @param {string} queryType The type of Ajax request (standard/totalposts). * @since 5.0.0 */ - alm.AjaxLoadMore.restapi = function (alm, action, queryType) { + alm.AjaxLoadMore.restapi = function (alm) { var alm_rest_template = wp.template(alm.extensions.restapi_template_id); var alm_rest_url = alm.extensions.restapi_base_url + '/' + alm.extensions.restapi_namespace + '/' + alm.extensions.restapi_endpoint; - var params = queryParams.almGetRestParams(alm); // [./helpers/queryParams.js] + var params = queryParams.getRestAPIParams(alm); // [./helpers/queryParams.js] // Axios Interceptor for nested data objects _axios2.default.interceptors.request.use(function (config) { @@ -4545,102 +4622,6 @@ function setButtonAtts(button, page, url) { /***/ }), -/***/ "./core/src/js/helpers/getCacheUrl.js": -/*!********************************************!*\ - !*** ./core/src/js/helpers/getCacheUrl.js ***! - \********************************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _filters = __webpack_require__(/*! ../addons/filters */ "./core/src/js/addons/filters.js"); - -/** - * Generate the cache page URL for GET request - * - * @param {*} alm - * @since 5.0 - * @supports Standard, SEO, Filters, Nextpage, Single Posts - */ -var getCacheUrl = function getCacheUrl(alm) { - if (!alm) { - return false; - } - - var firstpage = '1'; - var cache_url = ''; - var ext = '.html'; - var path = alm.addons.cache_path + alm.addons.cache_id; - - // SEO Add-on - if (alm.init && alm.addons.seo && alm.isPaged) { - // If request is a paged URL (e.g. /page/3/) - cache_url = path + '/page-' + firstpage + '-' + alm.start_page + ext; - } - - // Filters - else if (alm.addons.filters) { - var filtersPath = (0, _filters.parseQuerystring)(path); - - if (alm.init && alm.isPaged) { - // First run & Paged - cache_url = filtersPath + '/page-' + firstpage + '-' + alm.addons.filters_startpage + ext; - } else { - var page = alm.page + 1; - - if (alm.addons.preloaded === 'true') { - // Preloaded + Filters - page = alm.page + 2; - } - cache_url = filtersPath + '/page-' + page + ext; - } - } - - // Nextpage - else if (alm.addons.nextpage) { - var nextpage_cache_url = void 0; - if (alm.addons.paging) { - nextpage_cache_url = parseInt(alm.page) + 1; - } else { - nextpage_cache_url = parseInt(alm.page) + 2; - if (alm.isPaged) { - // If the request a paged URL (/page/3/) - nextpage_cache_url = parseInt(alm.page) + parseInt(alm.addons.nextpage_startpage) + 1; - } - } - - cache_url = path + '/page-' + nextpage_cache_url + ext; - } - - // Single Post - else if (alm.addons.single_post) { - cache_url = path + '/' + alm.addons.single_post_id + ext; - } - - // Comments & Preloaded - else if (alm.addons.comments === 'true' && alm.addons.preloaded === 'true') { - // When using comments we need to increase the current page by 2 - cache_url = path + '/page-' + (alm.page + 2) + ext; - } - - // Standard URL request - else { - cache_url = path + '/page-' + (alm.page + 1) + ext; - } - - return cache_url; -}; - -exports.default = getCacheUrl; - -/***/ }), - /***/ "./core/src/js/helpers/getParameterByName.js": /*!***************************************************!*\ !*** ./core/src/js/helpers/getParameterByName.js ***! @@ -5205,28 +5186,32 @@ if (!document.documentElement.dataset && ( Object.defineProperty(exports, "__esModule", { value: true }); -exports.almGetAjaxParams = almGetAjaxParams; -exports.almGetRestParams = almGetRestParams; +exports.getAjaxParams = getAjaxParams; +exports.getRestAPIParams = getRestAPIParams; + +var _cache = __webpack_require__(/*! ../addons/cache */ "./core/src/js/addons/cache.js"); + /** - * almGetAjaxParams - * Build the data object to send with the Ajax request + * Build the data object to send with the Ajax request. * - * @param alm object - * @param action string - * @param queryType string + * @param {object} alm The ALM object. + * @param {string} action The HTTP action. + * @param {string} queryType The query type. + * @return {object} The data object. * @since 3.6 */ - -function almGetAjaxParams(alm, action, queryType) { +function getAjaxParams(alm, action, queryType) { // Defaults var data = { + action: action, + query_type: queryType, id: alm.id, - post_id: alm.post_id, + post_id: parseInt(alm.post_id), slug: alm.slug, canonical_url: encodeURIComponent(alm.canonical_url), - posts_per_page: alm.posts_per_page, - page: alm.page, - offset: alm.offset, + posts_per_page: parseInt(alm.posts_per_page), + page: parseInt(alm.page), + offset: parseInt(alm.offset), post_type: alm.post_type, repeater: alm.repeater, seo_start_page: alm.start_page @@ -5245,13 +5230,9 @@ function almGetAjaxParams(alm, action, queryType) { if (alm.addons.paging) { data.paging = alm.addons.paging; } - if (alm.addons.preloaded) { + if (alm.addons.preloaded === 'true') { data.preloaded = alm.addons.preloaded; - data.preloaded_amount = alm.addons.preloaded_amount; - } - if (alm.addons.cache === 'true') { - data.cache_id = alm.addons.cache_id; - data.cache_logged_in = alm.addons.cache_logged_in; + data.preloaded_amount = parseInt(alm.addons.preloaded_amount); } if (alm.acf_array) { data.acf = alm.acf_array; @@ -5376,23 +5357,27 @@ function almGetAjaxParams(alm, action, queryType) { data.vars = escape(alm.listing.dataset.vars); } - data.action = action; - data.query_type = queryType; + // Set Cache params. + if (alm.addons.cache === 'true') { + data.cache_id = alm.addons.cache_id; + data.cache_logged_in = alm.addons.cache_logged_in; + data.cache_slug = (0, _cache.getCacheSlug)(alm, data); + } return data; } /** - * almGetRestParams - * Build the REST API data object to send with REST API request + * Build the REST API data object to send with REST API request. * - * @param alm object + * @param {object} alm The ALM object. + * @return {object} The data object. * @since 3.6 */ -function almGetRestParams(alm) { +function getRestAPIParams(alm) { var data = { id: alm.id, - post_id: alm.post_id, + post_id: parseInt(alm.post_id), posts_per_page: alm.posts_per_page, page: alm.page, offset: alm.offset, @@ -5431,7 +5416,6 @@ function almGetRestParams(alm) { preloaded_amount: alm.addons.preloaded_amount, seo_start_page: alm.start_page }; - return data; } @@ -18522,6 +18506,1088 @@ __webpack_require__(/*! ../modules/web.dom.iterable */ "./node_modules/core-js/m module.exports = __webpack_require__(/*! ../modules/_core */ "./node_modules/core-js/modules/_core.js"); +/***/ }), + +/***/ "./node_modules/crypto-js/core.js": +/*!****************************************!*\ + !*** ./node_modules/crypto-js/core.js ***! + \****************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +/* WEBPACK VAR INJECTION */(function(global) {;(function (root, factory) { + if (true) { + // CommonJS + module.exports = exports = factory(); + } + else {} +}(this, function () { + + /*globals window, global, require*/ + + /** + * CryptoJS core components. + */ + var CryptoJS = CryptoJS || (function (Math, undefined) { + + var crypto; + + // Native crypto from window (Browser) + if (typeof window !== 'undefined' && window.crypto) { + crypto = window.crypto; + } + + // Native crypto in web worker (Browser) + if (typeof self !== 'undefined' && self.crypto) { + crypto = self.crypto; + } + + // Native crypto from worker + if (typeof globalThis !== 'undefined' && globalThis.crypto) { + crypto = globalThis.crypto; + } + + // Native (experimental IE 11) crypto from window (Browser) + if (!crypto && typeof window !== 'undefined' && window.msCrypto) { + crypto = window.msCrypto; + } + + // Native crypto from global (NodeJS) + if (!crypto && typeof global !== 'undefined' && global.crypto) { + crypto = global.crypto; + } + + // Native crypto import via require (NodeJS) + if (!crypto && "function" === 'function') { + try { + crypto = __webpack_require__(/*! crypto */ 0); + } catch (err) {} + } + + /* + * Cryptographically secure pseudorandom number generator + * + * As Math.random() is cryptographically not safe to use + */ + var cryptoSecureRandomInt = function () { + if (crypto) { + // Use getRandomValues method (Browser) + if (typeof crypto.getRandomValues === 'function') { + try { + return crypto.getRandomValues(new Uint32Array(1))[0]; + } catch (err) {} + } + + // Use randomBytes method (NodeJS) + if (typeof crypto.randomBytes === 'function') { + try { + return crypto.randomBytes(4).readInt32LE(); + } catch (err) {} + } + } + + throw new Error('Native crypto module could not be used to get secure random number.'); + }; + + /* + * Local polyfill of Object.create + + */ + var create = Object.create || (function () { + function F() {} + + return function (obj) { + var subtype; + + F.prototype = obj; + + subtype = new F(); + + F.prototype = null; + + return subtype; + }; + }()); + + /** + * CryptoJS namespace. + */ + var C = {}; + + /** + * Library namespace. + */ + var C_lib = C.lib = {}; + + /** + * Base object for prototypal inheritance. + */ + var Base = C_lib.Base = (function () { + + + return { + /** + * Creates a new object that inherits from this object. + * + * @param {Object} overrides Properties to copy into the new object. + * + * @return {Object} The new object. + * + * @static + * + * @example + * + * var MyType = CryptoJS.lib.Base.extend({ + * field: 'value', + * + * method: function () { + * } + * }); + */ + extend: function (overrides) { + // Spawn + var subtype = create(this); + + // Augment + if (overrides) { + subtype.mixIn(overrides); + } + + // Create default initializer + if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { + subtype.init = function () { + subtype.$super.init.apply(this, arguments); + }; + } + + // Initializer's prototype is the subtype object + subtype.init.prototype = subtype; + + // Reference supertype + subtype.$super = this; + + return subtype; + }, + + /** + * Extends this object and runs the init method. + * Arguments to create() will be passed to init(). + * + * @return {Object} The new object. + * + * @static + * + * @example + * + * var instance = MyType.create(); + */ + create: function () { + var instance = this.extend(); + instance.init.apply(instance, arguments); + + return instance; + }, + + /** + * Initializes a newly created object. + * Override this method to add some logic when your objects are created. + * + * @example + * + * var MyType = CryptoJS.lib.Base.extend({ + * init: function () { + * // ... + * } + * }); + */ + init: function () { + }, + + /** + * Copies properties into this object. + * + * @param {Object} properties The properties to mix in. + * + * @example + * + * MyType.mixIn({ + * field: 'value' + * }); + */ + mixIn: function (properties) { + for (var propertyName in properties) { + if (properties.hasOwnProperty(propertyName)) { + this[propertyName] = properties[propertyName]; + } + } + + // IE won't copy toString using the loop above + if (properties.hasOwnProperty('toString')) { + this.toString = properties.toString; + } + }, + + /** + * Creates a copy of this object. + * + * @return {Object} The clone. + * + * @example + * + * var clone = instance.clone(); + */ + clone: function () { + return this.init.prototype.extend(this); + } + }; + }()); + + /** + * An array of 32-bit words. + * + * @property {Array} words The array of 32-bit words. + * @property {number} sigBytes The number of significant bytes in this word array. + */ + var WordArray = C_lib.WordArray = Base.extend({ + /** + * Initializes a newly created word array. + * + * @param {Array} words (Optional) An array of 32-bit words. + * @param {number} sigBytes (Optional) The number of significant bytes in the words. + * + * @example + * + * var wordArray = CryptoJS.lib.WordArray.create(); + * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); + * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); + */ + init: function (words, sigBytes) { + words = this.words = words || []; + + if (sigBytes != undefined) { + this.sigBytes = sigBytes; + } else { + this.sigBytes = words.length * 4; + } + }, + + /** + * Converts this word array to a string. + * + * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex + * + * @return {string} The stringified word array. + * + * @example + * + * var string = wordArray + ''; + * var string = wordArray.toString(); + * var string = wordArray.toString(CryptoJS.enc.Utf8); + */ + toString: function (encoder) { + return (encoder || Hex).stringify(this); + }, + + /** + * Concatenates a word array to this word array. + * + * @param {WordArray} wordArray The word array to append. + * + * @return {WordArray} This word array. + * + * @example + * + * wordArray1.concat(wordArray2); + */ + concat: function (wordArray) { + // Shortcuts + var thisWords = this.words; + var thatWords = wordArray.words; + var thisSigBytes = this.sigBytes; + var thatSigBytes = wordArray.sigBytes; + + // Clamp excess bits + this.clamp(); + + // Concat + if (thisSigBytes % 4) { + // Copy one byte at a time + for (var i = 0; i < thatSigBytes; i++) { + var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); + } + } else { + // Copy one word at a time + for (var j = 0; j < thatSigBytes; j += 4) { + thisWords[(thisSigBytes + j) >>> 2] = thatWords[j >>> 2]; + } + } + this.sigBytes += thatSigBytes; + + // Chainable + return this; + }, + + /** + * Removes insignificant bits. + * + * @example + * + * wordArray.clamp(); + */ + clamp: function () { + // Shortcuts + var words = this.words; + var sigBytes = this.sigBytes; + + // Clamp + words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); + words.length = Math.ceil(sigBytes / 4); + }, + + /** + * Creates a copy of this word array. + * + * @return {WordArray} The clone. + * + * @example + * + * var clone = wordArray.clone(); + */ + clone: function () { + var clone = Base.clone.call(this); + clone.words = this.words.slice(0); + + return clone; + }, + + /** + * Creates a word array filled with random bytes. + * + * @param {number} nBytes The number of random bytes to generate. + * + * @return {WordArray} The random word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.lib.WordArray.random(16); + */ + random: function (nBytes) { + var words = []; + + for (var i = 0; i < nBytes; i += 4) { + words.push(cryptoSecureRandomInt()); + } + + return new WordArray.init(words, nBytes); + } + }); + + /** + * Encoder namespace. + */ + var C_enc = C.enc = {}; + + /** + * Hex encoding strategy. + */ + var Hex = C_enc.Hex = { + /** + * Converts a word array to a hex string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The hex string. + * + * @static + * + * @example + * + * var hexString = CryptoJS.enc.Hex.stringify(wordArray); + */ + stringify: function (wordArray) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + + // Convert + var hexChars = []; + for (var i = 0; i < sigBytes; i++) { + var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + hexChars.push((bite >>> 4).toString(16)); + hexChars.push((bite & 0x0f).toString(16)); + } + + return hexChars.join(''); + }, + + /** + * Converts a hex string to a word array. + * + * @param {string} hexStr The hex string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Hex.parse(hexString); + */ + parse: function (hexStr) { + // Shortcut + var hexStrLength = hexStr.length; + + // Convert + var words = []; + for (var i = 0; i < hexStrLength; i += 2) { + words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); + } + + return new WordArray.init(words, hexStrLength / 2); + } + }; + + /** + * Latin1 encoding strategy. + */ + var Latin1 = C_enc.Latin1 = { + /** + * Converts a word array to a Latin1 string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The Latin1 string. + * + * @static + * + * @example + * + * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); + */ + stringify: function (wordArray) { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + + // Convert + var latin1Chars = []; + for (var i = 0; i < sigBytes; i++) { + var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + latin1Chars.push(String.fromCharCode(bite)); + } + + return latin1Chars.join(''); + }, + + /** + * Converts a Latin1 string to a word array. + * + * @param {string} latin1Str The Latin1 string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); + */ + parse: function (latin1Str) { + // Shortcut + var latin1StrLength = latin1Str.length; + + // Convert + var words = []; + for (var i = 0; i < latin1StrLength; i++) { + words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); + } + + return new WordArray.init(words, latin1StrLength); + } + }; + + /** + * UTF-8 encoding strategy. + */ + var Utf8 = C_enc.Utf8 = { + /** + * Converts a word array to a UTF-8 string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The UTF-8 string. + * + * @static + * + * @example + * + * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); + */ + stringify: function (wordArray) { + try { + return decodeURIComponent(escape(Latin1.stringify(wordArray))); + } catch (e) { + throw new Error('Malformed UTF-8 data'); + } + }, + + /** + * Converts a UTF-8 string to a word array. + * + * @param {string} utf8Str The UTF-8 string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); + */ + parse: function (utf8Str) { + return Latin1.parse(unescape(encodeURIComponent(utf8Str))); + } + }; + + /** + * Abstract buffered block algorithm template. + * + * The property blockSize must be implemented in a concrete subtype. + * + * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 + */ + var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ + /** + * Resets this block algorithm's data buffer to its initial state. + * + * @example + * + * bufferedBlockAlgorithm.reset(); + */ + reset: function () { + // Initial values + this._data = new WordArray.init(); + this._nDataBytes = 0; + }, + + /** + * Adds new data to this block algorithm's buffer. + * + * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. + * + * @example + * + * bufferedBlockAlgorithm._append('data'); + * bufferedBlockAlgorithm._append(wordArray); + */ + _append: function (data) { + // Convert string to WordArray, else assume WordArray already + if (typeof data == 'string') { + data = Utf8.parse(data); + } + + // Append + this._data.concat(data); + this._nDataBytes += data.sigBytes; + }, + + /** + * Processes available data blocks. + * + * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. + * + * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. + * + * @return {WordArray} The processed data. + * + * @example + * + * var processedData = bufferedBlockAlgorithm._process(); + * var processedData = bufferedBlockAlgorithm._process(!!'flush'); + */ + _process: function (doFlush) { + var processedWords; + + // Shortcuts + var data = this._data; + var dataWords = data.words; + var dataSigBytes = data.sigBytes; + var blockSize = this.blockSize; + var blockSizeBytes = blockSize * 4; + + // Count blocks ready + var nBlocksReady = dataSigBytes / blockSizeBytes; + if (doFlush) { + // Round up to include partial blocks + nBlocksReady = Math.ceil(nBlocksReady); + } else { + // Round down to include only full blocks, + // less the number of blocks that must remain in the buffer + nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); + } + + // Count words ready + var nWordsReady = nBlocksReady * blockSize; + + // Count bytes ready + var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); + + // Process blocks + if (nWordsReady) { + for (var offset = 0; offset < nWordsReady; offset += blockSize) { + // Perform concrete-algorithm logic + this._doProcessBlock(dataWords, offset); + } + + // Remove processed words + processedWords = dataWords.splice(0, nWordsReady); + data.sigBytes -= nBytesReady; + } + + // Return processed words + return new WordArray.init(processedWords, nBytesReady); + }, + + /** + * Creates a copy of this object. + * + * @return {Object} The clone. + * + * @example + * + * var clone = bufferedBlockAlgorithm.clone(); + */ + clone: function () { + var clone = Base.clone.call(this); + clone._data = this._data.clone(); + + return clone; + }, + + _minBufferSize: 0 + }); + + /** + * Abstract hasher template. + * + * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) + */ + var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({ + /** + * Configuration options. + */ + cfg: Base.extend(), + + /** + * Initializes a newly created hasher. + * + * @param {Object} cfg (Optional) The configuration options to use for this hash computation. + * + * @example + * + * var hasher = CryptoJS.algo.SHA256.create(); + */ + init: function (cfg) { + // Apply config defaults + this.cfg = this.cfg.extend(cfg); + + // Set initial values + this.reset(); + }, + + /** + * Resets this hasher to its initial state. + * + * @example + * + * hasher.reset(); + */ + reset: function () { + // Reset data buffer + BufferedBlockAlgorithm.reset.call(this); + + // Perform concrete-hasher logic + this._doReset(); + }, + + /** + * Updates this hasher with a message. + * + * @param {WordArray|string} messageUpdate The message to append. + * + * @return {Hasher} This hasher. + * + * @example + * + * hasher.update('message'); + * hasher.update(wordArray); + */ + update: function (messageUpdate) { + // Append + this._append(messageUpdate); + + // Update the hash + this._process(); + + // Chainable + return this; + }, + + /** + * Finalizes the hash computation. + * Note that the finalize operation is effectively a destructive, read-once operation. + * + * @param {WordArray|string} messageUpdate (Optional) A final message update. + * + * @return {WordArray} The hash. + * + * @example + * + * var hash = hasher.finalize(); + * var hash = hasher.finalize('message'); + * var hash = hasher.finalize(wordArray); + */ + finalize: function (messageUpdate) { + // Final message update + if (messageUpdate) { + this._append(messageUpdate); + } + + // Perform concrete-hasher logic + var hash = this._doFinalize(); + + return hash; + }, + + blockSize: 512/32, + + /** + * Creates a shortcut function to a hasher's object interface. + * + * @param {Hasher} hasher The hasher to create a helper for. + * + * @return {Function} The shortcut function. + * + * @static + * + * @example + * + * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); + */ + _createHelper: function (hasher) { + return function (message, cfg) { + return new hasher.init(cfg).finalize(message); + }; + }, + + /** + * Creates a shortcut function to the HMAC's object interface. + * + * @param {Hasher} hasher The hasher to use in this HMAC helper. + * + * @return {Function} The shortcut function. + * + * @static + * + * @example + * + * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); + */ + _createHmacHelper: function (hasher) { + return function (message, key) { + return new C_algo.HMAC.init(hasher, key).finalize(message); + }; + } + }); + + /** + * Algorithm namespace. + */ + var C_algo = C.algo = {}; + + return C; + }(Math)); + + + return CryptoJS; + +})); +/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js"))) + +/***/ }), + +/***/ "./node_modules/crypto-js/md5.js": +/*!***************************************!*\ + !*** ./node_modules/crypto-js/md5.js ***! + \***************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +;(function (root, factory) { + if (true) { + // CommonJS + module.exports = exports = factory(__webpack_require__(/*! ./core */ "./node_modules/crypto-js/core.js")); + } + else {} +}(this, function (CryptoJS) { + + (function (Math) { + // Shortcuts + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var Hasher = C_lib.Hasher; + var C_algo = C.algo; + + // Constants table + var T = []; + + // Compute constants + (function () { + for (var i = 0; i < 64; i++) { + T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0; + } + }()); + + /** + * MD5 hash algorithm. + */ + var MD5 = C_algo.MD5 = Hasher.extend({ + _doReset: function () { + this._hash = new WordArray.init([ + 0x67452301, 0xefcdab89, + 0x98badcfe, 0x10325476 + ]); + }, + + _doProcessBlock: function (M, offset) { + // Swap endian + for (var i = 0; i < 16; i++) { + // Shortcuts + var offset_i = offset + i; + var M_offset_i = M[offset_i]; + + M[offset_i] = ( + (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | + (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) + ); + } + + // Shortcuts + var H = this._hash.words; + + var M_offset_0 = M[offset + 0]; + var M_offset_1 = M[offset + 1]; + var M_offset_2 = M[offset + 2]; + var M_offset_3 = M[offset + 3]; + var M_offset_4 = M[offset + 4]; + var M_offset_5 = M[offset + 5]; + var M_offset_6 = M[offset + 6]; + var M_offset_7 = M[offset + 7]; + var M_offset_8 = M[offset + 8]; + var M_offset_9 = M[offset + 9]; + var M_offset_10 = M[offset + 10]; + var M_offset_11 = M[offset + 11]; + var M_offset_12 = M[offset + 12]; + var M_offset_13 = M[offset + 13]; + var M_offset_14 = M[offset + 14]; + var M_offset_15 = M[offset + 15]; + + // Working varialbes + var a = H[0]; + var b = H[1]; + var c = H[2]; + var d = H[3]; + + // Computation + a = FF(a, b, c, d, M_offset_0, 7, T[0]); + d = FF(d, a, b, c, M_offset_1, 12, T[1]); + c = FF(c, d, a, b, M_offset_2, 17, T[2]); + b = FF(b, c, d, a, M_offset_3, 22, T[3]); + a = FF(a, b, c, d, M_offset_4, 7, T[4]); + d = FF(d, a, b, c, M_offset_5, 12, T[5]); + c = FF(c, d, a, b, M_offset_6, 17, T[6]); + b = FF(b, c, d, a, M_offset_7, 22, T[7]); + a = FF(a, b, c, d, M_offset_8, 7, T[8]); + d = FF(d, a, b, c, M_offset_9, 12, T[9]); + c = FF(c, d, a, b, M_offset_10, 17, T[10]); + b = FF(b, c, d, a, M_offset_11, 22, T[11]); + a = FF(a, b, c, d, M_offset_12, 7, T[12]); + d = FF(d, a, b, c, M_offset_13, 12, T[13]); + c = FF(c, d, a, b, M_offset_14, 17, T[14]); + b = FF(b, c, d, a, M_offset_15, 22, T[15]); + + a = GG(a, b, c, d, M_offset_1, 5, T[16]); + d = GG(d, a, b, c, M_offset_6, 9, T[17]); + c = GG(c, d, a, b, M_offset_11, 14, T[18]); + b = GG(b, c, d, a, M_offset_0, 20, T[19]); + a = GG(a, b, c, d, M_offset_5, 5, T[20]); + d = GG(d, a, b, c, M_offset_10, 9, T[21]); + c = GG(c, d, a, b, M_offset_15, 14, T[22]); + b = GG(b, c, d, a, M_offset_4, 20, T[23]); + a = GG(a, b, c, d, M_offset_9, 5, T[24]); + d = GG(d, a, b, c, M_offset_14, 9, T[25]); + c = GG(c, d, a, b, M_offset_3, 14, T[26]); + b = GG(b, c, d, a, M_offset_8, 20, T[27]); + a = GG(a, b, c, d, M_offset_13, 5, T[28]); + d = GG(d, a, b, c, M_offset_2, 9, T[29]); + c = GG(c, d, a, b, M_offset_7, 14, T[30]); + b = GG(b, c, d, a, M_offset_12, 20, T[31]); + + a = HH(a, b, c, d, M_offset_5, 4, T[32]); + d = HH(d, a, b, c, M_offset_8, 11, T[33]); + c = HH(c, d, a, b, M_offset_11, 16, T[34]); + b = HH(b, c, d, a, M_offset_14, 23, T[35]); + a = HH(a, b, c, d, M_offset_1, 4, T[36]); + d = HH(d, a, b, c, M_offset_4, 11, T[37]); + c = HH(c, d, a, b, M_offset_7, 16, T[38]); + b = HH(b, c, d, a, M_offset_10, 23, T[39]); + a = HH(a, b, c, d, M_offset_13, 4, T[40]); + d = HH(d, a, b, c, M_offset_0, 11, T[41]); + c = HH(c, d, a, b, M_offset_3, 16, T[42]); + b = HH(b, c, d, a, M_offset_6, 23, T[43]); + a = HH(a, b, c, d, M_offset_9, 4, T[44]); + d = HH(d, a, b, c, M_offset_12, 11, T[45]); + c = HH(c, d, a, b, M_offset_15, 16, T[46]); + b = HH(b, c, d, a, M_offset_2, 23, T[47]); + + a = II(a, b, c, d, M_offset_0, 6, T[48]); + d = II(d, a, b, c, M_offset_7, 10, T[49]); + c = II(c, d, a, b, M_offset_14, 15, T[50]); + b = II(b, c, d, a, M_offset_5, 21, T[51]); + a = II(a, b, c, d, M_offset_12, 6, T[52]); + d = II(d, a, b, c, M_offset_3, 10, T[53]); + c = II(c, d, a, b, M_offset_10, 15, T[54]); + b = II(b, c, d, a, M_offset_1, 21, T[55]); + a = II(a, b, c, d, M_offset_8, 6, T[56]); + d = II(d, a, b, c, M_offset_15, 10, T[57]); + c = II(c, d, a, b, M_offset_6, 15, T[58]); + b = II(b, c, d, a, M_offset_13, 21, T[59]); + a = II(a, b, c, d, M_offset_4, 6, T[60]); + d = II(d, a, b, c, M_offset_11, 10, T[61]); + c = II(c, d, a, b, M_offset_2, 15, T[62]); + b = II(b, c, d, a, M_offset_9, 21, T[63]); + + // Intermediate hash value + H[0] = (H[0] + a) | 0; + H[1] = (H[1] + b) | 0; + H[2] = (H[2] + c) | 0; + H[3] = (H[3] + d) | 0; + }, + + _doFinalize: function () { + // Shortcuts + var data = this._data; + var dataWords = data.words; + + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + + var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000); + var nBitsTotalL = nBitsTotal; + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = ( + (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) | + (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00) + ); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( + (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) | + (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00) + ); + + data.sigBytes = (dataWords.length + 1) * 4; + + // Hash final blocks + this._process(); + + // Shortcuts + var hash = this._hash; + var H = hash.words; + + // Swap endian + for (var i = 0; i < 4; i++) { + // Shortcut + var H_i = H[i]; + + H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | + (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); + } + + // Return final computed hash + return hash; + }, + + clone: function () { + var clone = Hasher.clone.call(this); + clone._hash = this._hash.clone(); + + return clone; + } + }); + + function FF(a, b, c, d, x, s, t) { + var n = a + ((b & c) | (~b & d)) + x + t; + return ((n << s) | (n >>> (32 - s))) + b; + } + + function GG(a, b, c, d, x, s, t) { + var n = a + ((b & d) | (c & ~d)) + x + t; + return ((n << s) | (n >>> (32 - s))) + b; + } + + function HH(a, b, c, d, x, s, t) { + var n = a + (b ^ c ^ d) + x + t; + return ((n << s) | (n >>> (32 - s))) + b; + } + + function II(a, b, c, d, x, s, t) { + var n = a + (c ^ (b | ~d)) + x + t; + return ((n << s) | (n >>> (32 - s))) + b; + } + + /** + * Shortcut function to the hasher's object interface. + * + * @param {WordArray|string} message The message to hash. + * + * @return {WordArray} The hash. + * + * @static + * + * @example + * + * var hash = CryptoJS.MD5('message'); + * var hash = CryptoJS.MD5(wordArray); + */ + C.MD5 = Hasher._createHelper(MD5); + + /** + * Shortcut function to the HMAC's object interface. + * + * @param {WordArray|string} message The message to hash. + * @param {WordArray|string} key The secret key. + * + * @return {WordArray} The HMAC. + * + * @static + * + * @example + * + * var hmac = CryptoJS.HmacMD5(message, key); + */ + C.HmacMD5 = Hasher._createHmacHelper(MD5); + }(Math)); + + + return CryptoJS.MD5; + +})); + /***/ }), /***/ "./node_modules/ev-emitter/ev-emitter.js": @@ -20967,444 +22033,45 @@ try { /***/ }), -/***/ "./node_modules/smoothscroll-polyfill/dist/smoothscroll.js": -/*!*****************************************************************!*\ - !*** ./node_modules/smoothscroll-polyfill/dist/smoothscroll.js ***! - \*****************************************************************/ +/***/ "./node_modules/webpack/buildin/global.js": +/*!***********************************!*\ + !*** (webpack)/buildin/global.js ***! + \***********************************/ /*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -/* smoothscroll v0.4.4 - 2019 - Dustan Kasten, Jeremias Menichelli - MIT License */ -(function () { - 'use strict'; - - // polyfill - function polyfill() { - // aliases - var w = window; - var d = document; - - // return if scroll behavior is supported and polyfill is not forced - if ( - 'scrollBehavior' in d.documentElement.style && - w.__forceSmoothScrollPolyfill__ !== true - ) { - return; - } - - // globals - var Element = w.HTMLElement || w.Element; - var SCROLL_TIME = 468; - - // object gathering original scroll methods - var original = { - scroll: w.scroll || w.scrollTo, - scrollBy: w.scrollBy, - elementScroll: Element.prototype.scroll || scrollElement, - scrollIntoView: Element.prototype.scrollIntoView - }; - - // define timing method - var now = - w.performance && w.performance.now - ? w.performance.now.bind(w.performance) - : Date.now; - - /** - * indicates if a the current browser is made by Microsoft - * @method isMicrosoftBrowser - * @param {String} userAgent - * @returns {Boolean} - */ - function isMicrosoftBrowser(userAgent) { - var userAgentPatterns = ['MSIE ', 'Trident/', 'Edge/']; - - return new RegExp(userAgentPatterns.join('|')).test(userAgent); - } - - /* - * IE has rounding bug rounding down clientHeight and clientWidth and - * rounding up scrollHeight and scrollWidth causing false positives - * on hasScrollableSpace - */ - var ROUNDING_TOLERANCE = isMicrosoftBrowser(w.navigator.userAgent) ? 1 : 0; - - /** - * changes scroll position inside an element - * @method scrollElement - * @param {Number} x - * @param {Number} y - * @returns {undefined} - */ - function scrollElement(x, y) { - this.scrollLeft = x; - this.scrollTop = y; - } - - /** - * returns result of applying ease math function to a number - * @method ease - * @param {Number} k - * @returns {Number} - */ - function ease(k) { - return 0.5 * (1 - Math.cos(Math.PI * k)); - } - - /** - * indicates if a smooth behavior should be applied - * @method shouldBailOut - * @param {Number|Object} firstArg - * @returns {Boolean} - */ - function shouldBailOut(firstArg) { - if ( - firstArg === null || - typeof firstArg !== 'object' || - firstArg.behavior === undefined || - firstArg.behavior === 'auto' || - firstArg.behavior === 'instant' - ) { - // first argument is not an object/null - // or behavior is auto, instant or undefined - return true; - } - - if (typeof firstArg === 'object' && firstArg.behavior === 'smooth') { - // first argument is an object and behavior is smooth - return false; - } - - // throw error when behavior is not supported - throw new TypeError( - 'behavior member of ScrollOptions ' + - firstArg.behavior + - ' is not a valid value for enumeration ScrollBehavior.' - ); - } - - /** - * indicates if an element has scrollable space in the provided axis - * @method hasScrollableSpace - * @param {Node} el - * @param {String} axis - * @returns {Boolean} - */ - function hasScrollableSpace(el, axis) { - if (axis === 'Y') { - return el.clientHeight + ROUNDING_TOLERANCE < el.scrollHeight; - } - - if (axis === 'X') { - return el.clientWidth + ROUNDING_TOLERANCE < el.scrollWidth; - } - } - - /** - * indicates if an element has a scrollable overflow property in the axis - * @method canOverflow - * @param {Node} el - * @param {String} axis - * @returns {Boolean} - */ - function canOverflow(el, axis) { - var overflowValue = w.getComputedStyle(el, null)['overflow' + axis]; - - return overflowValue === 'auto' || overflowValue === 'scroll'; - } - - /** - * indicates if an element can be scrolled in either axis - * @method isScrollable - * @param {Node} el - * @param {String} axis - * @returns {Boolean} - */ - function isScrollable(el) { - var isScrollableY = hasScrollableSpace(el, 'Y') && canOverflow(el, 'Y'); - var isScrollableX = hasScrollableSpace(el, 'X') && canOverflow(el, 'X'); - - return isScrollableY || isScrollableX; - } - - /** - * finds scrollable parent of an element - * @method findScrollableParent - * @param {Node} el - * @returns {Node} el - */ - function findScrollableParent(el) { - while (el !== d.body && isScrollable(el) === false) { - el = el.parentNode || el.host; - } - - return el; - } - - /** - * self invoked function that, given a context, steps through scrolling - * @method step - * @param {Object} context - * @returns {undefined} - */ - function step(context) { - var time = now(); - var value; - var currentX; - var currentY; - var elapsed = (time - context.startTime) / SCROLL_TIME; - - // avoid elapsed times higher than one - elapsed = elapsed > 1 ? 1 : elapsed; - - // apply easing to elapsed time - value = ease(elapsed); - - currentX = context.startX + (context.x - context.startX) * value; - currentY = context.startY + (context.y - context.startY) * value; - - context.method.call(context.scrollable, currentX, currentY); - - // scroll more if we have not reached our destination - if (currentX !== context.x || currentY !== context.y) { - w.requestAnimationFrame(step.bind(w, context)); - } - } - - /** - * scrolls window or element with a smooth behavior - * @method smoothScroll - * @param {Object|Node} el - * @param {Number} x - * @param {Number} y - * @returns {undefined} - */ - function smoothScroll(el, x, y) { - var scrollable; - var startX; - var startY; - var method; - var startTime = now(); - - // define scroll context - if (el === d.body) { - scrollable = w; - startX = w.scrollX || w.pageXOffset; - startY = w.scrollY || w.pageYOffset; - method = original.scroll; - } else { - scrollable = el; - startX = el.scrollLeft; - startY = el.scrollTop; - method = scrollElement; - } - - // scroll looping over a frame - step({ - scrollable: scrollable, - method: method, - startTime: startTime, - startX: startX, - startY: startY, - x: x, - y: y - }); - } - - // ORIGINAL METHODS OVERRIDES - // w.scroll and w.scrollTo - w.scroll = w.scrollTo = function() { - // avoid action when no arguments are passed - if (arguments[0] === undefined) { - return; - } - - // avoid smooth behavior if not required - if (shouldBailOut(arguments[0]) === true) { - original.scroll.call( - w, - arguments[0].left !== undefined - ? arguments[0].left - : typeof arguments[0] !== 'object' - ? arguments[0] - : w.scrollX || w.pageXOffset, - // use top prop, second argument if present or fallback to scrollY - arguments[0].top !== undefined - ? arguments[0].top - : arguments[1] !== undefined - ? arguments[1] - : w.scrollY || w.pageYOffset - ); - - return; - } - - // LET THE SMOOTHNESS BEGIN! - smoothScroll.call( - w, - d.body, - arguments[0].left !== undefined - ? ~~arguments[0].left - : w.scrollX || w.pageXOffset, - arguments[0].top !== undefined - ? ~~arguments[0].top - : w.scrollY || w.pageYOffset - ); - }; - - // w.scrollBy - w.scrollBy = function() { - // avoid action when no arguments are passed - if (arguments[0] === undefined) { - return; - } - - // avoid smooth behavior if not required - if (shouldBailOut(arguments[0])) { - original.scrollBy.call( - w, - arguments[0].left !== undefined - ? arguments[0].left - : typeof arguments[0] !== 'object' ? arguments[0] : 0, - arguments[0].top !== undefined - ? arguments[0].top - : arguments[1] !== undefined ? arguments[1] : 0 - ); - - return; - } - - // LET THE SMOOTHNESS BEGIN! - smoothScroll.call( - w, - d.body, - ~~arguments[0].left + (w.scrollX || w.pageXOffset), - ~~arguments[0].top + (w.scrollY || w.pageYOffset) - ); - }; - - // Element.prototype.scroll and Element.prototype.scrollTo - Element.prototype.scroll = Element.prototype.scrollTo = function() { - // avoid action when no arguments are passed - if (arguments[0] === undefined) { - return; - } - - // avoid smooth behavior if not required - if (shouldBailOut(arguments[0]) === true) { - // if one number is passed, throw error to match Firefox implementation - if (typeof arguments[0] === 'number' && arguments[1] === undefined) { - throw new SyntaxError('Value could not be converted'); - } - - original.elementScroll.call( - this, - // use left prop, first number argument or fallback to scrollLeft - arguments[0].left !== undefined - ? ~~arguments[0].left - : typeof arguments[0] !== 'object' ? ~~arguments[0] : this.scrollLeft, - // use top prop, second argument or fallback to scrollTop - arguments[0].top !== undefined - ? ~~arguments[0].top - : arguments[1] !== undefined ? ~~arguments[1] : this.scrollTop - ); - - return; - } - - var left = arguments[0].left; - var top = arguments[0].top; - - // LET THE SMOOTHNESS BEGIN! - smoothScroll.call( - this, - this, - typeof left === 'undefined' ? this.scrollLeft : ~~left, - typeof top === 'undefined' ? this.scrollTop : ~~top - ); - }; - - // Element.prototype.scrollBy - Element.prototype.scrollBy = function() { - // avoid action when no arguments are passed - if (arguments[0] === undefined) { - return; - } - - // avoid smooth behavior if not required - if (shouldBailOut(arguments[0]) === true) { - original.elementScroll.call( - this, - arguments[0].left !== undefined - ? ~~arguments[0].left + this.scrollLeft - : ~~arguments[0] + this.scrollLeft, - arguments[0].top !== undefined - ? ~~arguments[0].top + this.scrollTop - : ~~arguments[1] + this.scrollTop - ); +/***/ (function(module, exports) { - return; - } +var g; - this.scroll({ - left: ~~arguments[0].left + this.scrollLeft, - top: ~~arguments[0].top + this.scrollTop, - behavior: arguments[0].behavior - }); - }; +// This works in non-strict mode +g = (function() { + return this; +})(); - // Element.prototype.scrollIntoView - Element.prototype.scrollIntoView = function() { - // avoid smooth behavior if not required - if (shouldBailOut(arguments[0]) === true) { - original.scrollIntoView.call( - this, - arguments[0] === undefined ? true : arguments[0] - ); +try { + // This works if eval is allowed (see CSP) + g = g || new Function("return this")(); +} catch (e) { + // This works if the window reference is available + if (typeof window === "object") g = window; +} - return; - } +// g can still be undefined, but nothing to do about it... +// We return undefined, instead of nothing here, so it's +// easier to handle this case. if(!global) { ...} - // LET THE SMOOTHNESS BEGIN! - var scrollableParent = findScrollableParent(this); - var parentRects = scrollableParent.getBoundingClientRect(); - var clientRects = this.getBoundingClientRect(); - - if (scrollableParent !== d.body) { - // reveal element inside parent - smoothScroll.call( - this, - scrollableParent, - scrollableParent.scrollLeft + clientRects.left - parentRects.left, - scrollableParent.scrollTop + clientRects.top - parentRects.top - ); +module.exports = g; - // reveal parent in viewport unless is fixed - if (w.getComputedStyle(scrollableParent).position !== 'fixed') { - w.scrollBy({ - left: parentRects.left, - top: parentRects.top, - behavior: 'smooth' - }); - } - } else { - // reveal element in viewport - w.scrollBy({ - left: clientRects.left, - top: clientRects.top, - behavior: 'smooth' - }); - } - }; - } - if (true) { - // commonjs - module.exports = { polyfill: polyfill }; - } else {} +/***/ }), -}()); +/***/ 0: +/*!************************!*\ + !*** crypto (ignored) ***! + \************************/ +/*! no static exports found */ +/***/ (function(module, exports) { +/* (ignored) */ /***/ }) diff --git a/core/src/js/addons/cache.js b/core/src/js/addons/cache.js index a17f617..124c70c 100644 --- a/core/src/js/addons/cache.js +++ b/core/src/js/addons/cache.js @@ -1,4 +1,21 @@ import axios from 'axios'; +import { parseQuerystring } from '../addons/filters'; +import MD5 from 'crypto-js/md5'; + +/** + * Create unique cache slug from query params. + * + * @param {object} alm The ALM object. + * @param {object} data The data object. + * @return {object} Modified data object. + */ +export function getCacheSlug(alm, data) { + if (alm.addons.nextpage) { + return `page-${alm.page + alm.addons.nextpage_startpage}`; + } else { + return MD5(JSON.stringify(data)).toString(); + } +} /** * Create a single post cache file. @@ -23,7 +40,7 @@ export function createCacheFile(alm, content, type = 'standard') { formData.append('name', name); formData.append('html', content.trim()); - axios.post(alm_localize.ajaxurl, formData).then(function (response) { + axios.post(alm_localize.ajaxurl, formData).then(function () { console.log('Cache created for: ' + alm.canonical_url); }); } @@ -31,8 +48,8 @@ export function createCacheFile(alm, content, type = 'standard') { /** * Create a WooCommerce cache file. * - * @param {Object} alm - * @param {String} content + * @param {object} alm The ALM object. + * @param {string} content The content to cache. * @since 5.3.1 */ export function wooCache(alm, content) { @@ -53,3 +70,79 @@ export function wooCache(alm, content) { console.log('Cache created for post: ' + alm.canonical_url); }); } + +/** + * Generate the cache page URL for GET request + * + * @param {object} alm The ALM object. + * @since 5.0 + * @supports Standard, SEO, Filters, Nextpage, Single Posts + */ +export function getCacheUrl(alm) { + if (!alm) { + return false; + } + + let firstpage = '1'; + let cache_url = ''; + let ext = '.html'; + let path = alm.addons.cache_path + alm.addons.cache_id; + + // SEO Add-on + if (alm.init && alm.addons.seo && alm.isPaged) { + // If request is a paged URL (e.g. /page/3/) + cache_url = path + '/page-' + firstpage + '-' + alm.start_page + ext; + } + + // Filters + else if (alm.addons.filters) { + let filtersPath = parseQuerystring(path); + + if (alm.init && alm.isPaged) { + // First run & Paged + cache_url = filtersPath + '/page-' + firstpage + '-' + alm.addons.filters_startpage + ext; + } else { + let page = alm.page + 1; + + if (alm.addons.preloaded === 'true') { + // Preloaded + Filters + page = alm.page + 2; + } + cache_url = filtersPath + '/page-' + page + ext; + } + } + + // Nextpage + else if (alm.addons.nextpage) { + let nextpage_cache_url; + if (alm.addons.paging) { + nextpage_cache_url = parseInt(alm.page) + 1; + } else { + nextpage_cache_url = parseInt(alm.page) + 2; + if (alm.isPaged) { + // If the request a paged URL (/page/3/) + nextpage_cache_url = parseInt(alm.page) + parseInt(alm.addons.nextpage_startpage) + 1; + } + } + + cache_url = path + '/page-' + nextpage_cache_url + ext; + } + + // Single Post + else if (alm.addons.single_post) { + cache_url = path + '/' + alm.addons.single_post_id + ext; + } + + // Comments & Preloaded + else if (alm.addons.comments === 'true' && alm.addons.preloaded === 'true') { + // When using comments we need to increase the current page by 2 + cache_url = path + '/page-' + (alm.page + 2) + ext; + } + + // Standard URL request + else { + cache_url = path + '/page-' + (alm.page + 1) + ext; + } + + return cache_url; +} diff --git a/core/src/js/ajax-load-more.js b/core/src/js/ajax-load-more.js index 6c67350..23c8b3e 100755 --- a/core/src/js/ajax-load-more.js +++ b/core/src/js/ajax-load-more.js @@ -1,24 +1,3 @@ -/** - * Ajax Load More - * https://connekthq.com/plugins/ajax-load-more/ - * Author: Darren Cooney - * Twitter: @KaptonKaos, @ajaxloadmore, @connekthq - * Copyright Connekt Media - https://connekthq.com - */ - -// Polyfills -require('@babel/polyfill/noConflict'); -require('focus-options-polyfill'); -require('./helpers/polyfills.js'); - -// External Modules -let qs = require('qs'); -let imagesLoaded = require('imagesloaded'); -import axios from 'axios'; -import smoothscroll from 'smoothscroll-polyfill'; // Smooth scrolling polyfill -axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; -smoothscroll.polyfill(); - // ALM Modules import './helpers/helpers'; //import commentReplyFix from './helpers/commentReplyFix'; @@ -30,7 +9,6 @@ import { singlePostHTML } from './addons/singleposts'; import { woocommerce, woocommerceLoaded, wooGetContent, wooInit, wooReset } from './addons/woocommerce'; import almAppendChildren from './helpers/almAppendChildren'; import almDomParser from './helpers/almDomParser'; -import getCacheUrl from './helpers/getCacheUrl'; import getParameterByName from './helpers/getParameterByName'; import getScrollPercentage from './helpers/getScrollPercentage'; import * as queryParams from './helpers/queryParams'; @@ -52,6 +30,17 @@ import setFocus from './modules/setFocus'; import setLocalizedVars from './modules/setLocalizedVars'; import { tableOfContents } from './modules/tableofcontents'; import getTotals from './helpers/getTotals'; +import axios from 'axios'; + +// External Modules +let qs = require('qs'); +let imagesLoaded = require('imagesloaded'); +axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; + +// Polyfills +require('@babel/polyfill/noConflict'); +require('focus-options-polyfill'); +require('./helpers/polyfills.js'); // Global filtering state. let alm_is_filtering = false; @@ -191,8 +180,7 @@ let alm_is_filtering = false; if (alm.addons.cache === 'true') { alm.addons.cache_id = alm.listing.dataset.cacheId; alm.addons.cache_path = alm.listing.dataset.cachePath; - alm.addons.cache_logged_in = alm.listing.dataset.cacheLoggedIn; - alm.addons.cache_logged_in = alm.addons.cache_logged_in === undefined ? false : alm.addons.cache_logged_in; + alm.addons.cache_logged_in = alm.listing.dataset.cacheLoggedIn ? alm.listing.dataset.cacheLoggedIn : false; } // CTA add-on @@ -619,15 +607,14 @@ let alm_is_filtering = false; * @since 2.0.0 */ alm.AjaxLoadMore.loadPosts = function () { - if (typeof almOnChange === 'function') { - window.almOnChange(alm); - } - - // Check for ajax blocker. if (alm.disable_ajax) { return; } + if (typeof almOnChange === 'function') { + window.almOnChange(alm); + } + alm.loading = true; showPlaceholder(alm); @@ -758,7 +745,7 @@ let alm_is_filtering = false; // Dispatch Ajax request. if (alm.extensions.restapi) { // REST API - alm.AjaxLoadMore.restapi(alm, action, queryType); + alm.AjaxLoadMore.restapi(alm); } else if (alm.addons.tabs) { // Tabs alm.AjaxLoadMore.tabs(alm); @@ -789,11 +776,11 @@ let alm_is_filtering = false; return config; }); - // Get Ajax URL + // Get Ajax URL. let ajaxURL = alm_localize.ajaxurl; - // Get data params - let params = queryParams.almGetAjaxParams(alm, action, queryType); // [./helpers/queryParams.js + // Get query params. + let params = queryParams.getAjaxParams(alm, action, queryType); // Single Posts Add-on // If has `single_post_target`, adjust the Ajax URL to the post URL. @@ -923,10 +910,10 @@ let alm_is_filtering = false; * @param {string} queryType The type of Ajax request (standard/totalposts). * @since 5.0.0 */ - alm.AjaxLoadMore.restapi = function (alm, action, queryType) { + alm.AjaxLoadMore.restapi = function (alm) { let alm_rest_template = wp.template(alm.extensions.restapi_template_id); let alm_rest_url = `${alm.extensions.restapi_base_url}/${alm.extensions.restapi_namespace}/${alm.extensions.restapi_endpoint}`; - let params = queryParams.almGetRestParams(alm); // [./helpers/queryParams.js] + let params = queryParams.getRestAPIParams(alm); // [./helpers/queryParams.js] // Axios Interceptor for nested data objects axios.interceptors.request.use((config) => { diff --git a/core/src/js/helpers/getCacheUrl.js b/core/src/js/helpers/getCacheUrl.js deleted file mode 100755 index 78b8f5d..0000000 --- a/core/src/js/helpers/getCacheUrl.js +++ /dev/null @@ -1,79 +0,0 @@ -import { parseQuerystring } from '../addons/filters'; - -/** - * Generate the cache page URL for GET request - * - * @param {*} alm - * @since 5.0 - * @supports Standard, SEO, Filters, Nextpage, Single Posts - */ -const getCacheUrl = function (alm) { - if (!alm) { - return false; - } - - let firstpage = '1'; - let cache_url = ''; - let ext = '.html'; - let path = alm.addons.cache_path + alm.addons.cache_id; - - // SEO Add-on - if (alm.init && alm.addons.seo && alm.isPaged) { - // If request is a paged URL (e.g. /page/3/) - cache_url = path + '/page-' + firstpage + '-' + alm.start_page + ext; - } - - // Filters - else if (alm.addons.filters) { - let filtersPath = parseQuerystring(path); - - if (alm.init && alm.isPaged) { - // First run & Paged - cache_url = filtersPath + '/page-' + firstpage + '-' + alm.addons.filters_startpage + ext; - } else { - let page = alm.page + 1; - - if (alm.addons.preloaded === 'true') { - // Preloaded + Filters - page = alm.page + 2; - } - cache_url = filtersPath + '/page-' + page + ext; - } - } - - // Nextpage - else if (alm.addons.nextpage) { - let nextpage_cache_url; - if (alm.addons.paging) { - nextpage_cache_url = parseInt(alm.page) + 1; - } else { - nextpage_cache_url = parseInt(alm.page) + 2; - if (alm.isPaged) { - // If the request a paged URL (/page/3/) - nextpage_cache_url = parseInt(alm.page) + parseInt(alm.addons.nextpage_startpage) + 1; - } - } - - cache_url = path + '/page-' + nextpage_cache_url + ext; - } - - // Single Post - else if (alm.addons.single_post) { - cache_url = path + '/' + alm.addons.single_post_id + ext; - } - - // Comments & Preloaded - else if (alm.addons.comments === 'true' && alm.addons.preloaded === 'true') { - // When using comments we need to increase the current page by 2 - cache_url = path + '/page-' + (alm.page + 2) + ext; - } - - // Standard URL request - else { - cache_url = path + '/page-' + (alm.page + 1) + ext; - } - - return cache_url; -}; - -export default getCacheUrl; diff --git a/core/src/js/helpers/queryParams.js b/core/src/js/helpers/queryParams.js index a92127f..422cbae 100755 --- a/core/src/js/helpers/queryParams.js +++ b/core/src/js/helpers/queryParams.js @@ -1,23 +1,26 @@ +import { getCacheSlug } from '../addons/cache'; + /** - * almGetAjaxParams - * Build the data object to send with the Ajax request + * Build the data object to send with the Ajax request. * - * @param alm object - * @param action string - * @param queryType string + * @param {object} alm The ALM object. + * @param {string} action The HTTP action. + * @param {string} queryType The query type. + * @return {object} The data object. * @since 3.6 */ - -export function almGetAjaxParams(alm, action, queryType) { +export function getAjaxParams(alm, action, queryType) { // Defaults - let data = { + const data = { + action: action, + query_type: queryType, id: alm.id, - post_id: alm.post_id, + post_id: parseInt(alm.post_id), slug: alm.slug, canonical_url: encodeURIComponent(alm.canonical_url), - posts_per_page: alm.posts_per_page, - page: alm.page, - offset: alm.offset, + posts_per_page: parseInt(alm.posts_per_page), + page: parseInt(alm.page), + offset: parseInt(alm.offset), post_type: alm.post_type, repeater: alm.repeater, seo_start_page: alm.start_page, @@ -36,13 +39,9 @@ export function almGetAjaxParams(alm, action, queryType) { if (alm.addons.paging) { data.paging = alm.addons.paging; } - if (alm.addons.preloaded) { + if (alm.addons.preloaded === 'true') { data.preloaded = alm.addons.preloaded; - data.preloaded_amount = alm.addons.preloaded_amount; - } - if (alm.addons.cache === 'true') { - data.cache_id = alm.addons.cache_id; - data.cache_logged_in = alm.addons.cache_logged_in; + data.preloaded_amount = parseInt(alm.addons.preloaded_amount); } if (alm.acf_array) { data.acf = alm.acf_array; @@ -167,23 +166,27 @@ export function almGetAjaxParams(alm, action, queryType) { data.vars = escape(alm.listing.dataset.vars); } - data.action = action; - data.query_type = queryType; + // Set Cache params. + if (alm.addons.cache === 'true') { + data.cache_id = alm.addons.cache_id; + data.cache_logged_in = alm.addons.cache_logged_in; + data.cache_slug = getCacheSlug(alm, data); + } return data; } /** - * almGetRestParams - * Build the REST API data object to send with REST API request + * Build the REST API data object to send with REST API request. * - * @param alm object + * @param {object} alm The ALM object. + * @return {object} The data object. * @since 3.6 */ -export function almGetRestParams(alm) { - let data = { +export function getRestAPIParams(alm) { + const data = { id: alm.id, - post_id: alm.post_id, + post_id: parseInt(alm.post_id), posts_per_page: alm.posts_per_page, page: alm.page, offset: alm.offset, @@ -222,6 +225,5 @@ export function almGetRestParams(alm) { preloaded_amount: alm.addons.preloaded_amount, seo_start_page: alm.start_page, }; - return data; } diff --git a/package.json b/package.json index 28e9710..fa269af 100755 --- a/package.json +++ b/package.json @@ -24,10 +24,10 @@ ], "dependencies": { "@babel/polyfill": "^7.10.1", + "crypto-js": "^4.1.1", "es6-promise": "^4.1.1", "focus-options-polyfill": "^1.4.0", - "lodash": "^4.17.15", - "smoothscroll-polyfill": "^0.4.3" + "lodash": "^4.17.15" }, "devDependencies": { "autoprefixer": "^7.1.4", @@ -72,4 +72,4 @@ "webpack": "^4.43.0", "webpack-cli": "^3.3.11" } -} \ No newline at end of file +} From 3aacbac35c25a0a2eb749a873bd839fcf546ac0f Mon Sep 17 00:00:00 2001 From: Darren Cooney Date: Wed, 10 May 2023 10:10:25 -0400 Subject: [PATCH 05/18] Adding cache changes for woo, elementor and single posts --- ajax-load-more.php | 37 +- core/dist/js/ajax-load-more.js | 1448 ++++++++++++++------------- core/src/js/addons/cache.js | 174 ++-- core/src/js/addons/elementor.js | 180 ++-- core/src/js/addons/singleposts.js | 48 +- core/src/js/addons/woocommerce.js | 128 ++- core/src/js/ajax-load-more.js | 349 ++----- core/src/js/helpers/almDomParser.js | 10 +- core/src/js/helpers/api.js | 14 + core/src/js/helpers/queryParams.js | 2 +- core/src/js/modules/loadItems.js | 42 +- 11 files changed, 1165 insertions(+), 1267 deletions(-) create mode 100644 core/src/js/helpers/api.js diff --git a/ajax-load-more.php b/ajax-load-more.php index a6e8ce2..50f2efc 100755 --- a/ajax-load-more.php +++ b/ajax-load-more.php @@ -17,14 +17,21 @@ /* IN Progress: - Started creating the cache slug in the JavaScript and passing it to the PHP using CryptoJS. +- +TODO: +- Remove the create fetching in all addons/extensions. +- Remove all functions and helpers for ALMCache::get_cache_file() ADD-ON Updates: - FILTERS: - Fix issue with decimal values in range slider. -- Next Page -- Cache -- Comments +- Next Page [1.6.4] +- Cache [2.0] +- Comments [1.2.1] +- Single Posts [1.5.5] +- Elementor [1.1.4] + Extension Updates - Terms @@ -57,8 +64,11 @@ Plugin CHANGES * NOTICE: Ajax Load More 6.0 is a major update and includes a number of breaking changes. Please review the documentation before updating. * NOTICE: Cache add-on < 2.0 is no longer supported. Please update to the latest version of the Cache add-on to use Cache functionality. +* UPDATE: Adding required functionality for the Cache 2.0 update. This introduces a new cache structure using MD5 hash for many cache URLs. -* UPDATE: Adding required functionality for the Cache 2.0 update. This introduces a new cache structure using MD5 hash for cache URLs. +* UPDATE: Code refactoring, cleanup and overall improvements across the Ajax Load More. +* FIX: Fixed issue with Elementor and Cache add-ons not working in some instances. +* FIX: Fixed issue with WooCommerce and Cache add-ons not working in some instances. */ @@ -408,6 +418,10 @@ public function alm_enqueue_scripts() { ALM_ENQUEUE::alm_enqueue_css( ALM_SLUG, $file ); } + // Determine if there is a trailing slash in the permalink structure. + $permalink_structure = get_option( 'permalink_structure' ); + $trailing_slash = substr( $permalink_structure, -1 ) === '/' ? 'true' : 'false'; + // Localized JS variables. wp_localize_script( 'ajax-load-more', @@ -418,6 +432,8 @@ public function alm_enqueue_scripts() { 'alm_nonce' => wp_create_nonce( 'ajax_load_more_nonce' ), 'rest_api' => esc_url_raw( rest_url() ), 'rest_nonce' => wp_create_nonce( 'wp_rest' ), + 'trailing_slash' => $trailing_slash, + 'is_front_page' => is_home() || is_front_page() ? 'true' : 'false', 'pluginurl' => ALM_URL, 'speed' => apply_filters( 'alm_speed', 200 ), 'ga_debug' => apply_filters( 'alm_ga_debug', 'false' ), @@ -588,17 +604,6 @@ public function alm_query_posts() { */ $args['alm_query'] = $single_post ? 'single_posts' : 'alm'; - /** - * Cache Add-on. - * Check for cached data before running WP_Query. - */ - if ( $cache_id && method_exists( 'ALMCache', 'get_cache_file' ) && $query_type !== 'totalposts' ) { - $cache_data = ALMCache::get_cache_file( $cache_id, $cache_slug ); - if ( $cache_data ) { - wp_send_json( $cache_data ); - } - } - /** * Custom WP_Query. * @@ -702,7 +707,6 @@ public function alm_query_posts() { 'meta' => [ 'postcount' => $alm_post_count, 'totalposts' => $alm_found_posts, - 'type' => 'standard', 'debug' => $debug, ], ]; @@ -720,7 +724,6 @@ public function alm_query_posts() { 'meta' => [ 'postcount' => 0, 'totalposts' => 0, - 'type' => 'standard', 'debug' => $debug, ], ]; diff --git a/core/dist/js/ajax-load-more.js b/core/dist/js/ajax-load-more.js index f8b95ee..3e87100 100644 --- a/core/dist/js/ajax-load-more.js +++ b/core/dist/js/ajax-load-more.js @@ -100,170 +100,186 @@ var ajaxloadmore = Object.defineProperty(exports, "__esModule", { value: true }); -exports.getCacheSlug = getCacheSlug; -exports.createCacheFile = createCacheFile; -exports.wooCache = wooCache; -exports.getCacheUrl = getCacheUrl; +exports.getCache = exports.createCache = undefined; -var _axios = __webpack_require__(/*! axios */ "./node_modules/axios/index.js"); +/** + * Create a cache file. + * + * @param {object} alm The ALM object. + * @param {string} data Content to cache. + * @param {string} name The cache slug + * @since 5.3.1 + */ +var createCache = exports.createCache = function () { + var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(alm, data, name) { + var _data$html, html, _data$meta, meta, params, res; + + return regeneratorRuntime.wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + _data$html = data.html, html = _data$html === undefined ? '' : _data$html, _data$meta = data.meta, meta = _data$meta === undefined ? {} : _data$meta; + + if (!(!html || !alm.addons.cache)) { + _context.next = 3; + break; + } -var _axios2 = _interopRequireDefault(_axios); + return _context.abrupt('return'); -var _filters = __webpack_require__(/*! ../addons/filters */ "./core/src/js/addons/filters.js"); + case 3: + params = { + cache_id: alm.addons.cache_id, + cache_logged_in: alm.addons.cache_logged_in, + canonical_url: alm.canonical_url, + name: name, + html: html.trim(), + postcount: meta.postcount, + totalposts: meta.totalposts + }; -var _md = __webpack_require__(/*! crypto-js/md5 */ "./node_modules/crypto-js/md5.js"); + // Create the cache file via REST API. -var _md2 = _interopRequireDefault(_md); + _context.next = 6; + return _api.api.post('ajax-load-more/cache/create', params); -function _interopRequireDefault(obj) { - return obj && obj.__esModule ? obj : { default: obj }; -} + case 6: + res = _context.sent; -/** - * Create unique cache slug from query params. - * - * @param {object} alm The ALM object. - * @param {object} data The data object. - * @return {object} Modified data object. - */ -function getCacheSlug(alm, data) { - if (alm.addons.nextpage) { - return 'page-' + (alm.page + alm.addons.nextpage_startpage); - } else { - return (0, _md2.default)(JSON.stringify(data)).toString(); - } -} + if (res.status === 200 && res.data && res.data.success) { + console.log(res.data.msg); + } -/** - * Create a single post cache file. - * - * @param {object} alm The ALM object. - * @param {string} content The content to cache. - * @param {string} type The type of cache to create. - * @since 5.3.1 - */ -function createCacheFile(alm, content) { - var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'standard'; + case 8: + case 'end': + return _context.stop(); + } + } + }, _callee, this); + })); - if (alm.addons.cache !== 'true' || !content || content === '') { - return false; - } - var name = type === 'single' ? alm.addons.single_post_id : 'page-' + (alm.page + 1); - - var formData = new FormData(); - formData.append('action', 'alm_cache_from_html'); - formData.append('security', alm_localize.alm_nonce); - formData.append('cache_id', alm.addons.cache_id); - formData.append('cache_logged_in', alm.addons.cache_logged_in); - formData.append('canonical_url', alm.canonical_url); - formData.append('name', name); - formData.append('html', content.trim()); - - _axios2.default.post(alm_localize.ajaxurl, formData).then(function () { - console.log('Cache created for: ' + alm.canonical_url); - }); -} + return function createCache(_x, _x2, _x3) { + return _ref.apply(this, arguments); + }; +}(); /** - * Create a WooCommerce cache file. + * Get cache data file. * - * @param {object} alm The ALM object. - * @param {string} content The content to cache. - * @since 5.3.1 + * @param {object} alm The ALM object. + * @param {object} params Query params. + * @return {Promise\boolean} Cache data or false. */ -function wooCache(alm, content) { - if (alm.addons.cache !== 'true' || !content || content === '') { - return false; - } - var formData = new FormData(); - formData.append('action', 'alm_cache_from_html'); - formData.append('security', alm_localize.alm_nonce); - formData.append('cache_id', alm.addons.cache_id); - formData.append('cache_logged_in', alm.addons.cache_logged_in); - formData.append('canonical_url', alm.canonical_url); - formData.append('name', 'page-' + alm.page); - formData.append('html', content.trim()); - - _axios2.default.post(alm_localize.ajaxurl, formData).then(function () { - console.log('Cache created for post: ' + alm.canonical_url); - }); -} +var getCache = exports.getCache = function () { + var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(alm, params) { + var restParams, res; + return regeneratorRuntime.wrap(function _callee2$(_context2) { + while (1) { + switch (_context2.prev = _context2.next) { + case 0: + if (!(!alm.addons.cache || alm.addons.cache && alm.addons.cache_logged_in)) { + _context2.next = 2; + break; + } -/** - * Generate the cache page URL for GET request - * - * @param {object} alm The ALM object. - * @since 5.0 - * @supports Standard, SEO, Filters, Nextpage, Single Posts - */ -function getCacheUrl(alm) { - if (!alm) { - return false; - } + return _context2.abrupt('return', false); - var firstpage = '1'; - var cache_url = ''; - var ext = '.html'; - var path = alm.addons.cache_path + alm.addons.cache_id; + case 2: + restParams = { + id: alm.addons.cache_id, + name: params.cache_slug + }; + _context2.next = 5; + return _api.api.get('ajax-load-more/cache/get', { params: restParams }); - // SEO Add-on - if (alm.init && alm.addons.seo && alm.isPaged) { - // If request is a paged URL (e.g. /page/3/) - cache_url = path + '/page-' + firstpage + '-' + alm.start_page + ext; - } + case 5: + res = _context2.sent; + + if (!(res.status === 200 && res.data)) { + _context2.next = 10; + break; + } - // Filters - else if (alm.addons.filters) { - var filtersPath = (0, _filters.parseQuerystring)(path); + return _context2.abrupt('return', res.data); - if (alm.init && alm.isPaged) { - // First run & Paged - cache_url = filtersPath + '/page-' + firstpage + '-' + alm.addons.filters_startpage + ext; - } else { - var page = alm.page + 1; + case 10: + return _context2.abrupt('return', false); - if (alm.addons.preloaded === 'true') { - // Preloaded + Filters - page = alm.page + 2; + case 11: + case 'end': + return _context2.stop(); } - cache_url = filtersPath + '/page-' + page + ext; } - } + }, _callee2, this); + })); - // Nextpage - else if (alm.addons.nextpage) { - var nextpage_cache_url = void 0; - if (alm.addons.paging) { - nextpage_cache_url = parseInt(alm.page) + 1; - } else { - nextpage_cache_url = parseInt(alm.page) + 2; - if (alm.isPaged) { - // If the request a paged URL (/page/3/) - nextpage_cache_url = parseInt(alm.page) + parseInt(alm.addons.nextpage_startpage) + 1; - } - } + return function getCache(_x4, _x5) { + return _ref2.apply(this, arguments); + }; +}(); - cache_url = path + '/page-' + nextpage_cache_url + ext; - } +exports.getCacheSlug = getCacheSlug; - // Single Post - else if (alm.addons.single_post) { - cache_url = path + '/' + alm.addons.single_post_id + ext; - } +var _md = __webpack_require__(/*! crypto-js/md5 */ "./node_modules/crypto-js/md5.js"); - // Comments & Preloaded - else if (alm.addons.comments === 'true' && alm.addons.preloaded === 'true') { - // When using comments we need to increase the current page by 2 - cache_url = path + '/page-' + (alm.page + 2) + ext; - } +var _md2 = _interopRequireDefault(_md); - // Standard URL request - else { - cache_url = path + '/page-' + (alm.page + 1) + ext; - } +var _api = __webpack_require__(/*! ../helpers/api */ "./core/src/js/helpers/api.js"); - return cache_url; +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} + +function _asyncToGenerator(fn) { + return function () { + var gen = fn.apply(this, arguments);return new Promise(function (resolve, reject) { + function step(key, arg) { + try { + var info = gen[key](arg);var value = info.value; + } catch (error) { + reject(error);return; + }if (info.done) { + resolve(value); + } else { + return Promise.resolve(value).then(function (value) { + step("next", value); + }, function (err) { + step("throw", err); + }); + } + }return step("next"); + }); + }; +} + +/** + * Create unique cache slug from query params. + * + * @param {object} alm The ALM object. + * @param {object} data The data object. + * @return {string} The cache file slug. + */ +function getCacheSlug(alm, data) { + var addons = alm.addons, + pagePrev = alm.pagePrev, + page = alm.page, + _alm$rel = alm.rel, + rel = _alm$rel === undefined ? 'next' : _alm$rel; + + if (addons.nextpage) { + // Nextpage. + return 'page-' + (page + addons.nextpage_startpage); + } else if (addons.single_post) { + // Single Post. + return addons.single_post_id; + } else if (addons.woocommerce || addons.elementor) { + // WooCommerce || Elementor. + return rel === 'prev' ? 'page-' + pagePrev : 'page-' + (page + 1); + } else { + // Standard. + return (0, _md2.default)(JSON.stringify(data)).toString(); + } } /***/ }), @@ -282,9 +298,9 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.elementorInit = elementorInit; +exports.elementorGetContent = elementorGetContent; exports.elementor = elementor; exports.elementorLoaded = elementorLoaded; -exports.elementorGetContent = elementorGetContent; exports.elementorCreateParams = elementorCreateParams; var _getButtonURL = __webpack_require__(/*! ../helpers/getButtonURL */ "./core/src/js/helpers/getButtonURL.js"); @@ -295,6 +311,8 @@ var _loadItems = __webpack_require__(/*! ../modules/loadItems */ "./core/src/js/ var _loadItems2 = _interopRequireDefault(_loadItems); +var _cache = __webpack_require__(/*! ./cache */ "./core/src/js/addons/cache.js"); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } @@ -327,7 +345,6 @@ function _asyncToGenerator(fn) { * @param {object} alm * @since 5.3.0 */ - function elementorInit(alm) { if (!alm.addons.elementor || !alm.addons.elementor_type || !alm.addons.elementor_type === 'posts') { return false; @@ -339,13 +356,12 @@ function elementorInit(alm) { alm.button.dataset.page = alm.addons.elementor_paged; // Set button URL - var nextPage = alm.addons.elementor_next_page_url; + var nextPage = alm.addons.elementor_next_page; alm.button.dataset.url = nextPage ? nextPage : ''; // Set a11y attributes target.setAttribute('aria-live', 'polite'); target.setAttribute('aria-atomic', 'true'); - alm.listing.removeAttribute('aria-live'); alm.listing.removeAttribute('aria-atomic'); @@ -358,11 +374,6 @@ function elementorInit(alm) { item.dataset.pageTitle = document.title; } - if (alm.addons.elementor_paged > 1) {} - // maybe soon - //almElementorResultsTextInit(alm); - - // Masonry Window Resize. Delay for masonry to be added via Elementor. if (alm.addons.elementor_masonry) { var resizeTimeout = void 0; @@ -378,48 +389,109 @@ function elementorInit(alm) { } } +/** + * Get the content, title and results text from the Ajax response. + * + * @param {object} alm The alm object. + * @param {string} url The request URL. + * @param {object} response Query response. + * @param {string} cache_slug The cache slug. + * @return {object} Results data. + * @since 5.4.0 + */ +function elementorGetContent(alm, url, response, cache_slug) { + // Default data object. + var data = { + html: '', + meta: { + postcount: 0, + totalposts: 0 + } + }; + + // Successful response. + if (response.status === 200 && response.data) { + var addons = alm.addons; + + // Create temp div to hold response data. + + var div = document.createElement('div'); + div.innerHTML = response.data; + + // Get Page Title + var title = div.querySelector('title').innerHTML; + data.pageTitle = title; + + // Get Elementor Items container. + var container = div.querySelector(addons.elementor_target + ' .' + addons.elementor_container_class); + if (!container) { + console.warn('Ajax Load More Elementor: Unable to find Elementor container element.'); + return data; + } + + // Get the first item and append data attributes. + var item = container ? container.querySelector('.' + addons.elementor_item_class) : null; + if (item) { + item.classList.add('alm-elementor'); + item.dataset.url = url; + item.dataset.page = addons.elementor_paged; + item.dataset.pageTitle = title; + } + + // Count the number of returned items. + var items = container.querySelectorAll('.' + addons.elementor_item_class); + if (items) { + // Set the html to the elementor container data. + data.html = container ? container.innerHTML : ''; + data.meta.postcount = items.length; + data.meta.totalposts = items.length; + + // Create cache file. + (0, _cache.createCache)(alm, data, cache_slug); + } + } + return data; +} + /** * Core ALM Elementor loader. * - * @param {HTMLElement} content - * @param {object} alm - * @param {string} pageTitle + * @param {HTMLElement} content The HTML data. + * @param {object} alm The alm object. * @since 5.3.0 */ function elementor(content, alm) { - var pageTitle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : document.title; - if (!content || !alm) { + alm.AjaxLoadMore.triggerDone(); return false; } return new Promise(function (resolve) { - var container = alm.addons.elementor_element.querySelector('.' + alm.addons.elementor_container_class); // Get post container - var items = content.querySelectorAll('.' + alm.addons.elementor_item_class); // Get all items in container - var url = alm.addons.elementor_current_url; // Current Page URL + var addons = alm.addons; + + var container = alm.addons.elementor_element.querySelector('.' + addons.elementor_container_class); // Get post container + var items = content.querySelectorAll('.' + addons.elementor_item_class); // Get all items in container - if (container && items && url) { - // Convert NodeList to Array - items = Array.prototype.slice.call(items); + if (container && items) { + var ElementorItems = Array.prototype.slice.call(items); // Convert NodeList to Array // Trigger almElementorLoaded callback. if (typeof almElementorLoaded === 'function') { - window.almElementorLoaded(items); + window.almElementorLoaded(ElementorItems); } - // Load the items _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; - return (0, _loadItems2.default)(container, items, alm, pageTitle, url, 'alm-elementor'); + return (0, _loadItems2.default)(container, ElementorItems, alm); case 2: - if (alm.addons.elementor_masonry) { + if (addons.elementor_masonry) { setTimeout(function () { - positionMasonryItems(alm, '.' + alm.addons.elementor_container_class, '.' + alm.addons.elementor_item_class); + positionMasonryItems(alm, '.' + addons.elementor_container_class, '.' + addons.elementor_item_class); }, 125); } @@ -441,17 +513,31 @@ function elementor(content, alm) { } /** - * Handle Elementor loaded functionality and dispatch actions. + * Elementor loaded and dispatch actions. * - * @param {object} alm + * @param {object} alm The alm object. * @since 5.5.0 */ function elementorLoaded(alm) { - var nextPageNum = alm.page + 1; - var nextPage = alm.addons.elementor_next_page_url; // Get URL. + var _alm_localize = alm_localize, + trailing_slash = _alm_localize.trailing_slash, + is_front_page = _alm_localize.is_front_page; + var page = alm.page, + button = alm.button, + canonical_url = alm.canonical_url, + AjaxLoadMore = alm.AjaxLoadMore, + addons = alm.addons; + + var nextPage = page + 1; + + var sep = is_front_page === 'true' ? 'page/' : trailing_slash === 'true' ? '' : '/'; + var slash = trailing_slash === 'true' ? '/' : ''; + var url = '' + (canonical_url + sep) + (nextPage + 1) + slash; + + var max_pages = addons.elementor_max_pages; // Set button data attributes. - (0, _getButtonURL.setButtonAtts)(alm.button, nextPageNum, nextPage); + (0, _getButtonURL.setButtonAtts)(button, nextPage, url); // Lazy load images if necessary. (0, _lazyImages.lazyImages)(alm); @@ -462,55 +548,16 @@ function elementorLoaded(alm) { } // End transitions. - alm.AjaxLoadMore.transitionEnd(); - - // ALM Done - if (!nextPage) { - alm.AjaxLoadMore.triggerDone(); - } -} - -/** - * Get the content, title and results text from the Ajax response. - * - * @param {*} response - * @param {object} alm - * @since 5.4.0 - */ -function elementorGetContent(response, alm) { - var data = { - html: '', - meta: { - postcount: 1, - totalposts: alm.localize.total_posts, - debug: false - } - }; - if (response.status === 200 && response.data) { - var div = document.createElement('div'); - div.innerHTML = response.data; - - // Get Page Title - var title = div.querySelector('title').innerHTML; - data.pageTitle = title; - - // Get Elementor Items HTML - var items = div.querySelector(alm.addons.elementor_target + ' .' + alm.addons.elementor_container_class); - data.html = items ? items.innerHTML : ''; + AjaxLoadMore.transitionEnd(); - // Set Page URL Params - alm.addons.elementor_current_url = alm.addons.elementor_next_page_url; // Set current to previous page URL - alm.addons.elementor_next_page_url = elementorGetNextPage(div, alm.addons.elementor_pagination_class); - - // Results Text - //almElementorResultsText(div, alm); + // ALM Done. + if (nextPage >= max_pages) { + AjaxLoadMore.triggerDone(); } - - return data; } /** - * Create Elementor Params for ALM. + * Create Elementor params for ALM. * * @param {object} alm The alm object. * @return {object} The modified object. @@ -536,9 +583,13 @@ function elementorCreateParams(alm) { alm.addons.elementor_controls = alm.addons.elementor_controls === 'true' ? true : false; alm.addons.elementor_scrolltop = parseInt(alm.addons.elementor_settings.scrolltop); - // Set Page & URL params - alm.addons.elementor_current_url = window.location.href; - alm.addons.elementor_next_page_url = elementorGetNextUrl(alm.addons.elementor_pagination); + // Get next page URL. + alm.addons.elementor_next_page = elementorGetNextUrl(alm.addons.elementor_pagination); + + // Get the max pages. + alm.addons.elementor_max_pages = alm.addons.elementor_element.querySelector('.e-load-more-anchor'); + alm.addons.elementor_max_pages = alm.addons.elementor_max_pages ? parseInt(alm.addons.elementor_max_pages.dataset.maxPage) : 999; + alm.addons.elementor_paged = alm.addons.elementor_settings.paged ? parseInt(alm.addons.elementor_settings.paged) : 1; alm.page = parseInt(alm.page) + alm.addons.elementor_paged; @@ -1080,32 +1131,42 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.singlePostHTML = singlePostHTML; + +var _cache = __webpack_require__(/*! ./cache */ "./core/src/js/addons/cache.js"); + /** * Create the HTML for loading Single Posts. * - * @param {Object} response Query response - * @param {HTMLElement} target The target div + * @param {object} alm The alm object. + * @param {object} response Query response. + * @param {string} cache_slug The cache slug. + * @return {object} Results data. * @since 5.1.8.1 */ -function singlePostHTML(response) { - var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; - +function singlePostHTML(alm, response, cache_slug) { var data = { html: '', meta: { - postcount: 1, - totalposts: 1, - debug: 'Single Posts Query' + postcount: 0, + totalposts: 0 } }; - if (response.status === 200 && response.data && target) { - // Create temp div to hold Ajax response data. + // Get target element. + var single_post_target = alm.addons.single_post_target; + + if (response.status === 200 && response.data && single_post_target) { + // Create temp div to hold response data. var div = document.createElement('div'); div.innerHTML = response.data; // Get target element. - var html = div.querySelector(target); + var html = div.querySelector(single_post_target); + + if (!html) { + console.warn('Ajax Load More: Unable to find ' + single_post_target + ' element.'); + return data; + } // Get any custom target elements. var customElements = window && window.almSinglePostsCustomElements; @@ -1113,11 +1174,14 @@ function singlePostHTML(response) { html.appendChild(singlePostsGetCustomElements(div, customElements)); } - if (html) { - data.html = html.innerHTML; - } else { - console.warn('Ajax Load More: Unable to find ' + target + ' element.'); - } + data.html = html.innerHTML; + data.meta = { + postcount: 1, + totalposts: 1 + }; + + // Create cache file. + (0, _cache.createCache)(alm, data, cache_slug); } return data; } @@ -1131,7 +1195,7 @@ exports.default = singlePostHTML; * * e.g. window.almSinglePostsCustomElements = ['#woocommerce-inline-inline-css', '#wc-block-style-css']; * - * @param {object} content The HTML element. + * @param {object} content The HTML element. * @param {array|string} customElements The elements to search for in content. * @return {object} HTML elements. */ @@ -1180,9 +1244,9 @@ Object.defineProperty(exports, "__esModule", { }); exports.wooInit = wooInit; exports.woocommerce = woocommerce; +exports.wooGetContent = wooGetContent; exports.woocommerceLoaded = woocommerceLoaded; exports.wooReset = wooReset; -exports.wooGetContent = wooGetContent; var _axios = __webpack_require__(/*! axios */ "./node_modules/axios/index.js"); @@ -1202,6 +1266,8 @@ var _loadItems2 = _interopRequireDefault(_loadItems); var _loadPrevious = __webpack_require__(/*! ../modules/loadPrevious */ "./core/src/js/modules/loadPrevious.js"); +var _cache = __webpack_require__(/*! ./cache */ "./core/src/js/addons/cache.js"); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } @@ -1294,37 +1360,33 @@ function wooInit(alm) { * * @param {Element} content WooCommerce content container. * @param {object} alm ALM object. - * @param {string} pageTitle Page title. * @since 5.3.0 */ function woocommerce(content, alm) { - var pageTitle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : document.title; - if (!content || !alm) { return false; } return new Promise(function (resolve) { - var container = document.querySelector(alm.addons.woocommerce_settings.container); // Get `ul.products` - var products = content.querySelectorAll(alm.addons.woocommerce_settings.products); // Get all `.products` - var page = alm.rel === 'prev' ? alm.pagePrev - 1 : alm.page; - var url = alm.addons.woocommerce_settings.paged_urls[page]; - var _alm$addons$woocommer = alm.addons.woocommerce_settings.settings, - settings = _alm$addons$woocommer === undefined ? {} : _alm$addons$woocommer; + var _alm$addons$woocommer = alm.addons.woocommerce_settings, + woocommerce_settings = _alm$addons$woocommer === undefined ? {} : _alm$addons$woocommer; + var _woocommerce_settings = woocommerce_settings.settings, + settings = _woocommerce_settings === undefined ? {} : _woocommerce_settings; + var container = document.querySelector(woocommerce_settings.container); // Get `ul.products` + var products = content.querySelectorAll(woocommerce_settings.products); // Get all `.products` var waitForImages = settings && settings.images_loaded === 'true' ? true : false; - if (container && products && url) { + if (container && products) { var wooProducts = Array.prototype.slice.call(products); // Convert NodeList to Array. - // Load the Products _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; - return (0, _loadItems2.default)(container, wooProducts, alm, pageTitle, url, 'alm-woocommerce', waitForImages); + return (0, _loadItems2.default)(container, wooProducts, alm, waitForImages); case 2: resolve(true); @@ -1347,6 +1409,83 @@ function woocommerce(content, alm) { }); } +/** + * Get the content, title and results from the Ajax request. + * + * @param {object} alm The alm object. + * @param {string} url The request URL. + * @param {object} response Query response. + * @param {string} cache_slug The cache slug. + * @return {object} Results data. + * @since 5.3.0 + */ +function wooGetContent(alm, url, response, cache_slug) { + // Default data object. + var data = { + html: '', + meta: { + postcount: 0, + totalposts: 0 + } + }; + + // Successful response. + if (response.status === 200 && response.data) { + var addons = alm.addons, + pagePrev = alm.pagePrev, + _alm$rel = alm.rel, + rel = _alm$rel === undefined ? 'next' : _alm$rel, + page = alm.page, + localize = alm.localize; + var total_posts = localize.total_posts; + var _addons$woocommerce_s = addons.woocommerce_settings, + woocommerce_settings = _addons$woocommerce_s === undefined ? {} : _addons$woocommerce_s; + + var currentPage = rel === 'prev' ? pagePrev : page + 1; // Get the page number. + + // Create temp div to hold response data. + var div = document.createElement('div'); + div.innerHTML = response.data; + + // Get Page Title + var title = div.querySelector('title').innerHTML; + data.pageTitle = title; + + // Get WooCommerce products container. + var container = div.querySelector(woocommerce_settings.container); + if (!container) { + console.warn('Ajax Load More WooCommerce: Unable to find WooCommerce ' + woocommerce_settings.container + ' element.'); + return data; + } + + // Get the first item and append data attributes. + var item = container ? container.querySelector(woocommerce_settings.products) : null; + if (item) { + item.classList.add('alm-woocommerce'); + item.dataset.url = url; + item.dataset.page = currentPage; + item.dataset.pageTitle = title; + } + + // Count the number of returned items. + var items = container.querySelectorAll(woocommerce_settings.products); + if (items) { + // Set the html to the elementor container data. + data.html = container ? container.innerHTML : ''; + data.meta.postcount = items.length; + data.meta.totalposts = total_posts; + + // Create cache file. + (0, _cache.createCache)(alm, data, cache_slug); + } + + // Results Text + almWooCommerceResultsText(div, alm); + } + + return data; +} + /** * Handle WooCommerce loaded functionality and dispatch actions. * @@ -1406,46 +1545,12 @@ function wooReset() { } else { resolve(false); } - }).catch(function (error) { + }).catch(function () { resolve(false); }); }); } -/** - * Get the content, title and results text from the Ajax response - * - * @param {object} alm ALM object. - * @since 5.3.0 - */ -function wooGetContent(response, alm) { - var data = { - html: '', - meta: { - postcount: 1, - totalposts: alm.localize.total_posts, - debug: false - } - }; - if (response.status === 200 && response.data) { - var div = document.createElement('div'); - div.innerHTML = response.data; - - // Get Page Title - var title = div.querySelector('title').innerHTML; - data.pageTitle = title; - - // Get Products HTML - var products = div.querySelector(alm.addons.woocommerce_settings.container); - data.html = products ? products.innerHTML : ''; - - // Results Text - almWooCommerceResultsText(div, alm); - } - - return data; -} - /** * Set results text for WooCommerce Add-on. * @@ -1549,7 +1654,9 @@ Object.defineProperty(exports, "__esModule", { }); exports.click = exports.render = exports.getOffset = exports.almScroll = exports.start = exports.tab = exports.tracking = exports.getTotalRemaining = exports.getTotalPosts = exports.getPostCount = exports.reset = exports.filter = undefined; -__webpack_require__(/*! ./helpers/helpers */ "./core/src/js/helpers/helpers.js"); +var _axios = __webpack_require__(/*! axios */ "./node_modules/axios/index.js"); + +var _axios2 = _interopRequireDefault(_axios); var _cache = __webpack_require__(/*! ./addons/cache */ "./core/src/js/addons/cache.js"); @@ -1571,6 +1678,8 @@ var _almDomParser = __webpack_require__(/*! ./helpers/almDomParser */ "./core/sr var _almDomParser2 = _interopRequireDefault(_almDomParser); +var _getButtonURL = __webpack_require__(/*! ./helpers/getButtonURL */ "./core/src/js/helpers/getButtonURL.js"); + var _getParameterByName = __webpack_require__(/*! ./helpers/getParameterByName */ "./core/src/js/helpers/getParameterByName.js"); var _getParameterByName2 = _interopRequireDefault(_getParameterByName); @@ -1579,9 +1688,13 @@ var _getScrollPercentage = __webpack_require__(/*! ./helpers/getScrollPercentage var _getScrollPercentage2 = _interopRequireDefault(_getScrollPercentage); -var _queryParams = __webpack_require__(/*! ./helpers/queryParams */ "./core/src/js/helpers/queryParams.js"); +var _getTotals = __webpack_require__(/*! ./helpers/getTotals */ "./core/src/js/helpers/getTotals.js"); + +var _getTotals2 = _interopRequireDefault(_getTotals); + +__webpack_require__(/*! ./helpers/helpers */ "./core/src/js/helpers/helpers.js"); -var queryParams = _interopRequireWildcard(_queryParams); +var _queryParams = __webpack_require__(/*! ./helpers/queryParams */ "./core/src/js/helpers/queryParams.js"); var _srcsetPolyfill = __webpack_require__(/*! ./helpers/srcsetPolyfill */ "./core/src/js/helpers/srcsetPolyfill.js"); @@ -1611,8 +1724,6 @@ var _filtering = __webpack_require__(/*! ./modules/filtering */ "./core/src/js/m var _filtering2 = _interopRequireDefault(_filtering); -var _getButtonURL = __webpack_require__(/*! ./helpers/getButtonURL */ "./core/src/js/helpers/getButtonURL.js"); - var _insertScript = __webpack_require__(/*! ./modules/insertScript */ "./core/src/js/modules/insertScript.js"); var _insertScript2 = _interopRequireDefault(_insertScript); @@ -1641,14 +1752,6 @@ var _setLocalizedVars2 = _interopRequireDefault(_setLocalizedVars); var _tableofcontents = __webpack_require__(/*! ./modules/tableofcontents */ "./core/src/js/modules/tableofcontents.js"); -var _getTotals = __webpack_require__(/*! ./helpers/getTotals */ "./core/src/js/helpers/getTotals.js"); - -var _getTotals2 = _interopRequireDefault(_getTotals); - -var _axios = __webpack_require__(/*! axios */ "./node_modules/axios/index.js"); - -var _axios2 = _interopRequireDefault(_axios); - function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; @@ -1697,14 +1800,26 @@ function _asyncToGenerator(fn) { }; } // ALM Modules -//import commentReplyFix from './helpers/commentReplyFix'; - // External Modules var qs = __webpack_require__(/*! qs */ "./node_modules/qs/lib/index.js"); var imagesLoaded = __webpack_require__(/*! imagesloaded */ "./node_modules/imagesloaded/imagesloaded.js"); + +// Axios Config. _axios2.default.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; +// Axios Interceptor for nested data objects +_axios2.default.interceptors.request.use(function (config) { + config.paramsSerializer = function (params) { + // Qs is already included in the Axios package + return qs.stringify(params, { + arrayFormat: 'brackets', + encode: false + }); + }; + return config; +}); + // Polyfills __webpack_require__(/*! @babel/polyfill/noConflict */ "./node_modules/@babel/polyfill/noConflict.js"); __webpack_require__(/*! focus-options-polyfill */ "./node_modules/focus-options-polyfill/index.js"); @@ -1844,9 +1959,8 @@ var alm_is_filtering = false; } // Cache add-on - alm.addons.cache = alm.listing.dataset.cache; - alm.addons.cache = alm.addons.cache === undefined ? false : alm.addons.cache; - if (alm.addons.cache === 'true') { + alm.addons.cache = alm.listing.dataset.cache && alm.listing.dataset.cache === 'true' ? true : false; + if (alm.addons.cache) { alm.addons.cache_id = alm.listing.dataset.cacheId; alm.addons.cache_path = alm.listing.dataset.cachePath; alm.addons.cache_logged_in = alm.listing.dataset.cacheLoggedIn ? alm.listing.dataset.cacheLoggedIn : false; @@ -1883,6 +1997,7 @@ var alm_is_filtering = false; alm.addons.single_post_progress_bar = alm.listing.dataset.singlePostProgressBar === undefined ? '' : alm.listing.dataset.singlePostProgressBar; alm.addons.single_post_target = alm.listing.dataset.singlePostTarget === undefined ? '' : alm.listing.dataset.singlePostTarget; alm.addons.single_post_preview = alm.listing.dataset.singlePostPreview === undefined ? false : true; + if (alm.addons.single_post_preview) { var singlePostPreviewData = alm.listing.dataset.singlePostPreview.split(':'); alm.addons.single_post_preview_data = { @@ -1906,7 +2021,6 @@ var alm_is_filtering = false; alm.addons.comments_callback = alm.listing.dataset.comments_callback; } - alm.addons.tabs = alm.listing.dataset.tabs; alm.addons.filters = alm.listing.dataset.filters; alm.addons.seo = alm.listing.dataset.seo; alm.addons.seo_offset = alm.listing.dataset.seoOffset; @@ -2012,30 +2126,6 @@ var alm_is_filtering = false; alm.addons.filters = false; } - // Tabs. - if (alm.addons.tabs === 'true') { - alm.addons.tabs = true; - alm.addons.tab_template = alm.listing.dataset.tabTemplate ? alm.listing.dataset.tabTemplate : ''; - alm.addons.tab_onload = alm.listing.dataset.tabOnload ? alm.listing.dataset.tabOnload : ''; - alm.addons.tabs_resturl = alm.listing.dataset.tabsRestUrl ? alm.listing.dataset.tabsRestUrl : ''; - - // Locate active template (deeplinks) - if (alm.addons.tab_onload !== '') { - var tabNav = document.querySelector('.alm-tab-nav li [data-tab-url=' + alm.addons.tab_onload + ']'); - alm.addons.tab_template = tabNav ? tabNav.dataset.tabTemplate : alm.addons.tab_template; - alm.listing.dataset.tabOnload = ''; // Clear tabOnload param - // Set selected tab - if (tabNav) { - var activeTab = document.querySelector('.alm-tab-nav li .active'); - if (activeTab) { - activeTab.classList.remove('active'); - } - } - } - } else { - alm.addons.tabs = false; - } - /* REST API */ if (alm.extensions.restapi) { alm.extensions.restapi_debug = alm.extensions.restapi_debug === undefined ? false : alm.extensions.restapi_debug; @@ -2124,6 +2214,7 @@ var alm_is_filtering = false; alm.addons.single_post_permalink = ''; alm.addons.single_post_title = ''; alm.addons.single_post_slug = ''; + alm.addons.single_post_cache = false; alm.addons.single_post_title_template = alm.listing.dataset.singlePostTitleTemplate; alm.addons.single_post_siteTitle = alm.listing.dataset.singlePostSiteTitle; alm.addons.single_post_siteTagline = alm.listing.dataset.singlePostSiteTagline; @@ -2282,10 +2373,9 @@ var alm_is_filtering = false; window.almOnChange(alm); } + // Set loading attributes. alm.loading = true; (0, _placeholder.showPlaceholder)(alm); - - // Add `.alm-loading` class to container. alm.main.classList.add('alm-loading'); // Add loading styles to buttons. @@ -2300,7 +2390,7 @@ var alm_is_filtering = false; } } - // Standard ALM query + // Dispatch Ajax query. alm.AjaxLoadMore.ajax(); }; @@ -2310,260 +2400,238 @@ var alm_is_filtering = false; * @param {string} queryType The type of Ajax request (standard/totalposts). * @since 2.6.0 */ - alm.AjaxLoadMore.ajax = function () { + alm.AjaxLoadMore.ajax = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { var queryType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'standard'; + var action, params, cache; + return regeneratorRuntime.wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + action = 'alm_get_posts'; // Default action - // Default ALM action - var action = 'alm_get_posts'; + // ACF Params - // ACF Params - alm.acf_array = ''; - if (alm.extensions.acf) { - // Custom query for the Repeater / Gallery / Flexible Content field types - if (alm.extensions.acf_field_type !== 'relationship') { - action = 'alm_acf'; - } - alm.acf_array = { - acf: 'true', - post_id: alm.extensions.acf_post_id, - field_type: alm.extensions.acf_field_type, - field_name: alm.extensions.acf_field_name, - parent_field_name: alm.extensions.acf_parent_field_name - }; - } + alm.acf_array = ''; + if (alm.extensions.acf) { + // Custom query for the Repeater / Gallery / Flexible Content field types + if (alm.extensions.acf_field_type !== 'relationship') { + action = 'alm_acf'; + } + alm.acf_array = { + acf: 'true', + post_id: alm.extensions.acf_post_id, + field_type: alm.extensions.acf_field_type, + field_name: alm.extensions.acf_field_name, + parent_field_name: alm.extensions.acf_parent_field_name + }; + } - // Term Query Params - alm.term_query_array = ''; - if (alm.extensions.term_query) { - action = 'alm_get_terms'; - alm.term_query_array = { - term_query: 'true', - taxonomy: alm.extensions.term_query_taxonomy, - hide_empty: alm.extensions.term_query_hide_empty, - number: alm.extensions.term_query_number - }; - } + // Term Query Params + alm.term_query_array = ''; + if (alm.extensions.term_query) { + action = 'alm_get_terms'; + alm.term_query_array = { + term_query: 'true', + taxonomy: alm.extensions.term_query_taxonomy, + hide_empty: alm.extensions.term_query_hide_empty, + number: alm.extensions.term_query_number + }; + } - // Nextpage Params - alm.nextpage_array = ''; - if (alm.addons.nextpage) { - action = 'alm_nextpage'; - alm.nextpage_array = { - nextpage: 'true', - urls: alm.addons.nextpage_urls, - scroll: alm.addons.nextpage_scroll, - pageviews: alm.addons.nextpage_pageviews, - post_id: alm.addons.nextpage_post_id, - startpage: alm.addons.nextpage_startpage, - nested: alm.nested - }; - } + // Nextpage Params + alm.nextpage_array = ''; + if (alm.addons.nextpage) { + action = 'alm_nextpage'; + alm.nextpage_array = { + nextpage: 'true', + urls: alm.addons.nextpage_urls, + scroll: alm.addons.nextpage_scroll, + pageviews: alm.addons.nextpage_pageviews, + post_id: alm.addons.nextpage_post_id, + startpage: alm.addons.nextpage_startpage, + nested: alm.nested + }; + } - // Previous Post Params - alm.single_post_array = ''; - if (alm.addons.single_post) { - alm.single_post_array = { - single_post: 'true', - id: alm.addons.single_post_id, - slug: alm.addons.single_post_slug - }; - } + // Previous Post Params + alm.single_post_array = ''; + if (alm.addons.single_post) { + alm.single_post_array = { + single_post: 'true', + id: alm.addons.single_post_id, + slug: alm.addons.single_post_slug + }; + } - // Comment Params - alm.comments_array = ''; - if (alm.addons.comments === 'true') { - action = 'alm_comments'; - alm.posts_per_page = alm.addons.comments_per_page; - alm.comments_array = { - comments: 'true', - post_id: alm.addons.comments_post_id, - per_page: alm.addons.comments_per_page, - type: alm.addons.comments_type, - style: alm.addons.comments_style, - template: alm.addons.comments_template, - callback: alm.addons.comments_callback - }; - } + // Comment Params + alm.comments_array = ''; + if (alm.addons.comments === 'true') { + action = 'alm_comments'; + alm.posts_per_page = alm.addons.comments_per_page; + alm.comments_array = { + comments: 'true', + post_id: alm.addons.comments_post_id, + per_page: alm.addons.comments_per_page, + type: alm.addons.comments_type, + style: alm.addons.comments_style, + template: alm.addons.comments_template, + callback: alm.addons.comments_callback + }; + } - // Users Params - alm.users_array = ''; - if (alm.addons.users) { - action = 'alm_users'; - alm.users_array = { - users: 'true', - role: alm.listing.dataset.usersRole, - include: alm.listing.dataset.usersInclude, - exclude: alm.listing.dataset.usersExclude, - per_page: alm.posts_per_page, - order: alm.listing.dataset.usersOrder, - orderby: alm.listing.dataset.usersOrderby - }; - } + // Users Params + alm.users_array = ''; + if (alm.addons.users) { + action = 'alm_users'; + alm.users_array = { + users: 'true', + role: alm.listing.dataset.usersRole, + include: alm.listing.dataset.usersInclude, + exclude: alm.listing.dataset.usersExclude, + per_page: alm.posts_per_page, + order: alm.listing.dataset.usersOrder, + orderby: alm.listing.dataset.usersOrderby + }; + } - // CTA Params - alm.cta_array = ''; - if (alm.addons.cta === 'true') { - alm.cta_array = { - cta: 'true', - cta_position: alm.addons.cta_position, - cta_repeater: alm.addons.cta_repeater, - cta_theme_repeater: alm.addons.cta_theme_repeater - }; - } + // CTA Params + alm.cta_array = ''; + if (alm.addons.cta === 'true') { + alm.cta_array = { + cta: 'true', + cta_position: alm.addons.cta_position, + cta_repeater: alm.addons.cta_repeater, + cta_theme_repeater: alm.addons.cta_theme_repeater + }; + } - // Dispatch Ajax request. - if (alm.extensions.restapi) { - // REST API - alm.AjaxLoadMore.restapi(alm); - } else if (alm.addons.tabs) { - // Tabs - alm.AjaxLoadMore.tabs(alm); - } else { - // Standard ALM - alm.AjaxLoadMore.adminajax(alm, action, queryType); - } - }; + // Dispatch Ajax request. + + if (!alm.extensions.restapi) { + _context.next = 19; + break; + } + + // Rest API. + alm.AjaxLoadMore.restapi(alm); + _context.next = 24; + break; + + case 19: + // Standard ALM. + params = (0, _queryParams.getAjaxParams)(alm, action, queryType); + _context.next = 22; + return (0, _cache.getCache)(alm, Object.assign({}, params)); + + case 22: + cache = _context.sent; + + if (cache) { + alm.AjaxLoadMore.success(cache); + } else { + alm.AjaxLoadMore.adminajax(params, queryType); + } + + case 24: + case 'end': + return _context.stop(); + } + } + }, _callee, this); + })); /** * Send request to the admin-ajax.php * - * @param {object} alm The Ajax Load More object. - * @param {string} action The Ajax action. + * @param {object} params Query params. * @param {string} queryType The type of Ajax request (standard/totalposts). * @since 5.0.0 */ - alm.AjaxLoadMore.adminajax = function (alm, action, queryType) { - // Axios Interceptor for nested data objects - _axios2.default.interceptors.request.use(function (config) { - config.paramsSerializer = function (params) { - // Qs is already included in the Axios package - return qs.stringify(params, { - arrayFormat: 'brackets', - encode: false - }); - }; - return config; - }); + alm.AjaxLoadMore.adminajax = function () { + var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(params, queryType) { + var _alm_localize, ajaxurl, _params, _params$cache_slug, cache_slug, data; - // Get Ajax URL. - var ajaxURL = alm_localize.ajaxurl; + return regeneratorRuntime.wrap(function _callee2$(_context2) { + while (1) { + switch (_context2.prev = _context2.next) { + case 0: + // Get Ajax URL. + _alm_localize = alm_localize, ajaxurl = _alm_localize.ajaxurl; - // Get query params. - var params = queryParams.getAjaxParams(alm, action, queryType); + // Deconstruct query params. - // Single Posts Add-on - // If has `single_post_target`, adjust the Ajax URL to the post URL. - if (alm.addons.single_post && alm.addons.single_post_target) { - ajaxURL = alm.addons.single_post_permalink + '?id=' + alm.addons.single_post_id + '&alm_page=' + (parseInt(alm.page) + 1); - params = ''; - } + _params = params, _params$cache_slug = _params.cache_slug, cache_slug = _params$cache_slug === undefined ? '' : _params$cache_slug; - // WooCommerce Add-on - if (alm.addons.woocommerce) { - ajaxURL = (0, _getButtonURL.getButtonURL)(alm, alm.rel); - params = ''; - } + /** + * Single Posts. + * If `single_post_target`, adjust the Ajax URL to the post URL. + */ - // Elementor Add-on - if (alm.addons.elementor && alm.addons.elementor_type && alm.addons.elementor_type === 'posts') { - ajaxURL = (0, _getButtonURL.getButtonURL)(alm, alm.rel); - params = ''; - } - - // Send HTTP request via axios - _axios2.default.get(ajaxURL, { params: params }).then(function (response) { - // Success - var data = ''; - - if (alm.addons.single_post && alm.addons.single_post_target) { - // Single Posts - data = (0, _singleposts.singlePostHTML)(response, alm.addons.single_post_target); - (0, _cache.createCacheFile)(alm, data.html, 'single'); - } else if (alm.addons.woocommerce) { - // WooCommerce - data = (0, _woocommerce.wooGetContent)(response, alm); - (0, _cache.createCacheFile)(alm, data.html, 'woocommerce'); - } else if (alm.addons.elementor) { - // Elementor - data = (0, _elementor.elementorGetContent)(response, alm); - (0, _cache.createCacheFile)(alm, data.html, 'elementor'); - } else { - // Get data from response - data = response.data; - } + if (alm.addons.single_post && alm.addons.single_post_target) { + ajaxurl = alm.addons.single_post_permalink + '?id=' + alm.addons.single_post_id + '&alm_page=' + (parseInt(alm.page) + 1); + params = ''; + } - // Standard Query - if (queryType === 'standard') { - alm.AjaxLoadMore.success(data); - } else if (queryType === 'totalpages' && alm.addons.paging && alm.addons.nextpage) { - // Next Page and Paging - if (typeof almBuildPagination === 'function') { - window.almBuildPagination(data.totalpages, alm); - alm.totalpages = data.totalpages; - } - } else if (queryType === 'totalposts' && alm.addons.paging) { - // Paging - if (typeof almBuildPagination === 'function') { - window.almBuildPagination(data.totalposts, alm); - } - } - }).catch(function (error) { - // Error - alm.AjaxLoadMore.error(error, 'adminajax'); - }); - }; + // WooCommerce || Elementor. + if (alm.addons.woocommerce || alm.addons.elementor && alm.addons.elementor_type === 'posts') { + ajaxurl = (0, _getButtonURL.getButtonURL)(alm, alm.rel); + params = ''; + } - /** - * Ajax Load More Tab functionality. - * - * @param {object} alm The Ajax Load More object. - * @since 5.2.0 - */ - alm.AjaxLoadMore.tabs = function (alm) { - var alm_rest_url = alm.addons.tabs_resturl + 'ajaxloadmore/tab'; + // Send HTTP request via axios. + _context2.next = 6; + return _axios2.default.get(ajaxurl, { params: params }).then(function (response) { + if (alm.addons.single_post && alm.addons.single_post_target) { + // Single Posts + return (0, _singleposts.singlePostHTML)(alm, response, cache_slug); + } else if (alm.addons.woocommerce) { + // WooCommerce. + return (0, _woocommerce.wooGetContent)(alm, ajaxurl, response, cache_slug); + } else if (alm.addons.elementor) { + // Elementor + return (0, _elementor.elementorGetContent)(alm, ajaxurl, response, cache_slug); + } else { + // Get data from response + return response.data; + } + }).catch(function (error) { + // Error + alm.AjaxLoadMore.error(error, 'adminajax'); + }); - var params = { - post_id: alm.post_id, - template: alm.addons.tab_template - }; + case 6: + data = _context2.sent; + _context2.t0 = queryType; + _context2.next = _context2.t0 === 'standard' ? 10 : _context2.t0 === 'totalposts' ? 12 : 14; + break; - // Axios Interceptor for nested data objects - _axios2.default.interceptors.request.use(function (config) { - config.paramsSerializer = function (params) { - // Qs is already included in the Axios package - return qs.stringify(params, { - arrayFormat: 'brackets', - encode: false - }); - }; - return config; - }); + case 10: + alm.AjaxLoadMore.success(data); + return _context2.abrupt('break', 14); - // Send Ajax request - _axios2.default.get(alm_rest_url, { params: params }).then(function (response) { - // Success - var results = response.data; // Get data from response - var html = results.html; + case 12: + if (alm.addons.paging && alm.addons.nextpage && typeof almBuildPagination === 'function') { + window.almBuildPagination(data.totalpages, alm); + alm.totalpages = data.totalpages; + } else { + if (alm.addons.paging && typeof almBuildPagination === 'function') { + window.almBuildPagination(data.totalposts, alm); + } + } + return _context2.abrupt('break', 14); - // Create object to pass to success() - var obj = { - html: html, - meta: { - postcount: 1, - totalposts: 1 + case 14: + case 'end': + return _context2.stop(); + } } - }; - alm.AjaxLoadMore.success(obj); // Send data + }, _callee2, this); + })); - // Callback to Tabs add-on - if (typeof almTabLoaded === 'function') { - window.almTabLoaded(alm); - } - }).catch(function (error) { - // Error - alm.AjaxLoadMore.error(error, 'restapi'); - }); - }; + return function (_x2, _x3) { + return _ref2.apply(this, arguments); + }; + }(); /** * Send request to the WP REST API @@ -2576,21 +2644,8 @@ var alm_is_filtering = false; alm.AjaxLoadMore.restapi = function (alm) { var alm_rest_template = wp.template(alm.extensions.restapi_template_id); var alm_rest_url = alm.extensions.restapi_base_url + '/' + alm.extensions.restapi_namespace + '/' + alm.extensions.restapi_endpoint; - var params = queryParams.getRestAPIParams(alm); // [./helpers/queryParams.js] - - // Axios Interceptor for nested data objects - _axios2.default.interceptors.request.use(function (config) { - config.paramsSerializer = function (params) { - // Qs is already included in the Axios package - return qs.stringify(params, { - arrayFormat: 'brackets', - encode: false - }); - }; - return config; - }); + var params = (0, _queryParams.getRestAPIParams)(alm); // [./helpers/queryParams.js] - // Send Ajax request _axios2.default.get(alm_rest_url, { params: params }).then(function (response) { // Success var results = response.data; // Get data from response @@ -2647,7 +2702,7 @@ var alm_is_filtering = false; var _this = this; if (alm.addons.single_post) { - alm.AjaxLoadMore.getSinglePost(); // Get previous post data + alm.AjaxLoadMore.getSinglePost(); // Get single post data for next post. } var isPaged = false; @@ -2679,9 +2734,6 @@ var alm_is_filtering = false; // Set alm.html as plain text return alm.html = html; - // If cache, get the length of the html object - // total = is_cache ? almDomParser(html).length : total; - // First Run Only if (alm.init) { // Set Meta @@ -2744,20 +2796,20 @@ var alm_is_filtering = false; /** * Set localized variables and Results Text. */ - _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { - return regeneratorRuntime.wrap(function _callee$(_context) { + _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() { + return regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { - switch (_context.prev = _context.next) { + switch (_context3.prev = _context3.next) { case 0: - _context.next = 2; + _context3.next = 2; return (0, _setLocalizedVars2.default)(alm); case 2: case 'end': - return _context.stop(); + return _context3.stop(); } } - }, _callee, _this); + }, _callee3, _this); }))(); /** @@ -2919,56 +2971,56 @@ var alm_is_filtering = false; // WooCommerce Add-on if (alm.addons.woocommerce) { - _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() { - return regeneratorRuntime.wrap(function _callee2$(_context2) { + _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() { + return regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { - switch (_context2.prev = _context2.next) { + switch (_context4.prev = _context4.next) { case 0: - _context2.next = 2; - return (0, _woocommerce.woocommerce)(reveal, alm, data.pageTitle); + _context4.next = 2; + return (0, _woocommerce.woocommerce)(reveal, alm); case 2: (0, _woocommerce.woocommerceLoaded)(alm); case 3: case 'end': - return _context2.stop(); + return _context4.stop(); } } - }, _callee2, this); + }, _callee4, this); }))().catch(function (e) { - console.log('Ajax Load More: There was an error loading woocommerce products.', e); + console.warn('Ajax Load More: There was an error loading woocommerce products.', e); }); alm.init = false; - return; // Exit + return; } // Elementor Add-on if (alm.addons.elementor) { - _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() { - return regeneratorRuntime.wrap(function _callee3$(_context3) { + _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() { + return regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) { - switch (_context3.prev = _context3.next) { + switch (_context5.prev = _context5.next) { case 0: - _context3.next = 2; - return (0, _elementor.elementor)(reveal, alm, data.pageTitle); + _context5.next = 2; + return (0, _elementor.elementor)(reveal, alm); case 2: (0, _elementor.elementorLoaded)(alm); case 3: case 'end': - return _context3.stop(); + return _context5.stop(); } } - }, _callee3, this); + }, _callee5, this); }))().catch(function (e) { - console.log('Ajax Load More: There was an error loading Elementor items.', e); + console.warn('Ajax Load More: There was an error loading Elementor items.', e); }); alm.init = false; - return; // Exit + return; } // Append `reveal` div to ALM Listing container @@ -3006,12 +3058,12 @@ var alm_is_filtering = false; alm.el = alm.listing; // Wrap almMasonry in anonymous async/await function - _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() { - return regeneratorRuntime.wrap(function _callee4$(_context4) { + _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() { + return regeneratorRuntime.wrap(function _callee6$(_context6) { while (1) { - switch (_context4.prev = _context4.next) { + switch (_context6.prev = _context6.next) { case 0: - _context4.next = 2; + _context6.next = 2; return (0, _masonry.almMasonry)(alm, alm.init, alm_is_filtering); case 2: @@ -3029,10 +3081,10 @@ var alm_is_filtering = false; case 7: case 'end': - return _context4.stop(); + return _context6.stop(); } } - }, _callee4, this); + }, _callee6, this); }))().catch(function () { console.log('There was an error with ALM Masonry'); }); @@ -3067,16 +3119,6 @@ var alm_is_filtering = false; alm.AjaxLoadMore.transitionEnd(); } } - - // TABS - Trigger almTabsSetHeight callback in Tabs add-on - if (alm.addons.tabs && typeof almTabsSetHeight === 'function') { - imagesLoaded(reveal, function () { - (0, _fadeIn2.default)(alm.listing, alm.speed); - setTimeout(function () { - window.almTabsSetHeight(alm); - }, alm.speed); - }); - } } else { // Paging if (!alm.init) { @@ -3144,15 +3186,6 @@ var alm_is_filtering = false; alm_is_filtering = false; - // Tabs Complete - if (alm.addons.tabs) { - // Tabs Complete - if (typeof almTabsComplete === 'function') { - // Standard Filtering - window.almTabsComplete(); - } - } - /** * ALM Done. */ @@ -3245,15 +3278,6 @@ var alm_is_filtering = false; alm_is_filtering = false; } - // Tabs Complete - if (alm.addons.tabs) { - // Tabs Complete - if (typeof almTabsComplete === 'function') { - // Standard Filtering - almTabsComplete(); - } - } - // Masonry, clear `alm-listing` height if (alm.transition === 'masonry') { alm.content.style.height = 'auto'; @@ -3388,38 +3412,29 @@ var alm_is_filtering = false; * * @since 2.7.4 */ - if (alm.addons.single_post_id) { - alm.fetchingPreviousPost = false; - alm.addons.single_post_init = true; - } - alm.AjaxLoadMore.getSinglePost = function () { - var action = 'alm_get_single'; - if (alm.fetchingPreviousPost) { - return false; + return; } - alm.fetchingPreviousPost = true; - // Get Ajax URL. - var ajaxURL = alm_localize.ajaxurl; + alm.fetchingPreviousPost = true; // Get data params var params = { + action: 'alm_get_single', id: alm.addons.single_post_id, initial_id: alm.addons.single_post_init_id, order: alm.addons.single_post_order, taxonomy: alm.addons.single_post_taxonomy, excluded_terms: alm.addons.single_post_excluded_terms, post_type: alm.post_type, - init: alm.addons.single_post_init, - action: action + init: alm.addons.single_post_init }; // Send HTTP request via Axios - _axios2.default.get(ajaxURL, { params: params }).then(function (response) { - // Success - var data = response.data; // Get data from response + _axios2.default.get(alm_localize.ajaxurl, { params: params }).then(function (response) { + // Get data from response. + var data = response.data; if (data.has_previous_post) { alm.listing.dataset.singlePostId = data.prev_id; // Update single-post-id on instance @@ -3427,7 +3442,9 @@ var alm_is_filtering = false; alm.addons.single_post_permalink = data.prev_permalink; alm.addons.single_post_title = data.prev_title; alm.addons.single_post_slug = data.prev_slug; + alm.addons.single_post_cache = data.cache; } else { + alm.addons.single_post_cache = false; if (!data.has_previous_post) { alm.AjaxLoadMore.triggerDone(); } @@ -3444,6 +3461,11 @@ var alm_is_filtering = false; }); }; + if (alm.addons.single_post_id) { + alm.fetchingPreviousPost = false; + alm.addons.single_post_init = true; + } + /** * Triggers various add-on functions (if available) after load complete. * @@ -3592,22 +3614,16 @@ var alm_is_filtering = false; } /** - * Window resize functions for Paging, Scroll Distance Percentage, Tabs etc. + * Window resize functions for Paging, Scroll Distance Percentage etc. * * @since 2.1.2 * @updated 5.2 */ - if (alm.addons.paging || alm.addons.tabs || alm.scroll_distance_perc || alm.scroll_direction === 'horizontal') { + if (alm.addons.paging || alm.scroll_distance_perc || alm.scroll_direction === 'horizontal') { var resize = void 0; alm.window.onresize = function () { clearTimeout(resize); - resize = setTimeout(function (e) { - if (alm.addons.tabs) { - // Tabs - if (typeof almOnTabsWindowResize === 'function') { - window.almOnTabsWindowResize(alm); - } - } + resize = setTimeout(function () { if (alm.addons.paging) { // Paging if (typeof almOnWindowResize === 'function') { @@ -3929,8 +3945,8 @@ var alm_is_filtering = false; if (alm.addons.elementor && alm.addons.elementor_type && alm.addons.elementor_type === 'posts') { (0, _elementor.elementorInit)(alm); - // Trigger `Done` if `elementor_next_page_url` is empty - if (alm.addons.elementor_next_page_url === '') { + // Trigger `Done` if `elementor_next_page` is empty + if (alm.addons.elementor_next_page === '') { alm.AjaxLoadMore.triggerDone(); } } @@ -3940,12 +3956,12 @@ var alm_is_filtering = false; // Masonry & Preloaded. if (alm.transition === 'masonry' && alm.addons.preloaded === 'true') { // Wrap almMasonry in anonymous async/await function - _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() { - return regeneratorRuntime.wrap(function _callee5$(_context5) { + _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() { + return regeneratorRuntime.wrap(function _callee7$(_context7) { while (1) { - switch (_context5.prev = _context5.next) { + switch (_context7.prev = _context7.next) { case 0: - _context5.next = 2; + _context7.next = 2; return (0, _masonry.almMasonry)(alm, true, false); case 2: @@ -3953,10 +3969,10 @@ var alm_is_filtering = false; case 3: case 'end': - return _context5.stop(); + return _context7.stop(); } } - }, _callee5, this); + }, _callee7, this); }))().catch(function (e) { console.log('There was an error with ALM Masonry'); }); @@ -4166,19 +4182,19 @@ var reset = exports.reset = function reset() { if (props && props.type === 'woocommerce') { // WooCommerce - _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() { + _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() { var instance, settings; - return regeneratorRuntime.wrap(function _callee6$(_context6) { + return regeneratorRuntime.wrap(function _callee8$(_context8) { while (1) { - switch (_context6.prev = _context6.next) { + switch (_context8.prev = _context8.next) { case 0: instance = document.querySelector('.ajax-load-more-wrap .alm-listing[data-woo="true"]'); // Get ALM instance - _context6.next = 3; + _context8.next = 3; return (0, _woocommerce.wooReset)(); case 3: - settings = _context6.sent; + settings = _context8.sent; // Get WooCommerce `settings` via Ajax if (settings) { instance.dataset.wooSettings = settings; // Update data atts @@ -4187,10 +4203,10 @@ var reset = exports.reset = function reset() { case 5: case 'end': - return _context6.stop(); + return _context8.stop(); } } - }, _callee6, this); + }, _callee8, this); }))().catch(function () { console.warn('Ajax Load More: There was an resetting the Ajax Load More instance.'); }); @@ -4510,8 +4526,8 @@ Object.defineProperty(exports, "__esModule", { /** * Convert a plain text string into an array of HTML nodes * - * @param {*} html | The HTML string - * @param {*} type + * @param {string} html The HTML string + * @param {string} type The type. * @return array * @since 5.0 */ @@ -4520,7 +4536,7 @@ var almDomParser = function almDomParser() { var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'text/html'; if (!html) { - return false; + return; } var parser = new DOMParser(); var data = parser.parseFromString(html, type); @@ -4530,6 +4546,48 @@ exports.default = almDomParser; /***/ }), +/***/ "./core/src/js/helpers/api.js": +/*!************************************!*\ + !*** ./core/src/js/helpers/api.js ***! + \************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.api = undefined; + +var _axios = __webpack_require__(/*! axios */ "./node_modules/axios/index.js"); + +var _axios2 = _interopRequireDefault(_axios); + +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} + +var _alm_localize = alm_localize, + rest_api = _alm_localize.rest_api, + rest_nonce = _alm_localize.rest_nonce; + +/* + * Create a Api object with Axios and configure it for the WordPRess Rest Api. + * + */ + +var api = exports.api = _axios2.default.create({ + baseURL: rest_api, + headers: { + 'content-type': 'application/json', + 'X-WP-Nonce': rest_nonce + } +}); + +/***/ }), + /***/ "./core/src/js/helpers/dispatchScrollEvent.js": /*!****************************************************!*\ !*** ./core/src/js/helpers/dispatchScrollEvent.js ***! @@ -5358,7 +5416,7 @@ function getAjaxParams(alm, action, queryType) { } // Set Cache params. - if (alm.addons.cache === 'true') { + if (alm.addons.cache) { data.cache_id = alm.addons.cache_id; data.cache_logged_in = alm.addons.cache_logged_in; data.cache_slug = (0, _cache.getCacheSlug)(alm, data); @@ -6212,34 +6270,24 @@ function _asyncToGenerator(fn) { /** * Load all items after Ajax request. - * * Note: The function is used with WooCommerce and Elementor add-ons. * * @param {Element} container The HTML container * @param {array} items Array of items. * @param {Object} alm The ALM object. - * @param {string} pageTitle Current page title. - * @param {string} url Current URL. - * @param {string} className Optional classnames. * @param {boolean} waitForImages Wait for images to load before loading next item. */ -function loadItems(container, items, alm, pageTitle) { - var url = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : window.location; - var className = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : ''; - var waitForImages = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : true; +function loadItems(container, items, alm) { + var waitForImages = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true; return new Promise(function (resolve) { + var _alm$rel = alm.rel, + rel = _alm$rel === undefined ? 'next' : _alm$rel; + var total = items.length; var index = 0; var count = 1; - // Get load direction. - var rel = alm.rel ? alm.rel : 'next'; - - // Set load properties. - var matchVal = rel === 'prev' ? total : 1; // The item to attach data attributes. - var page = rel === 'prev' ? alm.pagePrev : alm.page + 1; // Get the page number. - // Reverse items array if rel is 'prev'. items = rel === 'prev' ? items.reverse() : items; @@ -6251,39 +6299,22 @@ function loadItems(container, items, alm, pageTitle) { switch (_context.prev = _context.next) { case 0: items[index].style.opacity = 0; - - // Add data attributes to first or last item for URL updates. - if (count == matchVal) { - items[index].classList.add(className); - - // Set URL - items[index].dataset.url = url; - - // Set page num - items[index].dataset.page = page; - - // Set page title - items[index].dataset.pageTitle = pageTitle; - } - - _context.next = 4; + _context.next = 3; return (0, _loadImage2.default)(container, items[index], alm.ua, rel, waitForImages); - case 4: - + case 3: count++; index++; - loadItem(); - case 7: + case 6: case 'end': return _context.stop(); } } }, _callee, this); }))().catch(function () { - console.log('There was an error loading the items'); + console.warn('There was an error loading the items.'); }); } else { // Delay for effect only @@ -6292,13 +6323,10 @@ function loadItems(container, items, alm, pageTitle) { item.style.opacity = 1; }); if (items[0]) { - // Get the item to focus. - var focusItem = rel === 'prev' ? items[items.length - 1] : items[0]; - - // Set the focus. - (0, _setFocus2.default)(alm, focusItem, null, false); + var focusItem = rel === 'prev' ? items[items.length - 1] : items[0]; // Get the item to focus. + (0, _setFocus2.default)(alm, focusItem, null, false); // Set the focus. } - }, 50); + }, 25); resolve(true); } diff --git a/core/src/js/addons/cache.js b/core/src/js/addons/cache.js index 124c70c..c578487 100644 --- a/core/src/js/addons/cache.js +++ b/core/src/js/addons/cache.js @@ -1,148 +1,92 @@ -import axios from 'axios'; -import { parseQuerystring } from '../addons/filters'; import MD5 from 'crypto-js/md5'; +import { api } from '../helpers/api'; /** * Create unique cache slug from query params. * * @param {object} alm The ALM object. * @param {object} data The data object. - * @return {object} Modified data object. + * @return {string} The cache file slug. */ export function getCacheSlug(alm, data) { - if (alm.addons.nextpage) { - return `page-${alm.page + alm.addons.nextpage_startpage}`; + const { addons, pagePrev, page, rel = 'next' } = alm; + if (addons.nextpage) { + // Nextpage. + return `page-${page + addons.nextpage_startpage}`; + } else if (addons.single_post) { + // Single Post. + return addons.single_post_id; + } else if (addons.woocommerce || addons.elementor) { + // WooCommerce || Elementor. + return rel === 'prev' ? `page-${pagePrev}` : `page-${page + 1}`; } else { + // Standard. return MD5(JSON.stringify(data)).toString(); } } /** - * Create a single post cache file. + * Create a cache file. * - * @param {object} alm The ALM object. - * @param {string} content The content to cache. - * @param {string} type The type of cache to create. + * @param {object} alm The ALM object. + * @param {string} data Content to cache. + * @param {string} name The cache slug * @since 5.3.1 */ -export function createCacheFile(alm, content, type = 'standard') { - if (alm.addons.cache !== 'true' || !content || content === '') { - return false; - } - const name = type === 'single' ? alm.addons.single_post_id : `page-${alm.page + 1}`; - - const formData = new FormData(); - formData.append('action', 'alm_cache_from_html'); - formData.append('security', alm_localize.alm_nonce); - formData.append('cache_id', alm.addons.cache_id); - formData.append('cache_logged_in', alm.addons.cache_logged_in); - formData.append('canonical_url', alm.canonical_url); - formData.append('name', name); - formData.append('html', content.trim()); +export async function createCache(alm, data, name) { + const { html = '', meta = {} } = data; - axios.post(alm_localize.ajaxurl, formData).then(function () { - console.log('Cache created for: ' + alm.canonical_url); - }); -} - -/** - * Create a WooCommerce cache file. - * - * @param {object} alm The ALM object. - * @param {string} content The content to cache. - * @since 5.3.1 - */ -export function wooCache(alm, content) { - if (alm.addons.cache !== 'true' || !content || content === '') { - return false; + if (!html || !alm.addons.cache) { + return; } - let formData = new FormData(); - formData.append('action', 'alm_cache_from_html'); - formData.append('security', alm_localize.alm_nonce); - formData.append('cache_id', alm.addons.cache_id); - formData.append('cache_logged_in', alm.addons.cache_logged_in); - formData.append('canonical_url', alm.canonical_url); - formData.append('name', `page-${alm.page}`); - formData.append('html', content.trim()); - - axios.post(alm_localize.ajaxurl, formData).then(function () { - console.log('Cache created for post: ' + alm.canonical_url); - }); + const params = { + cache_id: alm.addons.cache_id, + cache_logged_in: alm.addons.cache_logged_in, + canonical_url: alm.canonical_url, + name: name, + html: html.trim(), + postcount: meta.postcount, + totalposts: meta.totalposts, + }; + + // Create the cache file via REST API. + const res = await api.post('ajax-load-more/cache/create', params); + if (res.status === 200 && res.data && res.data.success) { + console.log(res.data.msg); + } } /** - * Generate the cache page URL for GET request + * Get cache data file. * - * @param {object} alm The ALM object. - * @since 5.0 - * @supports Standard, SEO, Filters, Nextpage, Single Posts + * @param {object} alm The ALM object. + * @param {object} params Query params. + * @return {Promise\boolean} Cache data or false. */ -export function getCacheUrl(alm) { - if (!alm) { +export async function getCache(alm, params) { + if (!alm.addons.cache || (alm.addons.cache && alm.addons.cache_logged_in)) { + // Exit if not cache or cache is enabled but user is logged in with the setting checked. return false; } - let firstpage = '1'; - let cache_url = ''; - let ext = '.html'; - let path = alm.addons.cache_path + alm.addons.cache_id; - - // SEO Add-on - if (alm.init && alm.addons.seo && alm.isPaged) { - // If request is a paged URL (e.g. /page/3/) - cache_url = path + '/page-' + firstpage + '-' + alm.start_page + ext; - } - - // Filters - else if (alm.addons.filters) { - let filtersPath = parseQuerystring(path); - - if (alm.init && alm.isPaged) { - // First run & Paged - cache_url = filtersPath + '/page-' + firstpage + '-' + alm.addons.filters_startpage + ext; - } else { - let page = alm.page + 1; - - if (alm.addons.preloaded === 'true') { - // Preloaded + Filters - page = alm.page + 2; - } - cache_url = filtersPath + '/page-' + page + ext; - } - } - - // Nextpage - else if (alm.addons.nextpage) { - let nextpage_cache_url; - if (alm.addons.paging) { - nextpage_cache_url = parseInt(alm.page) + 1; - } else { - nextpage_cache_url = parseInt(alm.page) + 2; - if (alm.isPaged) { - // If the request a paged URL (/page/3/) - nextpage_cache_url = parseInt(alm.page) + parseInt(alm.addons.nextpage_startpage) + 1; - } - } - - cache_url = path + '/page-' + nextpage_cache_url + ext; - } - - // Single Post - else if (alm.addons.single_post) { - cache_url = path + '/' + alm.addons.single_post_id + ext; - } + const restParams = { + id: alm.addons.cache_id, + name: params.cache_slug, + }; - // Comments & Preloaded - else if (alm.addons.comments === 'true' && alm.addons.preloaded === 'true') { - // When using comments we need to increase the current page by 2 - cache_url = path + '/page-' + (alm.page + 2) + ext; - } - - // Standard URL request - else { - cache_url = path + '/page-' + (alm.page + 1) + ext; + const res = await api.get('ajax-load-more/cache/get', { params: restParams }); + if (res.status === 200 && res.data) { + return res.data; + } else { + return false; } - return cache_url; + // const cached_url = getCacheURL(alm, params); + // const data = await fetch(cached_url); + // try { + // return await data.json(); + // } catch (error) { + // return false; // No cache file found. + // } } diff --git a/core/src/js/addons/elementor.js b/core/src/js/addons/elementor.js index c3a85c6..09467df 100644 --- a/core/src/js/addons/elementor.js +++ b/core/src/js/addons/elementor.js @@ -1,6 +1,7 @@ import { setButtonAtts } from '../helpers/getButtonURL'; import { lazyImages } from '../modules/lazyImages'; import loadItems from '../modules/loadItems'; +import { createCache } from './cache'; /** * Set up the instance on Elementor @@ -8,7 +9,6 @@ import loadItems from '../modules/loadItems'; * @param {object} alm * @since 5.3.0 */ - export function elementorInit(alm) { if (!alm.addons.elementor || !alm.addons.elementor_type || !alm.addons.elementor_type === 'posts') { return false; @@ -20,18 +20,17 @@ export function elementorInit(alm) { alm.button.dataset.page = alm.addons.elementor_paged; // Set button URL - let nextPage = alm.addons.elementor_next_page_url; + const nextPage = alm.addons.elementor_next_page; alm.button.dataset.url = nextPage ? nextPage : ''; // Set a11y attributes target.setAttribute('aria-live', 'polite'); target.setAttribute('aria-atomic', 'true'); - alm.listing.removeAttribute('aria-live'); alm.listing.removeAttribute('aria-atomic'); // Set data atts on 1st grid item - let item = target.querySelector(`.${alm.addons.elementor_item_class}`); // Get first `.product` item + const item = target.querySelector(`.${alm.addons.elementor_item_class}`); // Get first `.product` item if (item) { item.classList.add('alm-elementor'); item.dataset.url = window.location; @@ -39,11 +38,6 @@ export function elementorInit(alm) { item.dataset.pageTitle = document.title; } - if (alm.addons.elementor_paged > 1) { - // maybe soon - //almElementorResultsTextInit(alm); - } - // Masonry Window Resize. Delay for masonry to be added via Elementor. if (alm.addons.elementor_masonry) { let resizeTimeout; @@ -59,39 +53,101 @@ export function elementorInit(alm) { } } +/** + * Get the content, title and results text from the Ajax response. + * + * @param {object} alm The alm object. + * @param {string} url The request URL. + * @param {object} response Query response. + * @param {string} cache_slug The cache slug. + * @return {object} Results data. + * @since 5.4.0 + */ +export function elementorGetContent(alm, url, response, cache_slug) { + // Default data object. + const data = { + html: '', + meta: { + postcount: 0, + totalposts: 0, + }, + }; + + // Successful response. + if (response.status === 200 && response.data) { + const { addons } = alm; + + // Create temp div to hold response data. + const div = document.createElement('div'); + div.innerHTML = response.data; + + // Get Page Title + const title = div.querySelector('title').innerHTML; + data.pageTitle = title; + + // Get Elementor Items container. + const container = div.querySelector(`${addons.elementor_target} .${addons.elementor_container_class}`); + if (!container) { + console.warn(`Ajax Load More Elementor: Unable to find Elementor container element.`); + return data; + } + + // Get the first item and append data attributes. + const item = container ? container.querySelector(`.${addons.elementor_item_class}`) : null; + if (item) { + item.classList.add('alm-elementor'); + item.dataset.url = url; + item.dataset.page = addons.elementor_paged; + item.dataset.pageTitle = title; + } + + // Count the number of returned items. + const items = container.querySelectorAll(`.${addons.elementor_item_class}`); + if (items) { + // Set the html to the elementor container data. + data.html = container ? container.innerHTML : ''; + data.meta.postcount = items.length; + data.meta.totalposts = items.length; + + // Create cache file. + createCache(alm, data, cache_slug); + } + } + return data; +} + /** * Core ALM Elementor loader. * - * @param {HTMLElement} content - * @param {object} alm - * @param {string} pageTitle + * @param {HTMLElement} content The HTML data. + * @param {object} alm The alm object. * @since 5.3.0 */ -export function elementor(content, alm, pageTitle = document.title) { +export function elementor(content, alm) { if (!content || !alm) { + alm.AjaxLoadMore.triggerDone(); return false; } return new Promise((resolve) => { - let container = alm.addons.elementor_element.querySelector(`.${alm.addons.elementor_container_class}`); // Get post container - let items = content.querySelectorAll(`.${alm.addons.elementor_item_class}`); // Get all items in container - let url = alm.addons.elementor_current_url; // Current Page URL + const { addons } = alm; + const container = alm.addons.elementor_element.querySelector(`.${addons.elementor_container_class}`); // Get post container + const items = content.querySelectorAll(`.${addons.elementor_item_class}`); // Get all items in container - if (container && items && url) { - // Convert NodeList to Array - items = Array.prototype.slice.call(items); + if (container && items) { + const ElementorItems = Array.prototype.slice.call(items); // Convert NodeList to Array // Trigger almElementorLoaded callback. if (typeof almElementorLoaded === 'function') { - window.almElementorLoaded(items); + window.almElementorLoaded(ElementorItems); } - // Load the items (async function () { - await loadItems(container, items, alm, pageTitle, url, 'alm-elementor'); - if (alm.addons.elementor_masonry) { + // Load the items. + await loadItems(container, ElementorItems, alm); + if (addons.elementor_masonry) { setTimeout(function () { - positionMasonryItems(alm, `.${alm.addons.elementor_container_class}`, `.${alm.addons.elementor_item_class}`); + positionMasonryItems(alm, `.${addons.elementor_container_class}`, `.${addons.elementor_item_class}`); }, 125); } @@ -106,17 +162,24 @@ export function elementor(content, alm, pageTitle = document.title) { } /** - * Handle Elementor loaded functionality and dispatch actions. + * Elementor loaded and dispatch actions. * - * @param {object} alm + * @param {object} alm The alm object. * @since 5.5.0 */ export function elementorLoaded(alm) { - let nextPageNum = alm.page + 1; - let nextPage = alm.addons.elementor_next_page_url; // Get URL. + const { trailing_slash, is_front_page } = alm_localize; + const { page, button, canonical_url, AjaxLoadMore, addons } = alm; + const nextPage = page + 1; + + const sep = is_front_page === 'true' ? 'page/' : trailing_slash === 'true' ? '' : '/'; + const slash = trailing_slash === 'true' ? '/' : ''; + const url = `${canonical_url + sep}${nextPage + 1}${slash}`; + + const max_pages = addons.elementor_max_pages; // Set button data attributes. - setButtonAtts(alm.button, nextPageNum, nextPage); + setButtonAtts(button, nextPage, url); // Lazy load images if necessary. lazyImages(alm); @@ -127,55 +190,16 @@ export function elementorLoaded(alm) { } // End transitions. - alm.AjaxLoadMore.transitionEnd(); + AjaxLoadMore.transitionEnd(); - // ALM Done - if (!nextPage) { - alm.AjaxLoadMore.triggerDone(); + // ALM Done. + if (nextPage >= max_pages) { + AjaxLoadMore.triggerDone(); } } /** - * Get the content, title and results text from the Ajax response. - * - * @param {*} response - * @param {object} alm - * @since 5.4.0 - */ -export function elementorGetContent(response, alm) { - let data = { - html: '', - meta: { - postcount: 1, - totalposts: alm.localize.total_posts, - debug: false, - }, - }; - if (response.status === 200 && response.data) { - let div = document.createElement('div'); - div.innerHTML = response.data; - - // Get Page Title - let title = div.querySelector('title').innerHTML; - data.pageTitle = title; - - // Get Elementor Items HTML - let items = div.querySelector(`${alm.addons.elementor_target} .${alm.addons.elementor_container_class}`); - data.html = items ? items.innerHTML : ''; - - // Set Page URL Params - alm.addons.elementor_current_url = alm.addons.elementor_next_page_url; // Set current to previous page URL - alm.addons.elementor_next_page_url = elementorGetNextPage(div, alm.addons.elementor_pagination_class); - - // Results Text - //almElementorResultsText(div, alm); - } - - return data; -} - -/** - * Create Elementor Params for ALM. + * Create Elementor params for ALM. * * @param {object} alm The alm object. * @return {object} The modified object. @@ -205,9 +229,13 @@ export function elementorCreateParams(alm) { alm.addons.elementor_controls = alm.addons.elementor_controls === 'true' ? true : false; alm.addons.elementor_scrolltop = parseInt(alm.addons.elementor_settings.scrolltop); - // Set Page & URL params - alm.addons.elementor_current_url = window.location.href; - alm.addons.elementor_next_page_url = elementorGetNextUrl(alm.addons.elementor_pagination); + // Get next page URL. + alm.addons.elementor_next_page = elementorGetNextUrl(alm.addons.elementor_pagination); + + // Get the max pages. + alm.addons.elementor_max_pages = alm.addons.elementor_element.querySelector('.e-load-more-anchor'); + alm.addons.elementor_max_pages = alm.addons.elementor_max_pages ? parseInt(alm.addons.elementor_max_pages.dataset.maxPage) : 999; + alm.addons.elementor_paged = alm.addons.elementor_settings.paged ? parseInt(alm.addons.elementor_settings.paged) : 1; alm.page = parseInt(alm.page) + alm.addons.elementor_paged; diff --git a/core/src/js/addons/singleposts.js b/core/src/js/addons/singleposts.js index f65ab5b..c84825d 100644 --- a/core/src/js/addons/singleposts.js +++ b/core/src/js/addons/singleposts.js @@ -1,27 +1,38 @@ +import { createCache } from './cache'; + /** * Create the HTML for loading Single Posts. * - * @param {Object} response Query response - * @param {HTMLElement} target The target div + * @param {object} alm The alm object. + * @param {object} response Query response. + * @param {string} cache_slug The cache slug. + * @return {object} Results data. * @since 5.1.8.1 */ -export function singlePostHTML(response, target = null) { - let data = { +export function singlePostHTML(alm, response, cache_slug) { + const data = { html: '', meta: { - postcount: 1, - totalposts: 1, - debug: 'Single Posts Query', + postcount: 0, + totalposts: 0, }, }; - if (response.status === 200 && response.data && target) { - // Create temp div to hold Ajax response data. + // Get target element. + const { single_post_target } = alm.addons; + + if (response.status === 200 && response.data && single_post_target) { + // Create temp div to hold response data. const div = document.createElement('div'); div.innerHTML = response.data; // Get target element. - let html = div.querySelector(target); + const html = div.querySelector(single_post_target); + + if (!html) { + console.warn(`Ajax Load More: Unable to find ${single_post_target} element.`); + return data; + } // Get any custom target elements. const customElements = window && window.almSinglePostsCustomElements; @@ -29,11 +40,14 @@ export function singlePostHTML(response, target = null) { html.appendChild(singlePostsGetCustomElements(div, customElements)); } - if (html) { - data.html = html.innerHTML; - } else { - console.warn(`Ajax Load More: Unable to find ${target} element.`); - } + data.html = html.innerHTML; + data.meta = { + postcount: 1, + totalposts: 1, + }; + + // Create cache file. + createCache(alm, data, cache_slug); } return data; } @@ -47,7 +61,7 @@ export default singlePostHTML; * * e.g. window.almSinglePostsCustomElements = ['#woocommerce-inline-inline-css', '#wc-block-style-css']; * - * @param {object} content The HTML element. + * @param {object} content The HTML element. * @param {array|string} customElements The elements to search for in content. * @return {object} HTML elements. */ @@ -66,7 +80,7 @@ function singlePostsGetCustomElements(content = '', customElements = false) { // Loop Array to extract elements and append to container. for (let i = 0; i < customElements.length; i++) { - let element = content.querySelector(customElements[i]); + const element = content.querySelector(customElements[i]); if (element) { container.appendChild(element); } diff --git a/core/src/js/addons/woocommerce.js b/core/src/js/addons/woocommerce.js index ae8e3be..8cab378 100644 --- a/core/src/js/addons/woocommerce.js +++ b/core/src/js/addons/woocommerce.js @@ -4,6 +4,7 @@ import { setButtonAtts } from '../helpers/getButtonURL'; import { lazyImages } from '../modules/lazyImages'; import loadItems from '../modules/loadItems'; import { createLoadPreviousButton } from '../modules/loadPrevious'; +import { createCache } from './cache'; /** * Set up instance of ALM WooCommerce @@ -77,28 +78,27 @@ export function wooInit(alm) { * * @param {Element} content WooCommerce content container. * @param {object} alm ALM object. - * @param {string} pageTitle Page title. * @since 5.3.0 */ -export function woocommerce(content, alm, pageTitle = document.title) { +export function woocommerce(content, alm) { if (!content || !alm) { return false; } return new Promise((resolve) => { - const container = document.querySelector(alm.addons.woocommerce_settings.container); // Get `ul.products` - const products = content.querySelectorAll(alm.addons.woocommerce_settings.products); // Get all `.products` - const page = alm.rel === 'prev' ? alm.pagePrev - 1 : alm.page; - const url = alm.addons.woocommerce_settings.paged_urls[page]; - const { settings = {} } = alm.addons.woocommerce_settings; + const { woocommerce_settings = {} } = alm.addons; + const { settings = {} } = woocommerce_settings; + + const container = document.querySelector(woocommerce_settings.container); // Get `ul.products` + const products = content.querySelectorAll(woocommerce_settings.products); // Get all `.products` const waitForImages = settings && settings.images_loaded === 'true' ? true : false; - if (container && products && url) { + if (container && products) { const wooProducts = Array.prototype.slice.call(products); // Convert NodeList to Array. - // Load the Products (async function () { - await loadItems(container, wooProducts, alm, pageTitle, url, 'alm-woocommerce', waitForImages); + // Load the Products. + await loadItems(container, wooProducts, alm, waitForImages); resolve(true); })().catch((e) => { console.log(e, 'There was an error with WooCommerce'); @@ -112,6 +112,76 @@ export function woocommerce(content, alm, pageTitle = document.title) { }); } +/** + * Get the content, title and results from the Ajax request. + * + * @param {object} alm The alm object. + * @param {string} url The request URL. + * @param {object} response Query response. + * @param {string} cache_slug The cache slug. + * @return {object} Results data. + * @since 5.3.0 + */ +export function wooGetContent(alm, url, response, cache_slug) { + // Default data object. + const data = { + html: '', + meta: { + postcount: 0, + totalposts: 0, + }, + }; + + // Successful response. + if (response.status === 200 && response.data) { + const { addons, pagePrev, rel = 'next', page, localize } = alm; + const { total_posts } = localize; + const { woocommerce_settings = {} } = addons; + const currentPage = rel === 'prev' ? pagePrev : page + 1; // Get the page number. + + // Create temp div to hold response data. + const div = document.createElement('div'); + div.innerHTML = response.data; + + // Get Page Title + const title = div.querySelector('title').innerHTML; + data.pageTitle = title; + + // Get WooCommerce products container. + const container = div.querySelector(woocommerce_settings.container); + if (!container) { + console.warn(`Ajax Load More WooCommerce: Unable to find WooCommerce ${woocommerce_settings.container} element.`); + return data; + } + + // Get the first item and append data attributes. + const item = container ? container.querySelector(woocommerce_settings.products) : null; + if (item) { + item.classList.add('alm-woocommerce'); + item.dataset.url = url; + item.dataset.page = currentPage; + item.dataset.pageTitle = title; + } + + // Count the number of returned items. + const items = container.querySelectorAll(woocommerce_settings.products); + if (items) { + // Set the html to the elementor container data. + data.html = container ? container.innerHTML : ''; + data.meta.postcount = items.length; + data.meta.totalposts = total_posts; + + // Create cache file. + createCache(alm, data, cache_slug); + } + + // Results Text + almWooCommerceResultsText(div, alm); + } + + return data; +} + /** * Handle WooCommerce loaded functionality and dispatch actions. * @@ -159,7 +229,7 @@ export function woocommerceLoaded(alm) { */ export function wooReset() { return new Promise((resolve) => { - let url = window.location; + const url = window.location; axios .get(url) .then((response) => { @@ -174,46 +244,12 @@ export function wooReset() { resolve(false); } }) - .catch(function (error) { + .catch(function () { resolve(false); }); }); } -/** - * Get the content, title and results text from the Ajax response - * - * @param {object} alm ALM object. - * @since 5.3.0 - */ -export function wooGetContent(response, alm) { - let data = { - html: '', - meta: { - postcount: 1, - totalposts: alm.localize.total_posts, - debug: false, - }, - }; - if (response.status === 200 && response.data) { - let div = document.createElement('div'); - div.innerHTML = response.data; - - // Get Page Title - let title = div.querySelector('title').innerHTML; - data.pageTitle = title; - - // Get Products HTML - let products = div.querySelector(alm.addons.woocommerce_settings.container); - data.html = products ? products.innerHTML : ''; - - // Results Text - almWooCommerceResultsText(div, alm); - } - - return data; -} - /** * Set results text for WooCommerce Add-on. * diff --git a/core/src/js/ajax-load-more.js b/core/src/js/ajax-load-more.js index 23c8b3e..289d3b2 100755 --- a/core/src/js/ajax-load-more.js +++ b/core/src/js/ajax-load-more.js @@ -1,17 +1,19 @@ // ALM Modules -import './helpers/helpers'; -//import commentReplyFix from './helpers/commentReplyFix'; -import { createCacheFile } from './addons/cache'; +import axios from 'axios'; +import { getCache } from './addons/cache'; import { elementor, elementorCreateParams, elementorGetContent, elementorInit, elementorLoaded } from './addons/elementor'; import { buildFilterURL } from './addons/filters'; import { createSEOAttributes, getSEOPageNum } from './addons/seo'; import { singlePostHTML } from './addons/singleposts'; -import { woocommerce, woocommerceLoaded, wooGetContent, wooInit, wooReset } from './addons/woocommerce'; +import { wooGetContent, wooInit, wooReset, woocommerce, woocommerceLoaded } from './addons/woocommerce'; import almAppendChildren from './helpers/almAppendChildren'; import almDomParser from './helpers/almDomParser'; +import { getButtonURL } from './helpers/getButtonURL'; import getParameterByName from './helpers/getParameterByName'; import getScrollPercentage from './helpers/getScrollPercentage'; -import * as queryParams from './helpers/queryParams'; +import getTotals from './helpers/getTotals'; +import './helpers/helpers'; +import { getAjaxParams, getRestAPIParams } from './helpers/queryParams'; import srcsetPolyfill from './helpers/srcsetPolyfill'; import stripEmptyNodes from './helpers/stripEmptyNodes'; import tableWrap from './helpers/tableWrap'; @@ -19,7 +21,6 @@ import almDebug from './modules/almDebug'; import almFadeIn from './modules/fadeIn'; import almFadeOut from './modules/fadeOut'; import almFilter from './modules/filtering'; -import { getButtonURL } from './helpers/getButtonURL'; import insertScript from './modules/insertScript'; import { lazyImages } from './modules/lazyImages'; import { almMasonry, almMasonryConfig } from './modules/masonry'; @@ -29,14 +30,26 @@ import * as resultsText from './modules/resultsText'; import setFocus from './modules/setFocus'; import setLocalizedVars from './modules/setLocalizedVars'; import { tableOfContents } from './modules/tableofcontents'; -import getTotals from './helpers/getTotals'; -import axios from 'axios'; // External Modules let qs = require('qs'); let imagesLoaded = require('imagesloaded'); + +// Axios Config. axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; +// Axios Interceptor for nested data objects +axios.interceptors.request.use((config) => { + config.paramsSerializer = (params) => { + // Qs is already included in the Axios package + return qs.stringify(params, { + arrayFormat: 'brackets', + encode: false, + }); + }; + return config; +}); + // Polyfills require('@babel/polyfill/noConflict'); require('focus-options-polyfill'); @@ -175,9 +188,8 @@ let alm_is_filtering = false; } // Cache add-on - alm.addons.cache = alm.listing.dataset.cache; - alm.addons.cache = alm.addons.cache === undefined ? false : alm.addons.cache; - if (alm.addons.cache === 'true') { + alm.addons.cache = alm.listing.dataset.cache && alm.listing.dataset.cache === 'true' ? true : false; + if (alm.addons.cache) { alm.addons.cache_id = alm.listing.dataset.cacheId; alm.addons.cache_path = alm.listing.dataset.cachePath; alm.addons.cache_logged_in = alm.listing.dataset.cacheLoggedIn ? alm.listing.dataset.cacheLoggedIn : false; @@ -214,6 +226,7 @@ let alm_is_filtering = false; alm.addons.single_post_progress_bar = alm.listing.dataset.singlePostProgressBar === undefined ? '' : alm.listing.dataset.singlePostProgressBar; alm.addons.single_post_target = alm.listing.dataset.singlePostTarget === undefined ? '' : alm.listing.dataset.singlePostTarget; alm.addons.single_post_preview = alm.listing.dataset.singlePostPreview === undefined ? false : true; + if (alm.addons.single_post_preview) { const singlePostPreviewData = alm.listing.dataset.singlePostPreview.split(':'); alm.addons.single_post_preview_data = { @@ -237,7 +250,6 @@ let alm_is_filtering = false; alm.addons.comments_callback = alm.listing.dataset.comments_callback; } - alm.addons.tabs = alm.listing.dataset.tabs; alm.addons.filters = alm.listing.dataset.filters; alm.addons.seo = alm.listing.dataset.seo; alm.addons.seo_offset = alm.listing.dataset.seoOffset; @@ -345,30 +357,6 @@ let alm_is_filtering = false; alm.addons.filters = false; } - // Tabs. - if (alm.addons.tabs === 'true') { - alm.addons.tabs = true; - alm.addons.tab_template = alm.listing.dataset.tabTemplate ? alm.listing.dataset.tabTemplate : ''; - alm.addons.tab_onload = alm.listing.dataset.tabOnload ? alm.listing.dataset.tabOnload : ''; - alm.addons.tabs_resturl = alm.listing.dataset.tabsRestUrl ? alm.listing.dataset.tabsRestUrl : ''; - - // Locate active template (deeplinks) - if (alm.addons.tab_onload !== '') { - let tabNav = document.querySelector(`.alm-tab-nav li [data-tab-url=${alm.addons.tab_onload}]`); - alm.addons.tab_template = tabNav ? tabNav.dataset.tabTemplate : alm.addons.tab_template; - alm.listing.dataset.tabOnload = ''; // Clear tabOnload param - // Set selected tab - if (tabNav) { - let activeTab = document.querySelector(`.alm-tab-nav li .active`); - if (activeTab) { - activeTab.classList.remove('active'); - } - } - } - } else { - alm.addons.tabs = false; - } - /* REST API */ if (alm.extensions.restapi) { alm.extensions.restapi_debug = alm.extensions.restapi_debug === undefined ? false : alm.extensions.restapi_debug; @@ -457,6 +445,7 @@ let alm_is_filtering = false; alm.addons.single_post_permalink = ''; alm.addons.single_post_title = ''; alm.addons.single_post_slug = ''; + alm.addons.single_post_cache = false; alm.addons.single_post_title_template = alm.listing.dataset.singlePostTitleTemplate; alm.addons.single_post_siteTitle = alm.listing.dataset.singlePostSiteTitle; alm.addons.single_post_siteTagline = alm.listing.dataset.singlePostSiteTagline; @@ -615,10 +604,9 @@ let alm_is_filtering = false; window.almOnChange(alm); } + // Set loading attributes. alm.loading = true; showPlaceholder(alm); - - // Add `.alm-loading` class to container. alm.main.classList.add('alm-loading'); // Add loading styles to buttons. @@ -633,7 +621,7 @@ let alm_is_filtering = false; } } - // Standard ALM query + // Dispatch Ajax query. alm.AjaxLoadMore.ajax(); }; @@ -643,9 +631,8 @@ let alm_is_filtering = false; * @param {string} queryType The type of Ajax request (standard/totalposts). * @since 2.6.0 */ - alm.AjaxLoadMore.ajax = function (queryType = 'standard') { - // Default ALM action - let action = 'alm_get_posts'; + alm.AjaxLoadMore.ajax = async function (queryType = 'standard') { + let action = 'alm_get_posts'; // Default action // ACF Params alm.acf_array = ''; @@ -744,162 +731,88 @@ let alm_is_filtering = false; // Dispatch Ajax request. if (alm.extensions.restapi) { - // REST API + // Rest API. alm.AjaxLoadMore.restapi(alm); - } else if (alm.addons.tabs) { - // Tabs - alm.AjaxLoadMore.tabs(alm); } else { - // Standard ALM - alm.AjaxLoadMore.adminajax(alm, action, queryType); + // Standard ALM. + const params = getAjaxParams(alm, action, queryType); + const cache = await getCache(alm, Object.assign({}, params)); + if (cache) { + alm.AjaxLoadMore.success(cache); + } else { + alm.AjaxLoadMore.adminajax(params, queryType); + } } }; /** * Send request to the admin-ajax.php * - * @param {object} alm The Ajax Load More object. - * @param {string} action The Ajax action. + * @param {object} params Query params. * @param {string} queryType The type of Ajax request (standard/totalposts). * @since 5.0.0 */ - alm.AjaxLoadMore.adminajax = function (alm, action, queryType) { - // Axios Interceptor for nested data objects - axios.interceptors.request.use((config) => { - config.paramsSerializer = (params) => { - // Qs is already included in the Axios package - return qs.stringify(params, { - arrayFormat: 'brackets', - encode: false, - }); - }; - return config; - }); - + alm.AjaxLoadMore.adminajax = async function (params, queryType) { // Get Ajax URL. - let ajaxURL = alm_localize.ajaxurl; + let { ajaxurl } = alm_localize; - // Get query params. - let params = queryParams.getAjaxParams(alm, action, queryType); + // Deconstruct query params. + const { cache_slug = '' } = params; - // Single Posts Add-on - // If has `single_post_target`, adjust the Ajax URL to the post URL. + /** + * Single Posts. + * If `single_post_target`, adjust the Ajax URL to the post URL. + */ if (alm.addons.single_post && alm.addons.single_post_target) { - ajaxURL = `${alm.addons.single_post_permalink}?id=${alm.addons.single_post_id}&alm_page=${parseInt(alm.page) + 1}`; + ajaxurl = `${alm.addons.single_post_permalink}?id=${alm.addons.single_post_id}&alm_page=${parseInt(alm.page) + 1}`; params = ''; } - // WooCommerce Add-on - if (alm.addons.woocommerce) { - ajaxURL = getButtonURL(alm, alm.rel); - params = ''; - } - - // Elementor Add-on - if (alm.addons.elementor && alm.addons.elementor_type && alm.addons.elementor_type === 'posts') { - ajaxURL = getButtonURL(alm, alm.rel); + // WooCommerce || Elementor. + if (alm.addons.woocommerce || (alm.addons.elementor && alm.addons.elementor_type === 'posts')) { + ajaxurl = getButtonURL(alm, alm.rel); params = ''; } - // Send HTTP request via axios - axios - .get(ajaxURL, { params }) + // Send HTTP request via axios. + const data = await axios + .get(ajaxurl, { params }) .then(function (response) { - // Success - let data = ''; - if (alm.addons.single_post && alm.addons.single_post_target) { // Single Posts - data = singlePostHTML(response, alm.addons.single_post_target); - createCacheFile(alm, data.html, 'single'); + return singlePostHTML(alm, response, cache_slug); } else if (alm.addons.woocommerce) { - // WooCommerce - data = wooGetContent(response, alm); - createCacheFile(alm, data.html, 'woocommerce'); + // WooCommerce. + return wooGetContent(alm, ajaxurl, response, cache_slug); } else if (alm.addons.elementor) { // Elementor - data = elementorGetContent(response, alm); - createCacheFile(alm, data.html, 'elementor'); + return elementorGetContent(alm, ajaxurl, response, cache_slug); } else { // Get data from response - data = response.data; - } - - // Standard Query - if (queryType === 'standard') { - alm.AjaxLoadMore.success(data); - } else if (queryType === 'totalpages' && alm.addons.paging && alm.addons.nextpage) { - // Next Page and Paging - if (typeof almBuildPagination === 'function') { - window.almBuildPagination(data.totalpages, alm); - alm.totalpages = data.totalpages; - } - } else if (queryType === 'totalposts' && alm.addons.paging) { - // Paging - if (typeof almBuildPagination === 'function') { - window.almBuildPagination(data.totalposts, alm); - } + return response.data; } }) .catch(function (error) { // Error alm.AjaxLoadMore.error(error, 'adminajax'); }); - }; - /** - * Ajax Load More Tab functionality. - * - * @param {object} alm The Ajax Load More object. - * @since 5.2.0 - */ - alm.AjaxLoadMore.tabs = function (alm) { - let alm_rest_url = `${alm.addons.tabs_resturl}ajaxloadmore/tab`; - - let params = { - post_id: alm.post_id, - template: alm.addons.tab_template, - }; + switch (queryType) { + case 'standard': + alm.AjaxLoadMore.success(data); + break; - // Axios Interceptor for nested data objects - axios.interceptors.request.use((config) => { - config.paramsSerializer = (params) => { - // Qs is already included in the Axios package - return qs.stringify(params, { - arrayFormat: 'brackets', - encode: false, - }); - }; - return config; - }); - - // Send Ajax request - axios - .get(alm_rest_url, { params }) - .then(function (response) { - // Success - let results = response.data; // Get data from response - let html = results.html; - - // Create object to pass to success() - let obj = { - html: html, - meta: { - postcount: 1, - totalposts: 1, - }, - }; - alm.AjaxLoadMore.success(obj); // Send data - - // Callback to Tabs add-on - if (typeof almTabLoaded === 'function') { - window.almTabLoaded(alm); + case 'totalposts': + if (alm.addons.paging && alm.addons.nextpage && typeof almBuildPagination === 'function') { + window.almBuildPagination(data.totalpages, alm); + alm.totalpages = data.totalpages; + } else { + if (alm.addons.paging && typeof almBuildPagination === 'function') { + window.almBuildPagination(data.totalposts, alm); + } } - }) - .catch(function (error) { - // Error - alm.AjaxLoadMore.error(error, 'restapi'); - }); + break; + } }; /** @@ -911,23 +824,10 @@ let alm_is_filtering = false; * @since 5.0.0 */ alm.AjaxLoadMore.restapi = function (alm) { - let alm_rest_template = wp.template(alm.extensions.restapi_template_id); - let alm_rest_url = `${alm.extensions.restapi_base_url}/${alm.extensions.restapi_namespace}/${alm.extensions.restapi_endpoint}`; - let params = queryParams.getRestAPIParams(alm); // [./helpers/queryParams.js] - - // Axios Interceptor for nested data objects - axios.interceptors.request.use((config) => { - config.paramsSerializer = (params) => { - // Qs is already included in the Axios package - return qs.stringify(params, { - arrayFormat: 'brackets', - encode: false, - }); - }; - return config; - }); + const alm_rest_template = wp.template(alm.extensions.restapi_template_id); + const alm_rest_url = `${alm.extensions.restapi_base_url}/${alm.extensions.restapi_namespace}/${alm.extensions.restapi_endpoint}`; + const params = getRestAPIParams(alm); // [./helpers/queryParams.js] - // Send Ajax request axios .get(alm_rest_url, { params }) .then(function (response) { @@ -949,7 +849,7 @@ let alm_is_filtering = false; } // Create object to pass to success() - let obj = { + const obj = { html: data, meta: { postcount: postcount, @@ -981,7 +881,7 @@ let alm_is_filtering = false; */ alm.AjaxLoadMore.success = function (data) { if (alm.addons.single_post) { - alm.AjaxLoadMore.getSinglePost(); // Get previous post data + alm.AjaxLoadMore.getSinglePost(); // Get single post data for next post. } let isPaged = false; @@ -1015,9 +915,6 @@ let alm_is_filtering = false; // Set alm.html as plain text return alm.html = html; - // If cache, get the length of the html object - // total = is_cache ? almDomParser(html).length : total; - // First Run Only if (alm.init) { // Set Meta @@ -1250,27 +1147,27 @@ let alm_is_filtering = false; // WooCommerce Add-on if (alm.addons.woocommerce) { (async function () { - await woocommerce(reveal, alm, data.pageTitle); + await woocommerce(reveal, alm); woocommerceLoaded(alm); })().catch((e) => { - console.log('Ajax Load More: There was an error loading woocommerce products.', e); + console.warn('Ajax Load More: There was an error loading woocommerce products.', e); }); alm.init = false; - return; // Exit + return; } // Elementor Add-on if (alm.addons.elementor) { (async function () { - await elementor(reveal, alm, data.pageTitle); + await elementor(reveal, alm); elementorLoaded(alm); })().catch((e) => { - console.log('Ajax Load More: There was an error loading Elementor items.', e); + console.warn('Ajax Load More: There was an error loading Elementor items.', e); }); alm.init = false; - return; // Exit + return; } // Append `reveal` div to ALM Listing container @@ -1355,16 +1252,6 @@ let alm_is_filtering = false; alm.AjaxLoadMore.transitionEnd(); } } - - // TABS - Trigger almTabsSetHeight callback in Tabs add-on - if (alm.addons.tabs && typeof almTabsSetHeight === 'function') { - imagesLoaded(reveal, function () { - almFadeIn(alm.listing, alm.speed); - setTimeout(function () { - window.almTabsSetHeight(alm); - }, alm.speed); - }); - } } else { // Paging if (!alm.init) { @@ -1432,15 +1319,6 @@ let alm_is_filtering = false; alm_is_filtering = false; - // Tabs Complete - if (alm.addons.tabs) { - // Tabs Complete - if (typeof almTabsComplete === 'function') { - // Standard Filtering - window.almTabsComplete(); - } - } - /** * ALM Done. */ @@ -1533,15 +1411,6 @@ let alm_is_filtering = false; alm_is_filtering = false; } - // Tabs Complete - if (alm.addons.tabs) { - // Tabs Complete - if (typeof almTabsComplete === 'function') { - // Standard Filtering - almTabsComplete(); - } - } - // Masonry, clear `alm-listing` height if (alm.transition === 'masonry') { alm.content.style.height = 'auto'; @@ -1674,24 +1543,16 @@ let alm_is_filtering = false; * * @since 2.7.4 */ - if (alm.addons.single_post_id) { - alm.fetchingPreviousPost = false; - alm.addons.single_post_init = true; - } - alm.AjaxLoadMore.getSinglePost = function () { - let action = 'alm_get_single'; - if (alm.fetchingPreviousPost) { - return false; + return; } - alm.fetchingPreviousPost = true; - // Get Ajax URL. - let ajaxURL = alm_localize.ajaxurl; + alm.fetchingPreviousPost = true; // Get data params - let params = { + const params = { + action: 'alm_get_single', id: alm.addons.single_post_id, initial_id: alm.addons.single_post_init_id, order: alm.addons.single_post_order, @@ -1699,15 +1560,14 @@ let alm_is_filtering = false; excluded_terms: alm.addons.single_post_excluded_terms, post_type: alm.post_type, init: alm.addons.single_post_init, - action: action, }; // Send HTTP request via Axios axios - .get(ajaxURL, { params }) + .get(alm_localize.ajaxurl, { params }) .then(function (response) { - // Success - let data = response.data; // Get data from response + // Get data from response. + const data = response.data; if (data.has_previous_post) { alm.listing.dataset.singlePostId = data.prev_id; // Update single-post-id on instance @@ -1715,7 +1575,9 @@ let alm_is_filtering = false; alm.addons.single_post_permalink = data.prev_permalink; alm.addons.single_post_title = data.prev_title; alm.addons.single_post_slug = data.prev_slug; + alm.addons.single_post_cache = data.cache; } else { + alm.addons.single_post_cache = false; if (!data.has_previous_post) { alm.AjaxLoadMore.triggerDone(); } @@ -1733,6 +1595,11 @@ let alm_is_filtering = false; }); }; + if (alm.addons.single_post_id) { + alm.fetchingPreviousPost = false; + alm.addons.single_post_init = true; + } + /** * Triggers various add-on functions (if available) after load complete. * @@ -1881,22 +1748,16 @@ let alm_is_filtering = false; } /** - * Window resize functions for Paging, Scroll Distance Percentage, Tabs etc. + * Window resize functions for Paging, Scroll Distance Percentage etc. * * @since 2.1.2 * @updated 5.2 */ - if (alm.addons.paging || alm.addons.tabs || alm.scroll_distance_perc || alm.scroll_direction === 'horizontal') { + if (alm.addons.paging || alm.scroll_distance_perc || alm.scroll_direction === 'horizontal') { let resize; alm.window.onresize = function () { clearTimeout(resize); - resize = setTimeout(function (e) { - if (alm.addons.tabs) { - // Tabs - if (typeof almOnTabsWindowResize === 'function') { - window.almOnTabsWindowResize(alm); - } - } + resize = setTimeout(function () { if (alm.addons.paging) { // Paging if (typeof almOnWindowResize === 'function') { @@ -2223,8 +2084,8 @@ let alm_is_filtering = false; if (alm.addons.elementor && alm.addons.elementor_type && alm.addons.elementor_type === 'posts') { elementorInit(alm); - // Trigger `Done` if `elementor_next_page_url` is empty - if (alm.addons.elementor_next_page_url === '') { + // Trigger `Done` if `elementor_next_page` is empty + if (alm.addons.elementor_next_page === '') { alm.AjaxLoadMore.triggerDone(); } } @@ -2435,8 +2296,8 @@ export const reset = function (props = {}) { if (props && props.type === 'woocommerce') { // WooCommerce (async function () { - let instance = document.querySelector('.ajax-load-more-wrap .alm-listing[data-woo="true"]'); // Get ALM instance - let settings = await wooReset(); // Get WooCommerce `settings` via Ajax + const instance = document.querySelector('.ajax-load-more-wrap .alm-listing[data-woo="true"]'); // Get ALM instance + const settings = await wooReset(); // Get WooCommerce `settings` via Ajax if (settings) { instance.dataset.wooSettings = settings; // Update data atts almFilter('fade', '100', data, 'filter'); diff --git a/core/src/js/helpers/almDomParser.js b/core/src/js/helpers/almDomParser.js index cb3ef41..30cffc8 100755 --- a/core/src/js/helpers/almDomParser.js +++ b/core/src/js/helpers/almDomParser.js @@ -1,17 +1,17 @@ /** * Convert a plain text string into an array of HTML nodes * - * @param {*} html | The HTML string - * @param {*} type + * @param {string} html The HTML string + * @param {string} type The type. * @return array * @since 5.0 */ const almDomParser = function (html = '', type = 'text/html') { if (!html) { - return false; + return; } - let parser = new DOMParser(); - let data = parser.parseFromString(html, type); + const parser = new DOMParser(); + const data = parser.parseFromString(html, type); return data ? Array.prototype.slice.call(data.body.childNodes) : data; }; export default almDomParser; diff --git a/core/src/js/helpers/api.js b/core/src/js/helpers/api.js new file mode 100644 index 0000000..393e956 --- /dev/null +++ b/core/src/js/helpers/api.js @@ -0,0 +1,14 @@ +import axios from 'axios'; +const { rest_api, rest_nonce } = alm_localize; + +/* + * Create a Api object with Axios and configure it for the WordPRess Rest Api. + * + */ +export const api = axios.create({ + baseURL: rest_api, + headers: { + 'content-type': 'application/json', + 'X-WP-Nonce': rest_nonce, + }, +}); diff --git a/core/src/js/helpers/queryParams.js b/core/src/js/helpers/queryParams.js index 422cbae..cd3ab76 100755 --- a/core/src/js/helpers/queryParams.js +++ b/core/src/js/helpers/queryParams.js @@ -167,7 +167,7 @@ export function getAjaxParams(alm, action, queryType) { } // Set Cache params. - if (alm.addons.cache === 'true') { + if (alm.addons.cache) { data.cache_id = alm.addons.cache_id; data.cache_logged_in = alm.addons.cache_logged_in; data.cache_slug = getCacheSlug(alm, data); diff --git a/core/src/js/modules/loadItems.js b/core/src/js/modules/loadItems.js index 8b0f524..29afa39 100644 --- a/core/src/js/modules/loadItems.js +++ b/core/src/js/modules/loadItems.js @@ -3,30 +3,20 @@ import setFocus from './setFocus'; /** * Load all items after Ajax request. - * * Note: The function is used with WooCommerce and Elementor add-ons. * * @param {Element} container The HTML container * @param {array} items Array of items. * @param {Object} alm The ALM object. - * @param {string} pageTitle Current page title. - * @param {string} url Current URL. - * @param {string} className Optional classnames. * @param {boolean} waitForImages Wait for images to load before loading next item. */ -export default function loadItems(container, items, alm, pageTitle, url = window.location, className = '', waitForImages = true) { +export default function loadItems(container, items, alm, waitForImages = true) { return new Promise((resolve) => { + const { rel = 'next' } = alm; const total = items.length; let index = 0; let count = 1; - // Get load direction. - const rel = alm.rel ? alm.rel : 'next'; - - // Set load properties. - const matchVal = rel === 'prev' ? total : 1; // The item to attach data attributes. - const page = rel === 'prev' ? alm.pagePrev : alm.page + 1; // Get the page number. - // Reverse items array if rel is 'prev'. items = rel === 'prev' ? items.reverse() : items; @@ -34,29 +24,12 @@ export default function loadItems(container, items, alm, pageTitle, url = window if (count <= total) { (async function () { items[index].style.opacity = 0; - - // Add data attributes to first or last item for URL updates. - if (count == matchVal) { - items[index].classList.add(className); - - // Set URL - items[index].dataset.url = url; - - // Set page num - items[index].dataset.page = page; - - // Set page title - items[index].dataset.pageTitle = pageTitle; - } - await loadImage(container, items[index], alm.ua, rel, waitForImages); - count++; index++; - loadItem(); })().catch(() => { - console.log('There was an error loading the items'); + console.warn('There was an error loading the items.'); }); } else { // Delay for effect only @@ -65,13 +38,10 @@ export default function loadItems(container, items, alm, pageTitle, url = window item.style.opacity = 1; }); if (items[0]) { - // Get the item to focus. - const focusItem = rel === 'prev' ? items[items.length - 1] : items[0]; - - // Set the focus. - setFocus(alm, focusItem, null, false); + const focusItem = rel === 'prev' ? items[items.length - 1] : items[0]; // Get the item to focus. + setFocus(alm, focusItem, null, false); // Set the focus. } - }, 50); + }, 25); resolve(true); } From 4283e0edeb764ba8302be8a781d0fbcecefa915d Mon Sep 17 00:00:00 2001 From: Darren Cooney Date: Wed, 10 May 2023 10:13:45 -0400 Subject: [PATCH 06/18] Code comment updates --- ajax-load-more.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ajax-load-more.php b/ajax-load-more.php index 50f2efc..bdb0e86 100755 --- a/ajax-load-more.php +++ b/ajax-load-more.php @@ -66,6 +66,8 @@ * NOTICE: Cache add-on < 2.0 is no longer supported. Please update to the latest version of the Cache add-on to use Cache functionality. * UPDATE: Adding required functionality for the Cache 2.0 update. This introduces a new cache structure using MD5 hash for many cache URLs. +* UPDATE: Core ALM JavaScript refactoring to stremline content loading using async/await and promises. +* UPDATE: Updated WooCommerce and Elementor add-on functionality to load content in a normalized manner. * UPDATE: Code refactoring, cleanup and overall improvements across the Ajax Load More. * FIX: Fixed issue with Elementor and Cache add-ons not working in some instances. * FIX: Fixed issue with WooCommerce and Cache add-ons not working in some instances. From e89a4b9740eb9b800dccf246c9389d7760428899 Mon Sep 17 00:00:00 2001 From: Darren Cooney Date: Fri, 12 May 2023 10:43:03 -0400 Subject: [PATCH 07/18] Updated query params and CTA variable passing --- ajax-load-more.php | 24 +- core/dist/js/ajax-load-more.js | 369 +++++++++++------------ core/src/js/addons/cache.js | 2 +- core/src/js/ajax-load-more.js | 107 +------ core/src/js/helpers/almAppendChild.js | 26 -- core/src/js/helpers/almAppendChildren.js | 32 +- core/src/js/helpers/queryParams.js | 161 +++++++--- 7 files changed, 336 insertions(+), 385 deletions(-) delete mode 100755 core/src/js/helpers/almAppendChild.js diff --git a/ajax-load-more.php b/ajax-load-more.php index bdb0e86..931d6cc 100755 --- a/ajax-load-more.php +++ b/ajax-load-more.php @@ -20,8 +20,10 @@ - TODO: -- Remove the create fetching in all addons/extensions. -- Remove all functions and helpers for ALMCache::get_cache_file() +- Remove the create fetching in all addons/extensions. [DONE] +- Remove all functions and helpers for ALMCache::get_cache_file() [DONE] +- Fix FILTER_SANITIZE_STRING deprecation notices in PHP 8.1. Possibly use @FILTER_SANITIZE_STRING to silence errors. + ADD-ON Updates: - FILTERS: @@ -31,6 +33,7 @@ - Comments [1.2.1] - Single Posts [1.5.5] - Elementor [1.1.4] +- WooCommerce [1.2.2] Extension Updates @@ -53,9 +56,6 @@ - Soltion for target loading cache. Working with Repeater Template. - Users [DONE] -- Update cache admin screen. Expand/Collapse files. -- Ensure backward compatibility. - Issues: - ACF not working with Paging - https://wpdev.local/acf-repeater-field/ @@ -539,13 +539,14 @@ public function alm_query_posts() { // CTA Add-on. $cta = false; $cta_data = isset( $params['cta'] ) ? $params['cta'] : false; + if ( $cta_data ) { $cta = true; $cta_position = isset( $cta_data['cta_position'] ) ? $cta_data['cta_position'] : 'before:1'; $cta_position_array = explode( ':', $cta_position ); $cta_pos = (string) $cta_position_array[0]; - $cta_val = (string) $cta_position_array[1]; $cta_pos = $cta_pos !== 'after' ? 'before' : $cta_pos; + $cta_val = (string) $cta_position_array[1]; $cta_repeater = isset( $cta_data['cta_repeater'] ) ? $cta_data['cta_repeater'] : 'null'; $cta_theme_repeater = isset( $cta_data['cta_theme_repeater'] ) ? sanitize_file_name( $cta_data['cta_theme_repeater'] ) : 'null'; } @@ -659,11 +660,8 @@ public function alm_query_posts() { $alm_current = 0; $alm_has_cta = false; - $cta_array = []; - if ( $cta && has_action( 'alm_cta_pos_array' ) ) { - // Build CTA Position Array. - $cta_array = apply_filters( 'alm_cta_pos_array', $seo_start_page, $page, $posts_per_page, $alm_post_count, $cta_val, $paging ); - } + // Build CTA Position Array. + $cta_array = $cta && has_action( 'alm_cta_pos_array' ) ? $cta_array = apply_filters( 'alm_cta_pos_array', $seo_start_page, $page, $posts_per_page, $alm_post_count, $cta_val, $paging ) : []; ob_start(); @@ -676,7 +674,7 @@ public function alm_query_posts() { $alm_item = ( $alm_page_count * $posts_per_page ) - $posts_per_page + $alm_loop_count; // Call to Action [Before]. - if ( $cta && has_action( 'alm_cta_inc' ) && $cta_pos === 'before' && in_array( (string) $alm_current, $cta_array, true ) ) { + if ( $cta && has_action( 'alm_cta_inc' ) && $cta_pos === 'before' && in_array( $alm_current, $cta_array ) ) { // phpcs:ignore do_action( 'alm_cta_inc', $cta_repeater, $cta_theme_repeater, $alm_found_posts, $alm_page, $alm_item, $alm_current, false, $args ); $alm_has_cta = true; } @@ -685,7 +683,7 @@ public function alm_query_posts() { alm_loop( $repeater, $type, $theme_repeater, $alm_found_posts, $alm_page, $alm_item, $alm_current, $args, false ); // Call to Action [After]. - if ( $cta && has_action( 'alm_cta_inc' ) && $cta_pos === 'after' && in_array( (string) $alm_current, $cta_array, true ) ) { + if ( $cta && has_action( 'alm_cta_inc' ) && $cta_pos === 'after' && in_array( $alm_current, $cta_array ) ) { // phpcs:ignore do_action( 'alm_cta_inc', $cta_repeater, $cta_theme_repeater, $alm_found_posts, $alm_page, $alm_item, $alm_current, false, $args ); $alm_has_cta = true; } diff --git a/core/dist/js/ajax-load-more.js b/core/dist/js/ajax-load-more.js index 3e87100..9b9e098 100644 --- a/core/dist/js/ajax-load-more.js +++ b/core/dist/js/ajax-load-more.js @@ -1967,8 +1967,8 @@ var alm_is_filtering = false; } // CTA add-on - alm.addons.cta = alm.listing.dataset.cta ? alm.listing.dataset.cta : false; - if (alm.addons.cta === 'true') { + alm.addons.cta = alm.listing.dataset.cta && alm.listing.dataset.cta === 'true' ? true : false; + if (alm.addons.cta) { alm.addons.cta_position = alm.listing.dataset.ctaPosition; alm.addons.cta_repeater = alm.listing.dataset.ctaRepeater; alm.addons.cta_theme_repeater = alm.listing.dataset.ctaThemeRepeater; @@ -2402,128 +2402,28 @@ var alm_is_filtering = false; */ alm.AjaxLoadMore.ajax = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { var queryType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'standard'; - var action, params, cache; + var params, cache; return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: - action = 'alm_get_posts'; // Default action - - // ACF Params - - alm.acf_array = ''; - if (alm.extensions.acf) { - // Custom query for the Repeater / Gallery / Flexible Content field types - if (alm.extensions.acf_field_type !== 'relationship') { - action = 'alm_acf'; - } - alm.acf_array = { - acf: 'true', - post_id: alm.extensions.acf_post_id, - field_type: alm.extensions.acf_field_type, - field_name: alm.extensions.acf_field_name, - parent_field_name: alm.extensions.acf_parent_field_name - }; - } - - // Term Query Params - alm.term_query_array = ''; - if (alm.extensions.term_query) { - action = 'alm_get_terms'; - alm.term_query_array = { - term_query: 'true', - taxonomy: alm.extensions.term_query_taxonomy, - hide_empty: alm.extensions.term_query_hide_empty, - number: alm.extensions.term_query_number - }; - } - - // Nextpage Params - alm.nextpage_array = ''; - if (alm.addons.nextpage) { - action = 'alm_nextpage'; - alm.nextpage_array = { - nextpage: 'true', - urls: alm.addons.nextpage_urls, - scroll: alm.addons.nextpage_scroll, - pageviews: alm.addons.nextpage_pageviews, - post_id: alm.addons.nextpage_post_id, - startpage: alm.addons.nextpage_startpage, - nested: alm.nested - }; - } - - // Previous Post Params - alm.single_post_array = ''; - if (alm.addons.single_post) { - alm.single_post_array = { - single_post: 'true', - id: alm.addons.single_post_id, - slug: alm.addons.single_post_slug - }; - } - - // Comment Params - alm.comments_array = ''; - if (alm.addons.comments === 'true') { - action = 'alm_comments'; - alm.posts_per_page = alm.addons.comments_per_page; - alm.comments_array = { - comments: 'true', - post_id: alm.addons.comments_post_id, - per_page: alm.addons.comments_per_page, - type: alm.addons.comments_type, - style: alm.addons.comments_style, - template: alm.addons.comments_template, - callback: alm.addons.comments_callback - }; - } - - // Users Params - alm.users_array = ''; - if (alm.addons.users) { - action = 'alm_users'; - alm.users_array = { - users: 'true', - role: alm.listing.dataset.usersRole, - include: alm.listing.dataset.usersInclude, - exclude: alm.listing.dataset.usersExclude, - per_page: alm.posts_per_page, - order: alm.listing.dataset.usersOrder, - orderby: alm.listing.dataset.usersOrderby - }; - } - - // CTA Params - alm.cta_array = ''; - if (alm.addons.cta === 'true') { - alm.cta_array = { - cta: 'true', - cta_position: alm.addons.cta_position, - cta_repeater: alm.addons.cta_repeater, - cta_theme_repeater: alm.addons.cta_theme_repeater - }; - } - - // Dispatch Ajax request. - if (!alm.extensions.restapi) { - _context.next = 19; + _context.next = 4; break; } // Rest API. alm.AjaxLoadMore.restapi(alm); - _context.next = 24; + _context.next = 9; break; - case 19: + case 4: // Standard ALM. - params = (0, _queryParams.getAjaxParams)(alm, action, queryType); - _context.next = 22; + params = (0, _queryParams.getAjaxParams)(alm, queryType); + _context.next = 7; return (0, _cache.getCache)(alm, Object.assign({}, params)); - case 22: + case 7: cache = _context.sent; if (cache) { @@ -2532,7 +2432,7 @@ var alm_is_filtering = false; alm.AjaxLoadMore.adminajax(params, queryType); } - case 24: + case 9: case 'end': return _context.stop(); } @@ -2637,8 +2537,6 @@ var alm_is_filtering = false; * Send request to the WP REST API * * @param {object} alm The Ajax Load More object. - * @param {string} action The Ajax action. - * @param {string} queryType The type of Ajax request (standard/totalposts). * @since 5.0.0 */ alm.AjaxLoadMore.restapi = function (alm) { @@ -2861,7 +2759,7 @@ var alm_is_filtering = false; isPaged = true; // Call to Actions - if (alm.addons.cta === 'true') { + if (alm.addons.cta) { posts_per_page = posts_per_page + 1; // Add 1 to posts_per_page for CTAs pages = Math.ceil(total / posts_per_page); // Update pages let with new posts_per_page total = pages + total; // Get new total w/ CTAs added @@ -4416,10 +4314,10 @@ var click = exports.click = function click() { /***/ }), -/***/ "./core/src/js/helpers/almAppendChild.js": -/*!***********************************************!*\ - !*** ./core/src/js/helpers/almAppendChild.js ***! - \***********************************************/ +/***/ "./core/src/js/helpers/almAppendChildren.js": +/*!**************************************************!*\ + !*** ./core/src/js/helpers/almAppendChildren.js ***! + \**************************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { @@ -4429,8 +4327,32 @@ var click = exports.click = function click() { Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = almAppendChildren; +exports.almAppendChild = almAppendChild; var nodeNameArray = ['#text', '#comment']; +/** + * Loop array of elements and append to target + * + * @param {Element} target | Target element to append items + * @param {Element} array | An array of elements + * @param {string} transition | The transiton + * @since 5.0 + */ +function almAppendChildren() { + var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + var array = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var transition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'fade'; + + if (!target || !array) { + return false; + } + for (var i = 0; i < array.length; i++) { + var element = array[i]; + almAppendChild(target, element, transition); + } +} + /** * Append a child element to a container * @@ -4439,7 +4361,7 @@ var nodeNameArray = ['#text', '#comment']; * @param {string} transition | The transiton * @since 5.0 */ -var almAppendChild = function almAppendChild() { +function almAppendChild() { var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var element = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; var transition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'fade'; @@ -4457,57 +4379,8 @@ var almAppendChild = function almAppendChild() { } target.appendChild(element); } -}; -exports.default = almAppendChild; - -/***/ }), - -/***/ "./core/src/js/helpers/almAppendChildren.js": -/*!**************************************************!*\ - !*** ./core/src/js/helpers/almAppendChildren.js ***! - \**************************************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _almAppendChild = __webpack_require__(/*! ./almAppendChild */ "./core/src/js/helpers/almAppendChild.js"); - -var _almAppendChild2 = _interopRequireDefault(_almAppendChild); - -function _interopRequireDefault(obj) { - return obj && obj.__esModule ? obj : { default: obj }; } -/** - * Loop array of elements and append to target - * - * @param {Element} target | Target element to append items - * @param {Element} array | An array of elements - * @param {string} transition | The transiton - * @since 5.0 - */ - -var almAppendChildren = function almAppendChildren() { - var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - var array = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; - var transition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'fade'; - - if (!target || !array) { - return false; - } - for (var i = 0; i < array.length; i++) { - var element = array[i]; - (0, _almAppendChild2.default)(target, element, transition); - } -}; -exports.default = almAppendChildren; - /***/ }), /***/ "./core/src/js/helpers/almDomParser.js": @@ -5245,6 +5118,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.getAjaxParams = getAjaxParams; +exports.getTypeParams = getTypeParams; exports.getRestAPIParams = getRestAPIParams; var _cache = __webpack_require__(/*! ../addons/cache */ "./core/src/js/addons/cache.js"); @@ -5253,15 +5127,18 @@ var _cache = __webpack_require__(/*! ../addons/cache */ "./core/src/js/addons/ca * Build the data object to send with the Ajax request. * * @param {object} alm The ALM object. - * @param {string} action The HTTP action. * @param {string} queryType The query type. * @return {object} The data object. * @since 3.6 */ -function getAjaxParams(alm, action, queryType) { +function getAjaxParams(alm, queryType) { + var addons = alm.addons, + extensions = alm.extensions; + // Defaults + var data = { - action: action, + action: 'alm_get_posts', query_type: queryType, id: alm.id, post_id: parseInt(alm.post_id), @@ -5276,45 +5153,55 @@ function getAjaxParams(alm, action, queryType) { }; // Addons & Extensions - if (alm.theme_repeater) { - data.theme_repeater = alm.theme_repeater; + + if (extensions.acf) { + data.acf = getTypeParams(alm, 'acf'); + if (extensions.acf_field_type !== 'relationship') { + data.action = 'alm_acf'; + } } - if (alm.addons.filters) { - data.filters = alm.addons.filters; - data.filters_startpage = alm.addons.filters_startpage; - data.filters_target = alm.addons.filters_target; - data.facets = alm.facets; + if (addons.comments === 'true') { + data.comments = getTypeParams(alm, 'comments'); + data.posts_per_page = addons.comments_per_page; + data.action = 'alm_comments'; } - if (alm.addons.paging) { - data.paging = alm.addons.paging; + if (addons.cta) { + data.cta = getTypeParams(alm, 'cta'); } - if (alm.addons.preloaded === 'true') { - data.preloaded = alm.addons.preloaded; - data.preloaded_amount = parseInt(alm.addons.preloaded_amount); + if (addons.filters) { + data.filters = addons.filters; + data.filters_startpage = addons.filters_startpage; + data.filters_target = addons.filters_target; + data.facets = alm.facets; } - if (alm.acf_array) { - data.acf = alm.acf_array; + if (addons.nextpage) { + data.nextpage = getTypeParams(alm, 'nextpage'); + data.action = 'alm_nextpage'; } - if (alm.term_query_array) { - data.term_query = alm.term_query_array; + if (addons.paging) { + data.paging = addons.paging; } - if (alm.cta_array) { - data.cta = alm.cta_array; + if (addons.preloaded === 'true') { + data.preloaded = addons.preloaded; + data.preloaded_amount = parseInt(addons.preloaded_amount); } - if (alm.comments_array) { - data.comments = alm.comments_array; + if (addons.single_post) { + data.single_post = getTypeParams(alm, 'single_post'); } - if (alm.nextpage_array) { - data.nextpage = alm.nextpage_array; + if (extensions.term_query) { + data.term_query = getTypeParams(alm, 'term_query'); + data.action = 'alm_get_terms'; } - if (alm.single_post_array) { - data.single_post = alm.single_post_array; + if (alm.theme_repeater) { + data.theme_repeater = alm.theme_repeater; } - if (alm.users_array) { - data.users = alm.users_array; + if (alm.addons.users) { + data.users = getTypeParams(alm, 'users'); + data.action = 'alm_users'; } - // Query data + // Query Data Params + if (alm.listing.dataset.lang) { data.lang = alm.listing.dataset.lang; } @@ -5415,16 +5302,96 @@ function getAjaxParams(alm, action, queryType) { data.vars = escape(alm.listing.dataset.vars); } - // Set Cache params. - if (alm.addons.cache) { - data.cache_id = alm.addons.cache_id; - data.cache_logged_in = alm.addons.cache_logged_in; + // Cache Params + + if (addons.cache) { + data.cache_id = addons.cache_id; + data.cache_logged_in = addons.cache_logged_in; data.cache_slug = (0, _cache.getCacheSlug)(alm, data); } return data; } +/** + * Build the query params for content types. + * + * @param {object} alm The ALM object. + * @param {string} type The query type. + * @return {object} The query params. + */ +function getTypeParams(alm, type) { + var addons = alm.addons, + extensions = alm.extensions; + + switch (type) { + case 'acf': + return { + acf: 'true', + post_id: extensions.acf_post_id, + field_type: extensions.acf_field_type, + field_name: extensions.acf_field_name, + parent_field_name: extensions.acf_parent_field_name + }; + + case 'comments': + return { + comments: 'true', + post_id: addons.comments_post_id, + per_page: addons.comments_per_page, + type: addons.comments_type, + style: addons.comments_style, + template: addons.comments_template, + callback: addons.comments_callback + }; + + case 'cta': + return { + cta: 'true', + cta_position: addons.cta_position, + cta_repeater: addons.cta_repeater, + cta_theme_repeater: addons.cta_theme_repeater + }; + + case 'nextpage': + return { + nextpage: 'true', + urls: addons.nextpage_urls, + scroll: addons.nextpage_scroll, + pageviews: addons.nextpage_pageviews, + post_id: addons.nextpage_post_id, + startpage: addons.nextpage_startpage, + nested: alm.nested + }; + + case 'single_posts': + return { + single_post: 'true', + id: addons.single_post_id, + slug: addons.single_post_slug + }; + + case 'term_query': + return { + term_query: 'true', + taxonomy: extensions.term_query_taxonomy, + hide_empty: extensions.term_query_hide_empty, + number: extensions.term_query_number + }; + + case 'users': + return { + users: 'true', + role: alm.listing.dataset.usersRole, + include: alm.listing.dataset.usersInclude, + exclude: alm.listing.dataset.usersExclude, + per_page: alm.posts_per_page, + order: alm.listing.dataset.usersOrder, + orderby: alm.listing.dataset.usersOrderby + }; + } +} + /** * Build the REST API data object to send with REST API request. * diff --git a/core/src/js/addons/cache.js b/core/src/js/addons/cache.js index c578487..31b36cd 100644 --- a/core/src/js/addons/cache.js +++ b/core/src/js/addons/cache.js @@ -66,7 +66,7 @@ export async function createCache(alm, data, name) { */ export async function getCache(alm, params) { if (!alm.addons.cache || (alm.addons.cache && alm.addons.cache_logged_in)) { - // Exit if not cache or cache is enabled but user is logged in with the setting checked. + // Exit if not cache or cache is enabled but user is logged in with the no-cache setting checked. return false; } diff --git a/core/src/js/ajax-load-more.js b/core/src/js/ajax-load-more.js index 289d3b2..7add10c 100755 --- a/core/src/js/ajax-load-more.js +++ b/core/src/js/ajax-load-more.js @@ -196,8 +196,8 @@ let alm_is_filtering = false; } // CTA add-on - alm.addons.cta = alm.listing.dataset.cta ? alm.listing.dataset.cta : false; - if (alm.addons.cta === 'true') { + alm.addons.cta = alm.listing.dataset.cta && alm.listing.dataset.cta === 'true' ? true : false; + if (alm.addons.cta) { alm.addons.cta_position = alm.listing.dataset.ctaPosition; alm.addons.cta_repeater = alm.listing.dataset.ctaRepeater; alm.addons.cta_theme_repeater = alm.listing.dataset.ctaThemeRepeater; @@ -632,110 +632,13 @@ let alm_is_filtering = false; * @since 2.6.0 */ alm.AjaxLoadMore.ajax = async function (queryType = 'standard') { - let action = 'alm_get_posts'; // Default action - - // ACF Params - alm.acf_array = ''; - if (alm.extensions.acf) { - // Custom query for the Repeater / Gallery / Flexible Content field types - if (alm.extensions.acf_field_type !== 'relationship') { - action = 'alm_acf'; - } - alm.acf_array = { - acf: 'true', - post_id: alm.extensions.acf_post_id, - field_type: alm.extensions.acf_field_type, - field_name: alm.extensions.acf_field_name, - parent_field_name: alm.extensions.acf_parent_field_name, - }; - } - - // Term Query Params - alm.term_query_array = ''; - if (alm.extensions.term_query) { - action = 'alm_get_terms'; - alm.term_query_array = { - term_query: 'true', - taxonomy: alm.extensions.term_query_taxonomy, - hide_empty: alm.extensions.term_query_hide_empty, - number: alm.extensions.term_query_number, - }; - } - - // Nextpage Params - alm.nextpage_array = ''; - if (alm.addons.nextpage) { - action = 'alm_nextpage'; - alm.nextpage_array = { - nextpage: 'true', - urls: alm.addons.nextpage_urls, - scroll: alm.addons.nextpage_scroll, - pageviews: alm.addons.nextpage_pageviews, - post_id: alm.addons.nextpage_post_id, - startpage: alm.addons.nextpage_startpage, - nested: alm.nested, - }; - } - - // Previous Post Params - alm.single_post_array = ''; - if (alm.addons.single_post) { - alm.single_post_array = { - single_post: 'true', - id: alm.addons.single_post_id, - slug: alm.addons.single_post_slug, - }; - } - - // Comment Params - alm.comments_array = ''; - if (alm.addons.comments === 'true') { - action = 'alm_comments'; - alm.posts_per_page = alm.addons.comments_per_page; - alm.comments_array = { - comments: 'true', - post_id: alm.addons.comments_post_id, - per_page: alm.addons.comments_per_page, - type: alm.addons.comments_type, - style: alm.addons.comments_style, - template: alm.addons.comments_template, - callback: alm.addons.comments_callback, - }; - } - - // Users Params - alm.users_array = ''; - if (alm.addons.users) { - action = 'alm_users'; - alm.users_array = { - users: 'true', - role: alm.listing.dataset.usersRole, - include: alm.listing.dataset.usersInclude, - exclude: alm.listing.dataset.usersExclude, - per_page: alm.posts_per_page, - order: alm.listing.dataset.usersOrder, - orderby: alm.listing.dataset.usersOrderby, - }; - } - - // CTA Params - alm.cta_array = ''; - if (alm.addons.cta === 'true') { - alm.cta_array = { - cta: 'true', - cta_position: alm.addons.cta_position, - cta_repeater: alm.addons.cta_repeater, - cta_theme_repeater: alm.addons.cta_theme_repeater, - }; - } - // Dispatch Ajax request. if (alm.extensions.restapi) { // Rest API. alm.AjaxLoadMore.restapi(alm); } else { // Standard ALM. - const params = getAjaxParams(alm, action, queryType); + const params = getAjaxParams(alm, queryType); const cache = await getCache(alm, Object.assign({}, params)); if (cache) { alm.AjaxLoadMore.success(cache); @@ -819,8 +722,6 @@ let alm_is_filtering = false; * Send request to the WP REST API * * @param {object} alm The Ajax Load More object. - * @param {string} action The Ajax action. - * @param {string} queryType The type of Ajax request (standard/totalposts). * @since 5.0.0 */ alm.AjaxLoadMore.restapi = function (alm) { @@ -1030,7 +931,7 @@ let alm_is_filtering = false; isPaged = true; // Call to Actions - if (alm.addons.cta === 'true') { + if (alm.addons.cta) { posts_per_page = posts_per_page + 1; // Add 1 to posts_per_page for CTAs pages = Math.ceil(total / posts_per_page); // Update pages let with new posts_per_page total = pages + total; // Get new total w/ CTAs added diff --git a/core/src/js/helpers/almAppendChild.js b/core/src/js/helpers/almAppendChild.js deleted file mode 100755 index d740d1a..0000000 --- a/core/src/js/helpers/almAppendChild.js +++ /dev/null @@ -1,26 +0,0 @@ -const nodeNameArray = ['#text', '#comment']; - -/** - * Append a child element to a container - * - * @param {Element} target | Target element to append items - * @param {Element} element | The element to append - * @param {string} transition | The transiton - * @since 5.0 - */ -const almAppendChild = function (target = null, element = null, transition = 'fade') { - if (!target || !element) { - return false; - } - - // Do not append elements that are not actual element nodes (i.e. #text node) - // Add item if not in exclude array - if (nodeNameArray.indexOf(element.nodeName.toLowerCase()) === -1) { - if (transition === 'masonry') { - // If Masonry, opacity = zero - element.style.opacity = 0; - } - target.appendChild(element); - } -}; -export default almAppendChild; diff --git a/core/src/js/helpers/almAppendChildren.js b/core/src/js/helpers/almAppendChildren.js index 76867c1..4b324f9 100755 --- a/core/src/js/helpers/almAppendChildren.js +++ b/core/src/js/helpers/almAppendChildren.js @@ -1,4 +1,4 @@ -import almAppendChild from './almAppendChild'; +const nodeNameArray = ['#text', '#comment']; /** * Loop array of elements and append to target @@ -8,8 +8,7 @@ import almAppendChild from './almAppendChild'; * @param {string} transition | The transiton * @since 5.0 */ - -const almAppendChildren = function (target = null, array = null, transition = 'fade') { +export default function almAppendChildren(target = null, array = null, transition = 'fade') { if (!target || !array) { return false; } @@ -17,5 +16,28 @@ const almAppendChildren = function (target = null, array = null, transition = 'f let element = array[i]; almAppendChild(target, element, transition); } -}; -export default almAppendChildren; +} + +/** + * Append a child element to a container + * + * @param {Element} target | Target element to append items + * @param {Element} element | The element to append + * @param {string} transition | The transiton + * @since 5.0 + */ +export function almAppendChild(target = null, element = null, transition = 'fade') { + if (!target || !element) { + return false; + } + + // Do not append elements that are not actual element nodes (i.e. #text node) + // Add item if not in exclude array + if (nodeNameArray.indexOf(element.nodeName.toLowerCase()) === -1) { + if (transition === 'masonry') { + // If Masonry, opacity = zero + element.style.opacity = 0; + } + target.appendChild(element); + } +} diff --git a/core/src/js/helpers/queryParams.js b/core/src/js/helpers/queryParams.js index cd3ab76..13a2817 100755 --- a/core/src/js/helpers/queryParams.js +++ b/core/src/js/helpers/queryParams.js @@ -4,15 +4,16 @@ import { getCacheSlug } from '../addons/cache'; * Build the data object to send with the Ajax request. * * @param {object} alm The ALM object. - * @param {string} action The HTTP action. * @param {string} queryType The query type. * @return {object} The data object. * @since 3.6 */ -export function getAjaxParams(alm, action, queryType) { +export function getAjaxParams(alm, queryType) { + const { addons, extensions } = alm; + // Defaults const data = { - action: action, + action: 'alm_get_posts', query_type: queryType, id: alm.id, post_id: parseInt(alm.post_id), @@ -27,45 +28,55 @@ export function getAjaxParams(alm, action, queryType) { }; // Addons & Extensions - if (alm.theme_repeater) { - data.theme_repeater = alm.theme_repeater; - } - if (alm.addons.filters) { - data.filters = alm.addons.filters; - data.filters_startpage = alm.addons.filters_startpage; - data.filters_target = alm.addons.filters_target; + + if (extensions.acf) { + data.acf = getTypeParams(alm, 'acf'); + if (extensions.acf_field_type !== 'relationship') { + data.action = 'alm_acf'; + } + } + if (addons.comments === 'true') { + data.comments = getTypeParams(alm, 'comments'); + data.posts_per_page = addons.comments_per_page; + data.action = 'alm_comments'; + } + if (addons.cta) { + data.cta = getTypeParams(alm, 'cta'); + } + if (addons.filters) { + data.filters = addons.filters; + data.filters_startpage = addons.filters_startpage; + data.filters_target = addons.filters_target; data.facets = alm.facets; } - if (alm.addons.paging) { - data.paging = alm.addons.paging; - } - if (alm.addons.preloaded === 'true') { - data.preloaded = alm.addons.preloaded; - data.preloaded_amount = parseInt(alm.addons.preloaded_amount); + if (addons.nextpage) { + data.nextpage = getTypeParams(alm, 'nextpage'); + data.action = 'alm_nextpage'; } - if (alm.acf_array) { - data.acf = alm.acf_array; + if (addons.paging) { + data.paging = addons.paging; } - if (alm.term_query_array) { - data.term_query = alm.term_query_array; + if (addons.preloaded === 'true') { + data.preloaded = addons.preloaded; + data.preloaded_amount = parseInt(addons.preloaded_amount); } - if (alm.cta_array) { - data.cta = alm.cta_array; + if (addons.single_post) { + data.single_post = getTypeParams(alm, 'single_post'); } - if (alm.comments_array) { - data.comments = alm.comments_array; + if (extensions.term_query) { + data.term_query = getTypeParams(alm, 'term_query'); + data.action = 'alm_get_terms'; } - if (alm.nextpage_array) { - data.nextpage = alm.nextpage_array; - } - if (alm.single_post_array) { - data.single_post = alm.single_post_array; + if (alm.theme_repeater) { + data.theme_repeater = alm.theme_repeater; } - if (alm.users_array) { - data.users = alm.users_array; + if (alm.addons.users) { + data.users = getTypeParams(alm, 'users'); + data.action = 'alm_users'; } - // Query data + // Query Data Params + if (alm.listing.dataset.lang) { data.lang = alm.listing.dataset.lang; } @@ -166,16 +177,94 @@ export function getAjaxParams(alm, action, queryType) { data.vars = escape(alm.listing.dataset.vars); } - // Set Cache params. - if (alm.addons.cache) { - data.cache_id = alm.addons.cache_id; - data.cache_logged_in = alm.addons.cache_logged_in; + // Cache Params + + if (addons.cache) { + data.cache_id = addons.cache_id; + data.cache_logged_in = addons.cache_logged_in; data.cache_slug = getCacheSlug(alm, data); } return data; } +/** + * Build the query params for content types. + * + * @param {object} alm The ALM object. + * @param {string} type The query type. + * @return {object} The query params. + */ +export function getTypeParams(alm, type) { + const { addons, extensions } = alm; + switch (type) { + case 'acf': + return { + acf: 'true', + post_id: extensions.acf_post_id, + field_type: extensions.acf_field_type, + field_name: extensions.acf_field_name, + parent_field_name: extensions.acf_parent_field_name, + }; + + case 'comments': + return { + comments: 'true', + post_id: addons.comments_post_id, + per_page: addons.comments_per_page, + type: addons.comments_type, + style: addons.comments_style, + template: addons.comments_template, + callback: addons.comments_callback, + }; + + case 'cta': + return { + cta: 'true', + cta_position: addons.cta_position, + cta_repeater: addons.cta_repeater, + cta_theme_repeater: addons.cta_theme_repeater, + }; + + case 'nextpage': + return { + nextpage: 'true', + urls: addons.nextpage_urls, + scroll: addons.nextpage_scroll, + pageviews: addons.nextpage_pageviews, + post_id: addons.nextpage_post_id, + startpage: addons.nextpage_startpage, + nested: alm.nested, + }; + + case 'single_posts': + return { + single_post: 'true', + id: addons.single_post_id, + slug: addons.single_post_slug, + }; + + case 'term_query': + return { + term_query: 'true', + taxonomy: extensions.term_query_taxonomy, + hide_empty: extensions.term_query_hide_empty, + number: extensions.term_query_number, + }; + + case 'users': + return { + users: 'true', + role: alm.listing.dataset.usersRole, + include: alm.listing.dataset.usersInclude, + exclude: alm.listing.dataset.usersExclude, + per_page: alm.posts_per_page, + order: alm.listing.dataset.usersOrder, + orderby: alm.listing.dataset.usersOrderby, + }; + } +} + /** * Build the REST API data object to send with REST API request. * From 4f2c83ba371fbdde72928673b8374d2c5c9b8851 Mon Sep 17 00:00:00 2001 From: Darren Cooney Date: Mon, 15 May 2023 09:49:35 -0400 Subject: [PATCH 08/18] Updated cache admin display --- admin/dist/css/admin.css | 471 ++++++++++++++-------------- admin/src/scss/admin.scss | 248 +-------------- admin/src/scss/partials/_cache.scss | 272 ++++++++++++++++ core/dist/js/ajax-load-more.js | 22 +- core/src/js/ajax-load-more.js | 22 +- 5 files changed, 529 insertions(+), 506 deletions(-) create mode 100644 admin/src/scss/partials/_cache.scss diff --git a/admin/dist/css/admin.css b/admin/dist/css/admin.css index 8f54ce7..f973066 100644 --- a/admin/dist/css/admin.css +++ b/admin/dist/css/admin.css @@ -1,3 +1,4 @@ +@charset "UTF-8"; @import '//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css'; /* This is the default Tooltipster theme (feel free to modify or duplicate and create multiple themes!): */ .tooltipster-default { border-radius: 3px; @@ -1543,6 +1544,240 @@ disabled look for disabled choices in the results dropdown text-decoration: none; } +.alm-cache { + /* Live Search */ + /* Directory Listing */ +} +.alm-cache .group .row { + overflow: visible; +} +.alm-cache .row:first-of-type { + margin-top: 0 !important; +} +.alm-cache h3.heading { + padding-right: 90px !important; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} +.alm-cache .alm-cache-search-wrap { + position: relative; + display: block; + margin: 0 0 15px; +} +.alm-cache .alm-cache-search-wrap input { + width: 100% !important; + margin: 0 !important; + padding: 13px 20px; + display: block; + font-size: 15px; + border-radius: 3px; + background-color: #f7f7f7; +} +.alm-cache .alm-cache-search-wrap i { + position: absolute; + right: 15px; + top: 50%; + -webkit-transform: translateY(-50%); + -ms-transform: translateY(-50%); + transform: translateY(-50%); + color: #ccc; + font-size: 16px; + z-index: 1; +} +.alm-cache .alm-cache-listing { + position: relative; +} +.alm-cache .alm-cache-listing .toggle-all { + right: 0; + top: -45px; +} +.alm-cache hr { + margin: 32px 0 25px; + border-top-color: #efefef; + border-bottom: none; +} +.alm-cache .alm-dir-listing { + border: 1px solid #e7e7e7; + border-radius: 3px; + overflow: hidden; + padding: 0; + margin: 10px 0 0; +} +.alm-cache .alm-dir-listing--nested { + padding: 0 15px 15px; +} +.alm-cache .alm-dir-listing--nested .alm-dir-listing { + margin: 0; +} +.alm-cache .alm-dir-listing.theme-repeaters { + padding: 15px; + margin: 0; +} +.alm-cache .alm-dir-listing.theme-repeaters ul { + border: none; + padding: 0; + margin: 0; +} +.alm-cache .alm-dir-listing.theme-repeaters i { + color: #ccc; + font-size: 1.1em; +} +.alm-cache .alm-dir-listing.deleting { + opacity: 0.5; + background: #fff url("../../img/loader-unlimited.gif") no-repeat center center; +} +.alm-cache .alm-dir-listing .dir-title { + margin: 0 0 5px; + position: relative; +} +.alm-cache .alm-dir-listing h3.heading { + padding-left: 40px !important; +} +.alm-cache .alm-dir-listing h3.heading:after { + content: "\f07c"; +} +.alm-cache .alm-dir-listing h3.heading.open:after { + content: "\f07b"; +} +.alm-cache .alm-dir-listing .dir-title .delete { + position: absolute; + right: 10px; + top: 10px; + font-weight: 400; + font-size: 13px; + text-decoration: none; + padding: 5px 12px; + border: 1px solid #e7e7e7; + color: #ccc; + border-radius: 3px; +} +.alm-cache .alm-dir-listing:hover .dir-title .delete { + border-color: #e7e7e7; + background-color: #fff; + color: #666; +} +.alm-cache .alm-dir-listing .dir-title .delete:hover { + background-color: #c94141; + border-color: #c94141; + color: #fff; +} +.alm-cache .alm-dir-listing .dir-title .delete:active { + -webkit-box-shadow: inset 0 2px 1px rgba(0, 0, 0, 0.2); + box-shadow: inset 0 2px 1px rgba(0, 0, 0, 0.2); +} +.alm-cache .cache-page-title { + font-size: 12px; + display: block; + width: 100%; + padding: 0 7px 10px; + font-weight: 700; + text-transform: uppercase; +} +.alm-cache .cache-page-wrap { + padding: 5px 12px 20px; +} +ß .alm-cache .cache-page-wrap ul { + max-height: 300px; + overflow-y: auto; + scroll-behavior: smooth; +} +.alm-cache .cache-full-path { + display: none; +} +.alm-cache .cache-full-path-button { + border: 1px solid #efefef; + border-radius: 3px; + background: #fff; + cursor: pointer; + margin: 0 2px 0 0; + text-align: left; + color: #878787; + font-size: 13px; + padding: 2px 4px; +} +.alm-cache .cache-full-path-button:hover, .alm-cache .cache-full-path-button:focus { + border-color: #e7e7e7; +} +.alm-cache .alm-dir-listing ul.cache-details { + display: block; + padding: 20px 15px 0; + margin: 0; + border: none; +} +.alm-cache .alm-dir-listing ul.cache-details li { + position: relative; + display: block; + width: 100%; + background: none; + padding: 0 10px 0 28px; + margin: 0 0 10px; +} +.alm-cache .alm-dir-listing ul.cache-details li i { + color: #999; + font-size: 16px; + position: absolute; + top: 1px; + left: 5px; +} +.alm-cache .alm-dir-listing ul.cache-details li a { + word-break: break-word; +} +.alm-cache .dir-empty { + margin-top: 10px; +} +.alm-cache .dir-empty, +.alm-cache .cache-cleared { + background-color: #ffffe8; + border: 1px solid #e4e4c8; + padding: 20px; + display: block; + color: #222; + text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.2); +} +.alm-cache .cache-cleared { + margin: 0 0 20px; + background-color: #e0f5ff; + border-color: #bad0da; + color: #666; +} +.alm-cache .cache-cleared i { + color: #111; + margin: 0 5px 0 0; +} +.alm-cache .cache-cleared .remove { + float: right; + font-size: 12px; + font-weight: 600; +} +.alm-cache p.cache-stats { + min-height: 38px; + line-height: 37px; + display: block; + padding: 0; + margin: 0; +} +.alm-cache p.cache-stats span { + display: inline-block; + width: 38px; + height: 38px; + line-height: 36px; + text-align: center; + margin: 0 9px 0 0; + font-weight: 700; + font-size: 15px; + border-radius: 2px; + background: #a4a5e2; + background: -webkit-gradient(linear, left top, left bottom, from(#a4a5e2), color-stop(50%, #9ea0d9), color-stop(51%, #8d8fce), to(#a4a5e2)); + background: linear-gradient(to bottom, #a4a5e2 0%, #9ea0d9 50%, #8d8fce 51%, #a4a5e2 100%); + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#a4a5e2", endColorstr="#a4a5e2", GradientType=0); + border: 1px solid #8586be; + -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15); + box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15); + color: #fff; + text-shadow: -1px -1px 0 rgba(0, 0, 0, 0.1); +} + .woocommerce-help--item { width: 100%; display: -webkit-box; @@ -4478,243 +4713,9 @@ span.cnkt-button.installed i, text-decoration: none; } -/* -* Cache -* @since 2.6.0 -*/ -.alm-cache { - /* Live Search */ - /* Directory Listing */ -} -.alm-cache .group .row { - overflow: visible; -} -.alm-cache .row:first-of-type { - margin-top: 0 !important; -} -.alm-cache h3.heading { - padding-right: 90px !important; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; -} -.alm-cache .alm-cache-search-wrap { - position: relative; - display: block; - margin: 0 0 15px; -} -.alm-cache .alm-cache-search-wrap input { - width: 100% !important; - margin: 0 !important; - padding: 13px 20px; - display: block; - font-size: 15px; - border-radius: 3px; - background-color: #f7f7f7; -} -.alm-cache .alm-cache-search-wrap i { - position: absolute; - right: 15px; - top: 50%; - -webkit-transform: translateY(-50%); - -ms-transform: translateY(-50%); - transform: translateY(-50%); - color: #ccc; - font-size: 16px; - z-index: 1; -} -.alm-cache .alm-cache-listing { - position: relative; -} -.alm-cache .alm-cache-listing .toggle-all { - right: 0; - top: -45px; -} -.alm-cache hr { - margin: 32px 0 25px; - border-top-color: #efefef; - border-bottom: none; -} -.alm-cache .alm-dir-listing { - border: 1px solid #e7e7e7; - border-radius: 3px; - overflow: hidden; - padding: 0; - margin: 10px 0 0; -} -.alm-cache .alm-dir-listing--nested { - padding: 0 15px 15px; -} -.alm-cache .alm-dir-listing--nested .alm-dir-listing { - margin: 0; -} -.alm-cache .alm-dir-listing.theme-repeaters { - padding: 15px; - margin: 0; -} -.alm-cache .alm-dir-listing.theme-repeaters ul { - border: none; - padding: 0; - margin: 0; -} -.alm-cache .alm-dir-listing.theme-repeaters i { - color: #ccc; - font-size: 1.1em; -} -.alm-cache .alm-dir-listing.deleting { - opacity: 0.5; - background: #fff url("../../img/loader-unlimited.gif") no-repeat center center; -} -.alm-cache .alm-dir-listing .dir-title { - margin: 0 0 5px; - position: relative; -} -.alm-cache .alm-dir-listing h3.heading { - padding-left: 40px !important; -} -.alm-cache .alm-dir-listing h3.heading:after { - content: "\f07c"; -} -.alm-cache .alm-dir-listing h3.heading.open:after { - content: "\f07b"; -} -.alm-cache .alm-dir-listing .dir-title .delete { - position: absolute; - right: 10px; - top: 10px; - font-weight: 400; - font-size: 13px; - text-decoration: none; - padding: 5px 12px; - border: 1px solid #e7e7e7; - color: #ccc; - border-radius: 3px; -} -.alm-cache .alm-dir-listing:hover .dir-title .delete { - border-color: #e7e7e7; - background-color: #fff; - color: #666; -} -.alm-cache .alm-dir-listing .dir-title .delete:hover { - background-color: #c94141; - border-color: #c94141; - color: #fff; -} -.alm-cache .alm-dir-listing .dir-title .delete:active { - -webkit-box-shadow: inset 0 2px 1px rgba(0, 0, 0, 0.2); - box-shadow: inset 0 2px 1px rgba(0, 0, 0, 0.2); -} -.alm-cache .cache-page-title { - font-size: 12px; - display: block; - width: 100%; - padding: 0 7px 10px; - font-weight: 700; - text-transform: uppercase; -} -.alm-cache .cache-page-wrap { - padding: 0 10px 20px; -} -.alm-cache .cache-full-path { - display: none; -} -.alm-cache .cache-full-path-button { - border: 1px solid #efefef; - border-radius: 3px; - background: #fff; - cursor: pointer; - margin: 0 2px 0 0; - text-align: left; - color: #878787; - font-size: 13px; - padding: 2px 4px; -} -.alm-cache .cache-full-path-button:hover, .alm-cache .cache-full-path-button:focus { - border-color: #e7e7e7; -} -.alm-cache .alm-dir-listing ul.cache-details { - display: block; - padding: 15px 10px 5px; - margin: 0; - border: none; -} -.alm-cache .alm-dir-listing ul.cache-details li { - position: relative; - display: block; - width: 100%; - background: none; - padding: 0 10px 0 28px; - margin: 0 0 10px; -} -.alm-cache .alm-dir-listing ul.cache-details li i { - color: #999; - font-size: 16px; - position: absolute; - top: 1px; - left: 5px; -} -.alm-cache .alm-dir-listing ul.cache-details li a { - word-break: break-word; -} -.alm-cache .dir-empty { - margin-top: 10px; -} -.alm-cache .dir-empty, -.alm-cache .cache-cleared { - background-color: #ffffe8; - border: 1px solid #e4e4c8; - padding: 20px; - display: block; - color: #222; - text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.2); -} -.alm-cache .cache-cleared { - margin: 0 0 20px; - background-color: #e0f5ff; - border-color: #bad0da; - color: #666; -} -.alm-cache .cache-cleared i { - color: #111; - margin: 0 5px 0 0; -} -.alm-cache .cache-cleared .remove { - float: right; - font-size: 12px; - font-weight: 600; -} -.alm-cache p.cache-stats { - min-height: 38px; - line-height: 37px; - display: block; +.alm-dir-listing ul { padding: 0; margin: 0; -} -.alm-cache p.cache-stats span { - display: inline-block; - width: 38px; - height: 38px; - line-height: 36px; - text-align: center; - margin: 0 9px 0 0; - font-weight: 700; - font-size: 15px; - border-radius: 2px; - background: #a4a5e2; - background: -webkit-gradient(linear, left top, left bottom, from(#a4a5e2), color-stop(50%, #9ea0d9), color-stop(51%, #8d8fce), to(#a4a5e2)); - background: linear-gradient(to bottom, #a4a5e2 0%, #9ea0d9 50%, #8d8fce 51%, #a4a5e2 100%); - filter: progid:DXImageTransform.Microsoft.gradient( startColorstr="#a4a5e2", endColorstr="#a4a5e2",GradientType=0 ); - border: 1px solid #8586be; - -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15); - box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15); - color: #fff; - text-shadow: -1px -1px 0 rgba(0, 0, 0, 0.1); -} - -.alm-dir-listing ul { - padding: 20px 0 0; - margin: 10px 0 0; - border-top: 1px solid #e7e7e7; display: -webkit-box; display: -ms-flexbox; display: flex; diff --git a/admin/src/scss/admin.scss b/admin/src/scss/admin.scss index eaba3f9..a62036d 100644 --- a/admin/src/scss/admin.scss +++ b/admin/src/scss/admin.scss @@ -10,6 +10,7 @@ @import 'partials/alm-settings-feedback'; @import 'partials/select2'; @import 'partials/shortcode-builder'; +@import 'partials/cache'; @import 'partials/woocommerce'; @import 'partials/builder-option-toggle'; @import 'partials/template-tags'; @@ -2484,254 +2485,11 @@ span.cnkt-button.installed i, } } -/* -* Cache -* @since 2.6.0 -*/ -.alm-cache { - .group .row { - overflow: visible; - } - .row { - &:first-of-type { - margin-top: 0 !important; - } - } - - h3.heading { - padding-right: 90px !important; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - } - - /* Live Search */ - .alm-cache-search-wrap { - position: relative; - display: block; - margin: 0 0 15px; - input { - width: 100% !important; - margin: 0 !important; - padding: 13px 20px; - display: block; - font-size: 15px; - border-radius: $radius; - background-color: $light_grey; - } - i { - position: absolute; - right: 15px; - top: 50%; - transform: translateY(-50%); - color: #ccc; - font-size: 16px; - z-index: 1; - } - } - - .alm-cache-listing { - position: relative; - .toggle-all { - right: 0; - top: -45px; - } - } - - hr { - margin: 32px 0 25px; - border-top-color: $light_border; - border-bottom: none; - } - - /* Directory Listing */ - .alm-dir-listing { - border: 1px solid $border; - border-radius: $radius; - overflow: hidden; - padding: 0; - margin: 10px 0 0; - &--nested { - padding: 0 15px 15px; - .alm-dir-listing { - margin: 0; - } - } - &.theme-repeaters { - padding: 15px; - margin: 0; - ul { - border: none; - padding: 0; - margin: 0; - } - i { - color: #ccc; - font-size: 1.1em; - } - } - } - - .alm-dir-listing.deleting { - opacity: 0.5; - background: #fff url('../../img/loader-unlimited.gif') no-repeat center center; - } - .alm-dir-listing .dir-title { - margin: 0 0 5px; - position: relative; - } - .alm-dir-listing h3.heading { - padding-left: 40px !important; - &:after { - content: '\f07c'; - } - &.open:after { - content: '\f07b'; - } - } - .alm-dir-listing .dir-title .delete { - position: absolute; - right: 10px; - top: 10px; - font-weight: 400; - font-size: 13px; - text-decoration: none; - padding: 5px 12px; - border: 1px solid $border; - color: #ccc; - border-radius: $radius; - } - .alm-dir-listing:hover .dir-title .delete { - border-color: $border; - background-color: #fff; - color: #666; - } - .alm-dir-listing .dir-title .delete:hover { - background-color: #c94141; - border-color: #c94141; - color: #fff; - } - .alm-dir-listing .dir-title .delete:active { - box-shadow: inset 0 2px 1px rgba(0, 0, 0, 0.2); - } - - .cache-page-title { - font-size: 12px; - display: block; - width: 100%; - padding: 0 7px 10px; - font-weight: 700; - text-transform: uppercase; - } - - .cache-page-wrap { - padding: 0 10px 20px; - } - - .cache-full-path { - display: none; - &-button { - border: 1px solid $light_border; - border-radius: 3px; - background: #fff; - cursor: pointer; - margin: 0 2px 0 0; - text-align: left; - color: #878787; - font-size: 13px; - padding: 2px 4px; - &:hover, - &:focus { - border-color: $border; - } - } - } - - .alm-dir-listing ul.cache-details { - display: block; - padding: 15px 10px 5px; - margin: 0; - border: none; - li { - position: relative; - display: block; - width: 100%; - background: none; - padding: 0 10px 0 28px; - margin: 0 0 10px; - i { - color: $grey_text; - font-size: 16px; - position: absolute; - top: 1px; - left: 5px; - } - a { - word-break: break-word; - } - } - } - - .dir-empty { - margin-top: 10px; - } - .dir-empty, - .cache-cleared { - background-color: $yellow; - border: 1px solid $yellow_dark; - padding: 20px; - display: block; - color: #222; - text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.2); - } - .cache-cleared { - margin: 0 0 20px; - background-color: #e0f5ff; - border-color: #bad0da; - color: #666; - i { - color: #111; - margin: 0 5px 0 0; - } - .remove { - float: right; - font-size: 12px; - font-weight: 600; - } - } - p.cache-stats { - min-height: 38px; - line-height: 37px; - display: block; - padding: 0; - margin: 0; - span { - display: inline-block; - width: 38px; - height: 38px; - line-height: 36px; - text-align: center; - margin: 0 9px 0 0; - font-weight: 700; - font-size: 15px; - border-radius: 2px; - background: #a4a5e2; - background: linear-gradient(to bottom, #a4a5e2 0%, #9ea0d9 50%, #8d8fce 51%, #a4a5e2 100%); - filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#a4a5e2', endColorstr='#a4a5e2',GradientType=0 ); - border: 1px solid #8586be; - box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15); - color: #fff; - text-shadow: -1px -1px 0 rgba(0, 0, 0, 0.1); - } - } -} - // Directory Listing .alm-dir-listing { ul { - padding: 20px 0 0; - margin: 10px 0 0; - border-top: 1px solid $border; + padding: 0; + margin: 0; display: flex; width: 100%; flex-wrap: wrap; diff --git a/admin/src/scss/partials/_cache.scss b/admin/src/scss/partials/_cache.scss new file mode 100644 index 0000000..669d8b7 --- /dev/null +++ b/admin/src/scss/partials/_cache.scss @@ -0,0 +1,272 @@ +// Cache +.alm-cache { + .group .row { + overflow: visible; + } + + .row { + &:first-of-type { + margin-top: 0 !important; + } + } + + h3.heading { + padding-right: 90px !important; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + + /* Live Search */ + .alm-cache-search-wrap { + position: relative; + display: block; + margin: 0 0 15px; + + input { + width: 100% !important; + margin: 0 !important; + padding: 13px 20px; + display: block; + font-size: 15px; + border-radius: $radius; + background-color: $light_grey; + } + + i { + position: absolute; + right: 15px; + top: 50%; + transform: translateY(-50%); + color: #ccc; + font-size: 16px; + z-index: 1; + } + } + + .alm-cache-listing { + position: relative; + + .toggle-all { + right: 0; + top: -45px; + } + } + + hr { + margin: 32px 0 25px; + border-top-color: $light_border; + border-bottom: none; + } + + /* Directory Listing */ + .alm-dir-listing { + border: 1px solid $border; + border-radius: $radius; + overflow: hidden; + padding: 0; + margin: 10px 0 0; + + &--nested { + padding: 0 15px 15px; + + .alm-dir-listing { + margin: 0; + } + } + + &.theme-repeaters { + padding: 15px; + margin: 0; + + ul { + border: none; + padding: 0; + margin: 0; + } + + i { + color: #ccc; + font-size: 1.1em; + } + } + } + + .alm-dir-listing.deleting { + opacity: 0.5; + background: #fff url('../../img/loader-unlimited.gif') no-repeat center center; + } + + .alm-dir-listing .dir-title { + margin: 0 0 5px; + position: relative; + } + + .alm-dir-listing h3.heading { + padding-left: 40px !important; + + &:after { + content: '\f07c'; + } + + &.open:after { + content: '\f07b'; + } + } + + .alm-dir-listing .dir-title .delete { + position: absolute; + right: 10px; + top: 10px; + font-weight: 400; + font-size: 13px; + text-decoration: none; + padding: 5px 12px; + border: 1px solid $border; + color: #ccc; + border-radius: $radius; + } + + .alm-dir-listing:hover .dir-title .delete { + border-color: $border; + background-color: #fff; + color: #666; + } + + .alm-dir-listing .dir-title .delete:hover { + background-color: #c94141; + border-color: #c94141; + color: #fff; + } + + .alm-dir-listing .dir-title .delete:active { + box-shadow: inset 0 2px 1px rgba(0, 0, 0, 0.2); + } + + .cache-page-title { + font-size: 12px; + display: block; + width: 100%; + padding: 0 7px 10px; + font-weight: 700; + text-transform: uppercase; + } + + .cache-page-wrap { + padding: 5px 12px 20px;ß + + & ul { + max-height: 300px; + overflow-y: auto; + scroll-behavior: smooth; + } + } + + .cache-full-path { + display: none; + + &-button { + border: 1px solid $light_border; + border-radius: 3px; + background: #fff; + cursor: pointer; + margin: 0 2px 0 0; + text-align: left; + color: #878787; + font-size: 13px; + padding: 2px 4px; + + &:hover, + &:focus { + border-color: $border; + } + } + } + + .alm-dir-listing ul.cache-details { + display: block; + padding: 20px 15px 0; + margin: 0; + border: none; + + li { + position: relative; + display: block; + width: 100%; + background: none; + padding: 0 10px 0 28px; + margin: 0 0 10px; + + i { + color: $grey_text; + font-size: 16px; + position: absolute; + top: 1px; + left: 5px; + } + + a { + word-break: break-word; + } + } + } + + .dir-empty { + margin-top: 10px; + } + + .dir-empty, + .cache-cleared { + background-color: $yellow; + border: 1px solid $yellow_dark; + padding: 20px; + display: block; + color: #222; + text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.2); + } + + .cache-cleared { + margin: 0 0 20px; + background-color: #e0f5ff; + border-color: #bad0da; + color: #666; + + i { + color: #111; + margin: 0 5px 0 0; + } + + .remove { + float: right; + font-size: 12px; + font-weight: 600; + } + } + + p.cache-stats { + min-height: 38px; + line-height: 37px; + display: block; + padding: 0; + margin: 0; + + span { + display: inline-block; + width: 38px; + height: 38px; + line-height: 36px; + text-align: center; + margin: 0 9px 0 0; + font-weight: 700; + font-size: 15px; + border-radius: 2px; + background: #a4a5e2; + background: linear-gradient(to bottom, #a4a5e2 0%, #9ea0d9 50%, #8d8fce 51%, #a4a5e2 100%); + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#a4a5e2', endColorstr='#a4a5e2', GradientType=0); + border: 1px solid #8586be; + box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15); + color: #fff; + text-shadow: -1px -1px 0 rgba(0, 0, 0, 0.1); + } + } +} diff --git a/core/dist/js/ajax-load-more.js b/core/dist/js/ajax-load-more.js index 9b9e098..0d83648 100644 --- a/core/dist/js/ajax-load-more.js +++ b/core/dist/js/ajax-load-more.js @@ -2390,8 +2390,7 @@ var alm_is_filtering = false; } } - // Dispatch Ajax query. - alm.AjaxLoadMore.ajax(); + alm.AjaxLoadMore.ajax(); // Dispatch http request. }; /** @@ -2427,7 +2426,7 @@ var alm_is_filtering = false; cache = _context.sent; if (cache) { - alm.AjaxLoadMore.success(cache); + alm.AjaxLoadMore.render(cache); } else { alm.AjaxLoadMore.adminajax(params, queryType); } @@ -2455,12 +2454,9 @@ var alm_is_filtering = false; while (1) { switch (_context2.prev = _context2.next) { case 0: - // Get Ajax URL. - _alm_localize = alm_localize, ajaxurl = _alm_localize.ajaxurl; + _alm_localize = alm_localize, ajaxurl = _alm_localize.ajaxurl; // Get Ajax URL - // Deconstruct query params. - - _params = params, _params$cache_slug = _params.cache_slug, cache_slug = _params$cache_slug === undefined ? '' : _params$cache_slug; + _params = params, _params$cache_slug = _params.cache_slug, cache_slug = _params$cache_slug === undefined ? '' : _params$cache_slug; // Deconstruct query params. /** * Single Posts. @@ -2506,7 +2502,7 @@ var alm_is_filtering = false; break; case 10: - alm.AjaxLoadMore.success(data); + alm.AjaxLoadMore.render(data); return _context2.abrupt('break', 14); case 12: @@ -2566,7 +2562,7 @@ var alm_is_filtering = false; data += alm_rest_template(result); } - // Create object to pass to success() + // Create results object. var obj = { html: data, meta: { @@ -2574,7 +2570,7 @@ var alm_is_filtering = false; totalposts: totalposts } }; - alm.AjaxLoadMore.success(obj); // Send data + alm.AjaxLoadMore.render(obj); }).catch(function (error) { // Error alm.AjaxLoadMore.error(error, 'restapi'); @@ -2591,12 +2587,12 @@ var alm_is_filtering = false; } /** - * Success function after loading data. + * Display/render results function. * * @param {object} data The results of the Ajax request. * @since 2.6.0 */ - alm.AjaxLoadMore.success = function (data) { + alm.AjaxLoadMore.render = function (data) { var _this = this; if (alm.addons.single_post) { diff --git a/core/src/js/ajax-load-more.js b/core/src/js/ajax-load-more.js index 7add10c..540fb41 100755 --- a/core/src/js/ajax-load-more.js +++ b/core/src/js/ajax-load-more.js @@ -621,8 +621,7 @@ let alm_is_filtering = false; } } - // Dispatch Ajax query. - alm.AjaxLoadMore.ajax(); + alm.AjaxLoadMore.ajax(); // Dispatch http request. }; /** @@ -641,7 +640,7 @@ let alm_is_filtering = false; const params = getAjaxParams(alm, queryType); const cache = await getCache(alm, Object.assign({}, params)); if (cache) { - alm.AjaxLoadMore.success(cache); + alm.AjaxLoadMore.render(cache); } else { alm.AjaxLoadMore.adminajax(params, queryType); } @@ -656,11 +655,8 @@ let alm_is_filtering = false; * @since 5.0.0 */ alm.AjaxLoadMore.adminajax = async function (params, queryType) { - // Get Ajax URL. - let { ajaxurl } = alm_localize; - - // Deconstruct query params. - const { cache_slug = '' } = params; + let { ajaxurl } = alm_localize; // Get Ajax URL + const { cache_slug = '' } = params; // Deconstruct query params. /** * Single Posts. @@ -702,7 +698,7 @@ let alm_is_filtering = false; switch (queryType) { case 'standard': - alm.AjaxLoadMore.success(data); + alm.AjaxLoadMore.render(data); break; case 'totalposts': @@ -749,7 +745,7 @@ let alm_is_filtering = false; data += alm_rest_template(result); } - // Create object to pass to success() + // Create results object. const obj = { html: data, meta: { @@ -757,7 +753,7 @@ let alm_is_filtering = false; totalposts: totalposts, }, }; - alm.AjaxLoadMore.success(obj); // Send data + alm.AjaxLoadMore.render(obj); }) .catch(function (error) { // Error @@ -775,12 +771,12 @@ let alm_is_filtering = false; } /** - * Success function after loading data. + * Display/render results function. * * @param {object} data The results of the Ajax request. * @since 2.6.0 */ - alm.AjaxLoadMore.success = function (data) { + alm.AjaxLoadMore.render = function (data) { if (alm.addons.single_post) { alm.AjaxLoadMore.getSinglePost(); // Get single post data for next post. } From c9984336c231c0bee50259444e4431d862ac97c4 Mon Sep 17 00:00:00 2001 From: Darren Cooney Date: Mon, 15 May 2023 10:05:49 -0400 Subject: [PATCH 09/18] Updated cache CSS --- admin/dist/css/admin.css | 14 +++++++----- admin/src/scss/admin.scss | 46 +++++++++++++++++++++------------------ ajax-load-more.php | 3 +-- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/admin/dist/css/admin.css b/admin/dist/css/admin.css index f973066..ff2583c 100644 --- a/admin/dist/css/admin.css +++ b/admin/dist/css/admin.css @@ -4725,25 +4725,29 @@ span.cnkt-button.installed i, } .alm-dir-listing ul li { margin: 0; - padding: 10px 5px 5px 40px; + padding: 10px 5px 5px 55px; + background: transparent url("../../img/directory-list.gif") no-repeat left 46%; + position: relative; display: block; - overflow: hidden; width: 50%; - background: transparent url("../../img/directory-list.gif") no-repeat left 46%; } .alm-dir-listing ul li.full { width: 100%; - display: block; } .alm-dir-listing ul li:last-child, .alm-dir-listing ul li:nth-last-child(2) { background-image: url("../../img/directory-list-btm.gif"); } .alm-dir-listing ul li a { text-decoration: none; + display: block; + word-break: break-all; } .alm-dir-listing ul li i { + width: 15px; color: #999; - padding: 0 5px 0 0; + position: absolute; + left: 36px; + top: 13px; } .alm-dir-listing p.theme-title { font-weight: 600; diff --git a/admin/src/scss/admin.scss b/admin/src/scss/admin.scss index a62036d..2cab3f9 100644 --- a/admin/src/scss/admin.scss +++ b/admin/src/scss/admin.scss @@ -2493,28 +2493,32 @@ span.cnkt-button.installed i, display: flex; width: 100%; flex-wrap: wrap; - } - ul li { - margin: 0; - padding: 10px 5px 5px 40px; - display: block; - overflow: hidden; - width: 50%; - background: transparent url('../../img/directory-list.gif') no-repeat left 46%; - &.full { - width: 100%; + li { + margin: 0; + padding: 10px 5px 5px 55px; + background: transparent url('../../img/directory-list.gif') no-repeat left 46%; + position: relative; display: block; - } - &:last-child, - &:nth-last-child(2) { - background-image: url('../../img/directory-list-btm.gif'); - } - a { - text-decoration: none; - } - i { - color: $grey_text; - padding: 0 5px 0 0; + width: 50%; + &.full { + width: 100%; + } + &:last-child, + &:nth-last-child(2) { + background-image: url('../../img/directory-list-btm.gif'); + } + a { + text-decoration: none; + display: block; + word-break: break-all; + } + i { + width: 15px; + color: $grey_text; + position: absolute; + left: 36px; + top: 13px; + } } } p.theme-title { diff --git a/ajax-load-more.php b/ajax-load-more.php index 931d6cc..2f9b907 100755 --- a/ajax-load-more.php +++ b/ajax-load-more.php @@ -52,8 +52,7 @@ - Terms [DONE] - ACF [DONE] - Comments [DONE] -- Single Posts - - Soltion for target loading cache. Working with Repeater Template. +- Single Posts [DONE] - Users [DONE] From a1c757cca63f401509f27f362abb918ff1295473 Mon Sep 17 00:00:00 2001 From: Darren Cooney Date: Thu, 18 May 2023 13:05:07 -0400 Subject: [PATCH 10/18] Adding new settings URL deeplinks --- admin/dist/js/admin.js | 49 +++++++++++++---------------- admin/src/js/admin.js | 63 +++++++++++++++++-------------------- admin/views/settings.php | 4 +-- ajax-load-more.php | 1 + core/src/js/addons/cache.js | 8 ----- 5 files changed, 52 insertions(+), 73 deletions(-) diff --git a/admin/dist/js/admin.js b/admin/dist/js/admin.js index e418325..4c110f5 100644 --- a/admin/dist/js/admin.js +++ b/admin/dist/js/admin.js @@ -1336,9 +1336,11 @@ jQuery(document).ready(function ($) { * @since 5.4 */ var ACTIVE_TAB_CLASS = 'active'; - function openTabbedItem(button, index, almTabbedWrapper) { - // Get Currently Active Button. - var activeBtn = document.querySelector('.alm-tabbed-wrapper--nav button.active'); + function openTabbedItem(button, almTabbedWrapper) { + var activeBtn = document.querySelector('.alm-tabbed-wrapper--nav button.active'); // Get Currently Active Button. + var id = button.dataset.id; + + // Remove currently active button. if (activeBtn) { activeBtn.classList.remove(ACTIVE_TAB_CLASS); } @@ -1349,19 +1351,16 @@ jQuery(document).ready(function ($) { // Activate Current Section if (almTabbedWrapper) { var currentActive = almTabbedWrapper.querySelector('.alm-tabbed-wrapper--section.' + ACTIVE_TAB_CLASS); - var sections = almTabbedWrapper.querySelectorAll('.alm-tabbed-wrapper--section'); - if (currentActive && sections) { + var section = almTabbedWrapper.querySelector('.alm-tabbed-wrapper--section#' + id); + if (currentActive && section) { currentActive.classList.remove(ACTIVE_TAB_CLASS); - if (sections[index]) { - sections[index].classList.add(ACTIVE_TAB_CLASS); - sections[index].focus({ preventScroll: true }); - $('html, body').animate({ - scrollTop: $('.alm-tabbed-wrapper--sections').offset().top - 45 - }, 350, function () { - var section = parseInt(index) + 1; - window.location.hash = 'alm-section-' + section; - }); - } + section.classList.add(ACTIVE_TAB_CLASS); + section.focus({ preventScroll: true }); + $('html, body').animate({ + scrollTop: $('.alm-tabbed-wrapper--sections').offset().top - 45 + }, 400, function () { + history.replaceState({}, '', '#' + id); + }); } } } @@ -1376,27 +1375,21 @@ jQuery(document).ready(function ($) { if (tabbedNav) { tabbedNav.forEach(function (item, index) { item.addEventListener('click', function () { - openTabbedItem(this, index, almTabbedWrapper); + openTabbedItem(this, almTabbedWrapper); }); }); } - // Open hash + // Open section from hash. var hash = window.location.hash; - if (hash && hash.indexOf('alm-section') !== -1) { + if (hash) { hash = hash.replace('#', ''); - var openSection = hash.replace('alm-section-', ''); - openSection = parseInt(openSection) - 1; - // Get button from nodelist. - var nodeItem = tabbedNav.item(openSection); - if (nodeItem) { - // trigger a click. - nodeItem.click(); + var targetBtn = document.querySelector('.alm-tabbed-wrapper--nav button[data-id="' + hash + '"]'); + if (targetBtn) { + targetBtn.click(); } } else { - if (tabbedNav) { - tabbedNav[0].classList.add(ACTIVE_TAB_CLASS); - } + document.querySelector('.alm-tabbed-wrapper--nav button').classList.add(ACTIVE_TAB_CLASS); } } diff --git a/admin/src/js/admin.js b/admin/src/js/admin.js index 73ca6e6..61bee56 100644 --- a/admin/src/js/admin.js +++ b/admin/src/js/admin.js @@ -58,9 +58,11 @@ jQuery(document).ready(function ($) { * @since 5.4 */ const ACTIVE_TAB_CLASS = 'active'; - function openTabbedItem(button, index, almTabbedWrapper) { - // Get Currently Active Button. - let activeBtn = document.querySelector('.alm-tabbed-wrapper--nav button.active'); + function openTabbedItem(button, almTabbedWrapper) { + const activeBtn = document.querySelector('.alm-tabbed-wrapper--nav button.active'); // Get Currently Active Button. + const id = button.dataset.id; + + // Remove currently active button. if (activeBtn) { activeBtn.classList.remove(ACTIVE_TAB_CLASS); } @@ -71,58 +73,49 @@ jQuery(document).ready(function ($) { // Activate Current Section if (almTabbedWrapper) { let currentActive = almTabbedWrapper.querySelector('.alm-tabbed-wrapper--section.' + ACTIVE_TAB_CLASS); - let sections = almTabbedWrapper.querySelectorAll('.alm-tabbed-wrapper--section'); - if (currentActive && sections) { + let section = almTabbedWrapper.querySelector('.alm-tabbed-wrapper--section#' + id); + if (currentActive && section) { currentActive.classList.remove(ACTIVE_TAB_CLASS); - if (sections[index]) { - sections[index].classList.add(ACTIVE_TAB_CLASS); - sections[index].focus({ preventScroll: true }); - $('html, body').animate( - { - scrollTop: $('.alm-tabbed-wrapper--sections').offset().top - 45, - }, - 350, - function () { - var section = parseInt(index) + 1; - window.location.hash = 'alm-section-' + section; - } - ); - } + section.classList.add(ACTIVE_TAB_CLASS); + section.focus({ preventScroll: true }); + $('html, body').animate( + { + scrollTop: $('.alm-tabbed-wrapper--sections').offset().top - 45, + }, + 400, + function () { + history.replaceState({}, '', '#' + id); + } + ); } } } - let almTabbedWrapper = document.querySelector('.alm-tabbed-wrapper'); + const almTabbedWrapper = document.querySelector('.alm-tabbed-wrapper'); if (almTabbedWrapper) { - let current = almTabbedWrapper.querySelector('.alm-tabbed-wrapper--section'); + const current = almTabbedWrapper.querySelector('.alm-tabbed-wrapper--section'); if (current) { current.classList.add(ACTIVE_TAB_CLASS); } - let tabbedNav = almTabbedWrapper.querySelectorAll('.alm-tabbed-wrapper--nav button'); + const tabbedNav = almTabbedWrapper.querySelectorAll('.alm-tabbed-wrapper--nav button'); if (tabbedNav) { tabbedNav.forEach(function (item, index) { item.addEventListener('click', function () { - openTabbedItem(this, index, almTabbedWrapper); + openTabbedItem(this, almTabbedWrapper); }); }); } - // Open hash + // Open section from hash. let hash = window.location.hash; - if (hash && hash.indexOf('alm-section') !== -1) { + if (hash) { hash = hash.replace('#', ''); - let openSection = hash.replace('alm-section-', ''); - openSection = parseInt(openSection) - 1; - // Get button from nodelist. - let nodeItem = tabbedNav.item(openSection); - if (nodeItem) { - // trigger a click. - nodeItem.click(); + const targetBtn = document.querySelector('.alm-tabbed-wrapper--nav button[data-id="' + hash + '"]'); + if (targetBtn) { + targetBtn.click(); } } else { - if (tabbedNav) { - tabbedNav[0].classList.add(ACTIVE_TAB_CLASS); - } + document.querySelector('.alm-tabbed-wrapper--nav button').classList.add(ACTIVE_TAB_CLASS); } } diff --git a/admin/views/settings.php b/admin/views/settings.php index 228f2ac..64b1b32 100755 --- a/admin/views/settings.php +++ b/admin/views/settings.php @@ -35,7 +35,7 @@