{"version":3,"file":"relatedArticlesCarousel-o-d5k981.js","sources":["../../../../../src/scripts/modules/relatedArticlesCarousel.ts"],"sourcesContent":["import { Component } from '@verndale/core';\nimport Splide from '@splidejs/splide';\nimport '@splidejs/splide/dist/css/splide-core.min.css';\n\nclass RelatedArticlesCarousel extends Component {\n public relatedArticlesCarousel: Splide;\n\n constructor(el: HTMLElement) {\n super(el);\n this.relatedArticlesCarousel = {} as Splide;\n this.initSplide();\n }\n\n setupDefaults() {\n this.dom = {\n el: this.el,\n pagination: this.el.querySelector(\n '.related-articles-carousel__slider-pagination'\n ),\n slides: this.el.querySelectorAll('.splide__slide'),\n prevButton: this.el.querySelector('.btn-previous-slide'),\n nextButton: this.el.querySelector('.btn-next-slide')\n };\n this.initSplide();\n }\n\n addListeners() {\n this.relatedArticlesCarousel.on('move', this.updatePagination.bind(this));\n }\n\n initSplide() {\n this.relatedArticlesCarousel = new Splide(this.el as HTMLElement, {\n type: 'slide',\n perPage: 4,\n focus: (this.dom.slides as NodeList).length > 4 ? 0 : undefined,\n trimSpace: (this.dom.slides as NodeList).length > 4 ? false : true,\n perMove: 1,\n gap: 48,\n pagination: false,\n arrows: (this.dom.slides as NodeList).length > 4 ? true : false,\n breakpoints: {\n 768: {\n perPage: 1,\n gap: 16,\n arrows: true,\n },\n 1280: {\n perPage: 3,\n gap: 24,\n arrows: (this.dom.slides as NodeList).length > 3 ? true : false,\n }\n },\n reducedMotion: {\n speed: 0,\n rewindSpeed: 0,\n },\n }).mount();\n\n this.updatePagination(0);\n }\n\n updatePagination(index: number) {\n if (this.dom.pagination) {\n const totalSlides = this.relatedArticlesCarousel.Components.Slides.getLength();\n const totalPages = Math.ceil(totalSlides / this.relatedArticlesCarousel.options.perMove!);\n const currentPage = Math.ceil(index / this.relatedArticlesCarousel.options.perMove!) + 1;\n (this.dom.pagination as HTMLElement).textContent = `${currentPage} / ${totalPages}`;\n }\n }\n}\n\nexport default RelatedArticlesCarousel;\n"],"names":["RelatedArticlesCarousel","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