forked from bigcommerce/cornerstone
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d6f8b3
commit 4f6b8f4
Showing
12 changed files
with
631 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import utils from '@bigcommerce/stencil-utils'; | ||
|
||
export default function loadProductByCategory(productBlockCols, productBlockLimit) { | ||
const carouselConfig = { | ||
template: 'products/carousel-2', | ||
}; | ||
const categoryBlocks = $('.mwn-block[data-category-id]'); | ||
|
||
if (categoryBlocks.length > 0) { | ||
const headerHeight = $('.header').height(); | ||
let hasInitialized = false; | ||
|
||
$(window).on('load scroll', (() => { | ||
let hasScrolledHeader = false; | ||
|
||
if (hasInitialized) { | ||
return; | ||
} | ||
|
||
if ($(window).scrollTop() > headerHeight) { | ||
hasScrolledHeader = true; | ||
} | ||
|
||
if (hasScrolledHeader) { | ||
categoryBlocks.each(((_index, element) => { | ||
const productCarousel = $(element).find('.productCarousel'); | ||
const categoryId = $(element).data('category-id'); | ||
const categoryUrl = $(element).data('category-url'); | ||
|
||
// Load products for the category if the product carousel is empty | ||
if ($(`#category-product-${categoryId}.productCarousel .productCarousel-slide`).length === 0) { | ||
utils.api.getPage(`${categoryUrl}?limit=${productBlockLimit}`, carouselConfig, (_err, responseData) => { | ||
productCarousel.html(responseData); | ||
|
||
// Initialize the product carousel with Slick slider | ||
function initializeCarousel(carouselElement) { | ||
carouselElement.slick({ | ||
dots: true, | ||
arrows: false, | ||
infinite: false, | ||
mobileFirst: true, | ||
slidesToShow: 2, | ||
slidesToScroll: 1, | ||
nextArrow: "<svg class='slick-next slick-arrow slick-arrow-large' aria-label='Next Slide'><use xlink:href=#slick-arrow-next></use></svg>", | ||
prevArrow: "<svg class='slick-prev slick-arrow slick-arrow-large' aria-label='Previous Slide'><use xlink:href=#slick-arrow-prev></use></svg>", | ||
responsive: [{ | ||
breakpoint: 1024, | ||
settings: { | ||
arrows: true, | ||
slidesToShow: parseInt(productBlockCols, 10), | ||
}, | ||
}, { | ||
breakpoint: 991, | ||
settings: { | ||
slidesToShow: parseInt(productBlockCols, 10) - 1, | ||
}, | ||
}, { | ||
breakpoint: 767, | ||
settings: { | ||
slidesToShow: parseInt(productBlockCols, 10) - 2, | ||
}, | ||
}], | ||
}); | ||
} | ||
|
||
initializeCarousel(productCarousel); | ||
productCarousel.parents('.mwn-block[data-category-id]').find('.loadingOverlay').remove(); | ||
}); | ||
} | ||
})); | ||
|
||
hasInitialized = true; | ||
} | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import PageManager from './page-manager'; | ||
import loadProductByCategory from './common/product-by-category'; | ||
|
||
export default class Home extends PageManager { | ||
onReady() { | ||
const { | ||
categoryBlockCarouselLimit, | ||
categoryBlockCarouselCol, | ||
} = this.context; | ||
|
||
loadProductByCategory(categoryBlockCarouselCol, categoryBlockCarouselLimit); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,3 +202,5 @@ | |
|
||
// Vendors | ||
@import "stencil/vendor/component"; | ||
|
||
@import "stencil/customBlocks"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.mwn-block { | ||
display: block; | ||
position: relative; | ||
|
||
.padding-vertical { | ||
padding-top: 30px; | ||
padding-bottom: 30px; | ||
} | ||
|
||
&-product { | ||
.loadingOverlay { | ||
display: block; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,3 +183,6 @@ div.slick-slider { | |
*width: 100%; | ||
} | ||
|
||
.slick-list { | ||
margin-bottom: 12px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.