Skip to content

Commit

Permalink
listing jquery removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Oksydan committed Oct 21, 2023
1 parent fe6b1d5 commit 068c386
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions _dev/js/listing/index.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
import $ from 'jquery';
import prestashop from 'prestashop';
import Filters from '@js/listing/components/filters/Filters';
import parseToHtml from '../theme/utils/parseToHtml';
import { each } from '../theme/utils/DOMHelpers';
import DOMReady from '../theme/utils/DOMReady';

function updateProductListDOM(data) {
$(prestashop.selectors.listing.searchFilters).replaceWith(
data.rendered_facets,
);
$(prestashop.selectors.listing.activeSearchFilters).replaceWith(
data.rendered_active_filters,
);
$(prestashop.selectors.listing.listTop).replaceWith(
data.rendered_products_top,
);

const renderedProducts = $(data.rendered_products);
const productSelectors = $(prestashop.selectors.listing.product);

if (productSelectors.length > 0) {
productSelectors.removeClass().addClass(productSelectors.first().attr('class'));
} else {
productSelectors.removeClass().addClass(renderedProducts.first().attr('class'));
}

$(prestashop.selectors.listing.list).replaceWith(renderedProducts);
$(prestashop.selectors.listing.listBottom).replaceWith(data.rendered_products_bottom);
each(prestashop.selectors.listing.searchFilters, (el) => {
el.replaceWith(parseToHtml(data.rendered_facets));
});
each(prestashop.selectors.listing.activeSearchFilters, (el) => {
el.replaceWith(parseToHtml(data.rendered_active_filters));
});
each(prestashop.selectors.listing.listTop, (el) => {
el.replaceWith(parseToHtml(data.rendered_products_top));
});
each(prestashop.selectors.listing.listBottom, (el) => {
el.replaceWith(parseToHtml(data.rendered_products_bottom));
});
each(prestashop.selectors.listing.list, (el) => {
el.replaceWith(parseToHtml(data.rendered_products));
});

if (data.rendered_products_header) {
$(prestashop.selectors.listing.listHeader).replaceWith(data.rendered_products_header);
each(prestashop.selectors.listing.listHeader, (el) => {
el.replaceWith(parseToHtml(data.rendered_products_header));
});
}

prestashop.emit('updatedProductList', data);
}

$(() => {
DOMReady(() => {
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "filters" }] */
const filters = new Filters();

Expand Down

0 comments on commit 068c386

Please sign in to comment.