Files
du_an_khach_hang/Chico/PC/homepage.js
2023-03-31 13:29:47 +07:00

184 lines
4.2 KiB
JavaScript

lazy_load_group.push(
{
id: 'js-hottpye-new',
target: '#js-hottpye-new',
loadFn: function () {
getCategoryNew();
},
},
)
//SWIPER SLIDER SHOWCASE
function swiperTopBanner() {
new Swiper(".swiperTopBanner", {
slidesPerView: 1,
spaceBetween: 12,
centeredSlides: true,
loop: true,
speed: 1000,
preloadImages: false,
lazy: true,
autoplay: {
delay: 2500,
disableOnInteraction: false,
pauseOnMouseEnter: "true",
},
pagination: {
el: ".swiper-pagination",
clickable: true,
},
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev",
},
});
}
swiperTopBanner();
//SWIPER CATEGORY HOMEPAGE
function swiperCollectionBox() {
new Swiper(".homepage-collection-swiper", {
slidesPerView: 6,
spaceBetween: 16,
rewind: true,
speed: 1000,
preloadImages: false,
lazy: true,
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev",
},
breakpoints: {
1200: {
slidesPerView: 5,
},
1600: {
slidesPerView: 6,
},
},
});
}
swiperCollectionBox();
// SET CATEGOTY ITEM LINK TO VIEW MORE BUTTON
function setLinkToSeeAllBtn(target, categoryLink) {
target
.parents(".collection-tab-container")
.find(".all-item-collection")
.children()
.attr("href", categoryLink);
}
// COLLECTION SECTION
function collectionBoxHandler() {
$(".js-collection-item").on("click", function () {
var collectionId = $(this).attr("data-id");
var collectionLink = $(this).attr("data-url");
$(this).parent().find(".active").removeClass("active");
$(this).addClass("active");
getCollectionProduct(collectionId);
setLinkToSeeAllBtn($(this), collectionLink);
});
}
function getCollectionProduct(collectionId) {
var params = {
action_type: "list",
id: collectionId,
show: 18,
};
var target = "#js-collection-holder";
Hura.Ajax.get("collection", params).then(function (data) {
var html = Hura.Template.parse(productTpl, data.list);
Hura.Template.render(target, html);
tooltip();
});
}
function firstClickCollection() {
collectionBoxHandler();
$(".js-collection-item").first().click();
}
firstClickCollection();
//SWIPER CATEGORY HOMEPAGE
function swiperListBox() {
new Swiper(".homepage-cat-swiper", {
slidesPerView: 6,
spaceBetween: 12,
rewind: true,
speed: 1000,
preloadImages: false,
lazy: true,
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev",
},
breakpoints: {
1200: {
slidesPerView: 5,
},
1600: {
slidesPerView: 6,
},
},
});
}
swiperListBox();
function lazyCategoryBox(){
for (let i = 0; i <= category_to_fetch.length - 1; i++) {
let idCat = category_to_fetch[i]
lazy_load_group.push(
{
id: "js-product-" + idCat,
target: "#js-product-" + idCat,
loadFn: function () {
getCategoryProduct(idCat)
},
},
);
}
}
lazyCategoryBox();
// AJAX CATEGORY BOX - HOT PRODUCT
function getCategoryProduct(id) {
var params = {
action_type: "product-list",
category: id,
};
var target = "#js-product-" + id;
Hura.Ajax.get("product", params).then(function (data) {
//console.log(data.list);
if (data.total == 0) {
$(target).html(
`<h3 class="box-empty font-weight-700 d-flex align-items-center justify-content-center">Sản phẩm đang được cập nhật...!</h3>`
);
} else {
var html = Hura.Template.parse(listCategoryHome, data.list);
Hura.Template.render(target, html);
tooltip();
}
});
}