Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 28 additions & 39 deletions public/class-infinite-loader-for-woocommerce-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private function get_woocommerce_selectors() {
);

// Add support for WooCommerce blocks if active.
if ( $this->is_woocommerce_blocks_active() ) {
if ( class_exists( 'Automattic\WooCommerce\Blocks\Package' ) ) {
$this->selectors['products'] .= ', .wc-block-grid__products';
$this->selectors['item'] .= ', .wc-block-grid__product';
}
Expand All @@ -191,15 +191,6 @@ private function get_woocommerce_selectors() {
return $this->selectors;
}

/**
* Check if WooCommerce blocks is active
*
* @return bool
*/
private function is_woocommerce_blocks_active() {
return class_exists( 'Automattic\WooCommerce\Blocks\Package' );
}

/**
* Function to register font awesome css file.
*
Expand Down Expand Up @@ -335,7 +326,6 @@ public function infinite_loader_for_woocommerce_display_button() {
* @param int $threshold Pixels. Default 300.
*/
'scroll_threshold' => (int) apply_filters( 'infinite_loader_scroll_threshold', 300 ),
'is_mobile' => wp_is_mobile(),
'debug_mode' => defined( 'WP_DEBUG' ) && WP_DEBUG,
);

Expand Down Expand Up @@ -485,41 +475,40 @@ private function infinite_loader_get_product_count_data() {
* Add load more button Hover css on front-end.
*/
public function infinite_loader_add_load_more_hover_css() {
if ( ! $this->infinite_loader_should_load_assets() ) {
return;
}

$button_setting = $this->get_cached_option( 'infinite_loader_admin_button_option' );
$bg_hover_color = isset( $button_setting['background_color_mouse_hover'] ) ? $button_setting['background_color_mouse_hover'] : '#0e4da0';
$hover_text_color = isset( $button_setting['text_color_mouse_hover'] ) ? $button_setting['text_color_mouse_hover'] : '#ffffff';

// Sanitize colors.
$bg_hover_color = $this->sanitize_hex_color( $bg_hover_color, '#0e4da0' );
$hover_text_color = $this->sanitize_hex_color( $hover_text_color, '#ffffff' );

$style = '
.infinite_loader_btn_setting .infinite_button:hover {
background-color: ' . esc_attr( $bg_hover_color ) . ' !important;
color: ' . esc_attr( $hover_text_color ) . ' !important;
}';

$style = apply_filters( 'infinite_loader_lm_btn_hover_css', $style );

if ( ! empty( $style ) ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_strip_all_tags is used for CSS sanitization.
echo '<style type="text/css" id="infinite-loader-hover-css">' . wp_strip_all_tags( $style ) . '</style>';
}
$this->output_hover_css(
'infinite_loader_admin_button_option',
'.infinite_loader_btn_setting .infinite_button:hover',
'infinite_loader_lm_btn_hover_css',
'infinite-loader-hover-css'
);
}

/**
* Add Previous button Hover css on front-end.
*/
public function infinite_loader_add_previous_hover_css() {
$this->output_hover_css(
'infinite_loader_admin_previous_button_option',
'.infinite_loader_prev_btn_setting .infinite_button:hover',
'infinite_loader_previous_btn_hover_css',
'infinite-loader-prev-hover-css'
);
}

/**
* Output a button hover-color style block in the document head.
*
* @param string $option_key Settings option holding the hover colors.
* @param string $selector CSS selector for the button hover state.
* @param string $filter Filter applied to the generated style.
* @param string $style_id ID for the emitted <style> element.
*/
private function output_hover_css( $option_key, $selector, $filter, $style_id ) {
if ( ! $this->infinite_loader_should_load_assets() ) {
return;
}

$button_setting = $this->get_cached_option( 'infinite_loader_admin_previous_button_option' );
$button_setting = $this->get_cached_option( $option_key );
$bg_hover_color = isset( $button_setting['background_color_mouse_hover'] ) ? $button_setting['background_color_mouse_hover'] : '#0e4da0';
$hover_text_color = isset( $button_setting['text_color_mouse_hover'] ) ? $button_setting['text_color_mouse_hover'] : '#ffffff';

Expand All @@ -528,16 +517,16 @@ public function infinite_loader_add_previous_hover_css() {
$hover_text_color = $this->sanitize_hex_color( $hover_text_color, '#ffffff' );

$style = '
.infinite_loader_prev_btn_setting .infinite_button:hover {
' . $selector . ' {
background-color: ' . esc_attr( $bg_hover_color ) . ' !important;
color: ' . esc_attr( $hover_text_color ) . ' !important;
}';

$style = apply_filters( 'infinite_loader_previous_btn_hover_css', $style );
$style = apply_filters( $filter, $style );

if ( ! empty( $style ) ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_strip_all_tags is used for CSS sanitization.
echo '<style type="text/css" id="infinite-loader-prev-hover-css">' . wp_strip_all_tags( $style ) . '</style>';
echo '<style type="text/css" id="' . esc_attr( $style_id ) . '">' . wp_strip_all_tags( $style ) . '</style>';
}
}

Expand Down
118 changes: 21 additions & 97 deletions public/js/infinite_loader_products.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var infinite_loader_update_state, infinite_loader_product_data, infinite_loader_load_next_page, infinite_loader_ajax_instance = false, infinite_loader_update_lazyload, infinite_loader_init, infinite_loader_init_buttons;
var infinite_loader_update_state, infinite_loader_product_data, infinite_loader_load_next_page, infinite_loader_ajax_instance = false, infinite_loader_init, infinite_loader_init_buttons;

(function ($) {
'use strict';
Expand Down Expand Up @@ -196,27 +196,25 @@ var infinite_loader_update_state, infinite_loader_product_data, infinite_loader_
});

// Pagination click handler
if (!infinite_loader_product_data.is_AAPF || typeof the_ajax_script === 'undefined') {
$(document).on('click', infinite_loader_product_data.pagination + ' a', function (event) {
event.preventDefault();
var next_page = $(this).attr('href');

if (!is_valid_url(next_page)) {
return;
}

if (infinite_loader_product_data.update_url) {
update_browser_history(next_page);
}

// 1 means "replace the grid", not "true". replace is a
// three-state mode (1 replace, 2 prepend, falsy
// append) that is compared with ===, so passing a
// boolean here silently fell through to append and
// paginating stacked page 2 underneath page 1.
infinite_loader_load_next_page(1, next_page);
});
}
$(document).on('click', infinite_loader_product_data.pagination + ' a', function (event) {
event.preventDefault();
var next_page = $(this).attr('href');

if (!is_valid_url(next_page)) {
return;
}

if (infinite_loader_product_data.update_url) {
update_browser_history(next_page);
}

// 1 means "replace the grid", not "true". replace is a
// three-state mode (1 replace, 2 prepend, falsy
// append) that is compared with ===, so passing a
// boolean here silently fell through to append and
// paginating stacked page 2 underneath page 1.
infinite_loader_load_next_page(1, next_page);
});

// Integration events
$(document).on('infinite_loader_ajax_filter_start', function () {
Expand Down Expand Up @@ -449,11 +447,6 @@ var infinite_loader_update_state, infinite_loader_product_data, infinite_loader_
return;
}

// Process lazy loading attributes
if (should_lazy_load()) {
prepare_lazy_load_content($data);
}

// Mark first item with URL
mark_first_item($data, next_page);

Expand All @@ -469,9 +462,6 @@ var infinite_loader_update_state, infinite_loader_product_data, infinite_loader_
domCache.products.append($products);
}

// Update lazy loading
infinite_loader_update_lazyload();

// Update result count
update_result_count($data, replace);

Expand All @@ -497,23 +487,6 @@ var infinite_loader_update_state, infinite_loader_product_data, infinite_loader_
}
}

function should_lazy_load() {
var is_mobile = domCache.window.width() <= (infinite_loader_product_data.mobile_width || 768);
return (infinite_loader_product_data.lazy_load_m && is_mobile) ||
(infinite_loader_product_data.lazy_load && !is_mobile);
}

function prepare_lazy_load_content($data) {
$data.find(infinite_loader_product_data.products + ' .lazy,' + infinite_loader_product_data.item + ', .infinite_loader_extra_data')
.find('img').each(function () {
var $img = $(this);
$img.attr('data-src', $img.attr('src')).removeAttr('src');
$img.attr('data-srcset', $img.attr('srcset')).removeAttr('srcset');
});

$data.find(infinite_loader_product_data.item + ', .infinite_loader_extra_data').addClass('lazy');
}

function mark_first_item($data, next_page) {
var validUrl = safe_encode_url(next_page);

Expand Down Expand Up @@ -669,13 +642,7 @@ var infinite_loader_update_state, infinite_loader_product_data, infinite_loader_
}
}

var is_mobile = domCache.window.width() <= (infinite_loader_product_data.mobile_width || 768);

if (infinite_loader_product_data.use_mobile && is_mobile) {
set_style(infinite_loader_product_data.mobile_type);
} else {
set_style(infinite_loader_product_data.type);
}
set_style(infinite_loader_product_data.type);
}

var test_prev_page_timeout = false;
Expand Down Expand Up @@ -811,52 +778,9 @@ var infinite_loader_update_state, infinite_loader_product_data, infinite_loader_
}
}

// Update lazy load function
infinite_loader_update_lazyload = function () {
if (typeof domCache.window.lazyLoadXT !== 'undefined' && should_lazy_load()) {
$(infinite_loader_product_data.products + ' .lazy').find('img').lazyLoadXT();

domCache.products.find('.lazy').on('lazyshow', function () {
var $this = $(this);
$this.removeClass('lazy')
.addClass('animated')
.addClass(infinite_loader_product_data.LLanimation || 'fadeIn');

if ($this.is('img')) {
$this.attr('srcset', $this.data('srcset'));
} else {
$this.find('img').each(function () {
$(this).attr('srcset', $(this).data('srcset'));
});
}

if (!$this.is('.infinite_loader_extra_data')) {
$this.next('.infinite_loader_extra_data')
.removeClass('lazy')
.addClass('animated')
.addClass(infinite_loader_product_data.LLanimation || 'fadeIn');
}
});
}
};

// Events
$(document).on('infinite_loader_ajax_loader', function () {
infinite_loader_update_state(true);

if (typeof domCache.window.lazyLoadXT !== 'undefined' && should_lazy_load()) {
$(infinite_loader_product_data.item + ', .infinite_loader_extra_data')
.addClass('lazy')
.find('img')
.each(function () {
var $img = $(this);
$img.attr('data-src', $img.attr('src')).removeAttr('src')
.attr('data-srcset', $img.attr('srcset')).removeAttr('srcset');
})
.lazyLoadXT();
}

infinite_loader_update_lazyload();
});

$(document).on('infinite_loader_after_style_set', function () {
Expand Down
Loading
Loading