chunks
7 months ago
vendor
8 months ago
admin.build.js
7 months ago
admin.js
9 months ago
analytics-tracker.js
9 months ago
analytics.build.js
7 months ago
blocks.build.js
7 months ago
carousel.js
1 year ago
documents-viewer-script.js
3 years ago
feature-notices.js
7 months ago
front.js
7 months ago
frontend.build.js
9 months ago
gallery-justify.js
9 months ago
gutneberg-script.js
1 year ago
index.html
7 years ago
initCarousel.js
2 years ago
initplyr.js
8 months ago
instafeed.js
7 months ago
license.js
7 months ago
preview.js
8 months ago
settings.js
7 months ago
sponsored.js
9 months ago
carousel.js
208 lines
| 1 | window.CgCarousel = class { |
| 2 | constructor(t, i = {}, e = []) { |
| 3 | (this.container = document.querySelector(t)), |
| 4 | this.container && |
| 5 | ((this.slidesSelector = i.slidesSelector || ".js-carousel__slide"), |
| 6 | (this.trackSelector = i.trackSelector || ".js-carousel__track"), |
| 7 | (this.slides = []), |
| 8 | (this.track = this.container.querySelector(this.trackSelector)), |
| 9 | (this.slidesLength = 0), |
| 10 | (this.currentBreakpoint = void 0), |
| 11 | (this.breakpoints = i.breakpoints || {}), |
| 12 | (this.hooks = e), |
| 13 | (this.initialOptions = { loop: i.loop || !1, autoplay: i.autoplay || !1, autoplaySpeed: i.autoplaySpeed || 3e3, transitionSpeed: i.transitionSpeed || 650, slidesPerView: i.slidesPerView || 1, spacing: i.spacing || 0 }), |
| 14 | (this.options = this.initialOptions), |
| 15 | (this.animationStart = void 0), |
| 16 | (this.animation = void 0), |
| 17 | (this.animationCurrentTrans = 0), |
| 18 | (this.animationIndex = 0), |
| 19 | (window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame), |
| 20 | (window.cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame), |
| 21 | (this.autoplayInterval = void 0), |
| 22 | (this.isButtonRightDisabled = !1), |
| 23 | (this.isButtonLeftDisabled = !1), |
| 24 | (this.currentIndex = 0), |
| 25 | (this.maxIndex = 0), |
| 26 | (this.isInfinite = !1), |
| 27 | (this.isPrevInfinite = !1), |
| 28 | (this.swipeStartX = void 0), |
| 29 | (this.swipeStartY = void 0), |
| 30 | (this.swipeThreshold = 100), |
| 31 | (this.swipeRestraint = 100), |
| 32 | (this.swipeDir = void 0), |
| 33 | this.track && (this.addEventListeners(), this.initCarousel())); |
| 34 | } |
| 35 | hook(t) { |
| 36 | this.hooks[t] && this.hooks[t](this); |
| 37 | } |
| 38 | isTouchableDevice() { |
| 39 | return window.matchMedia("(pointer: coarse)").matches; |
| 40 | } |
| 41 | handleSwipe() { |
| 42 | switch (this.swipeDir) { |
| 43 | case "top": |
| 44 | case "bottom": |
| 45 | default: |
| 46 | break; |
| 47 | case "left": |
| 48 | this.next(); |
| 49 | break; |
| 50 | case "right": |
| 51 | this.prev(); |
| 52 | } |
| 53 | } |
| 54 | onSwipeStart(t) { |
| 55 | if (!this.isTouchableDevice() || !t.changedTouches) return; |
| 56 | const i = t.changedTouches[0]; |
| 57 | (this.swipeStartX = i.pageX), (this.swipeStartY = i.pageY); |
| 58 | } |
| 59 | setSwipeDirection(t) { |
| 60 | const i = t.changedTouches[0], |
| 61 | e = i.pageX - this.swipeStartX, |
| 62 | s = i.pageY - this.swipeStartY; |
| 63 | Math.abs(e) >= this.swipeThreshold && Math.abs(s) <= this.swipeRestraint |
| 64 | ? (this.swipeDir = e < 0 ? "left" : "right") |
| 65 | : Math.abs(s) >= this.swipeThreshold && Math.abs(e) <= this.swipeRestraint && (this.swipeDir = s < 0 ? "up" : "down"); |
| 66 | } |
| 67 | onSwipeMove(t) { |
| 68 | this.isTouchableDevice() && t.changedTouches && (this.setSwipeDirection(t), ["left", "right"].includes(this.swipeDir) && t.cancelable && t.preventDefault()); |
| 69 | } |
| 70 | onSwipeEnd(t) { |
| 71 | this.isTouchableDevice() && t.changedTouches && (this.setSwipeDirection(t), this.handleSwipe()); |
| 72 | } |
| 73 | addEventListeners() { |
| 74 | window.addEventListener("orientationchange", () => this.onResize()), |
| 75 | window.addEventListener("resize", () => this.onResize()), |
| 76 | this.container.addEventListener("touchstart", (t) => this.onSwipeStart(t), { passive: !0 }), |
| 77 | this.container.addEventListener("touchmove", (t) => this.onSwipeMove(t), !1), |
| 78 | this.container.addEventListener("touchend", (t) => this.onSwipeEnd(t), { passive: !0 }); |
| 79 | } |
| 80 | onResize() { |
| 81 | this.checkBreakpoint() && this.buildCarousel(), this.hook("resized"); |
| 82 | } |
| 83 | setUpAutoplay() { |
| 84 | this.options.autoplay && (clearInterval(this.autoplayInterval), (this.autoplayInterval = setInterval(() => this.next(), this.options.autoplaySpeed))); |
| 85 | } |
| 86 | checkBreakpoint() { |
| 87 | if (!this.breakpoints) return; |
| 88 | const t = Object.keys(this.breakpoints) |
| 89 | .reverse() |
| 90 | .find((t) => { |
| 91 | const i = `(min-width: ${t}px)`; |
| 92 | return window.matchMedia(i).matches; |
| 93 | }); |
| 94 | if (this.currentBreakpoint === t) return; |
| 95 | this.currentBreakpoint = t; |
| 96 | const i = t ? this.breakpoints[t] : this.initialOptions; |
| 97 | return (this.options = { ...this.initialOptions, ...i }), !0; |
| 98 | } |
| 99 | setButtonsVisibility() { |
| 100 | (this.isButtonLeftDisabled = !this.options.loop && 0 === this.currentIndex), (this.isButtonRightDisabled = !this.options.loop && this.currentIndex === this.maxIndex - 1); |
| 101 | } |
| 102 | clearCarouselStyles() { |
| 103 | ["grid-auto-columns", "gap", "transition", "left"].map((t) => this.track.style.removeProperty(t)); |
| 104 | const t = ["grid-column-start", "grid-column-end", "grid-row-start", "grid-row-end", "left"]; |
| 105 | this.slides.forEach((i) => { |
| 106 | t.map((t) => i.style.removeProperty(t)); |
| 107 | }); |
| 108 | } |
| 109 | setCarouselStyles() { |
| 110 | if (!this.slides) return; |
| 111 | const t = this.options.slidesPerView, |
| 112 | i = 100 / t, |
| 113 | e = (this.options.spacing * (t - 1)) / t; |
| 114 | (this.track.style.gridAutoColumns = `calc(${i}% - ${e}px)`), (this.track.style.gridGap = `${this.options.spacing}px`), (this.track.style.left = 0); |
| 115 | } |
| 116 | buildCarousel() { |
| 117 | (this.maxIndex = Math.ceil(this.slidesLength / this.options.slidesPerView)), this.clearCarouselStyles(), this.setCarouselStyles(), this.setButtonsVisibility(), this.setUpAutoplay(), (this.currentIndex = 0), this.hook("built"); |
| 118 | } |
| 119 | initCarousel() { |
| 120 | (this.slides = this.container.querySelectorAll(this.slidesSelector)), (this.slidesLength = this.slides?.length), this.checkBreakpoint(), this.buildCarousel(), this.hook("created"); |
| 121 | } |
| 122 | onAnimationEnd() { |
| 123 | const t = this.options.spacing * this.animationIndex, |
| 124 | i = -100 * this.animationIndex; |
| 125 | (this.track.style.left = `calc(${i}% - ${t}px)`), (this.animationCurrentTrans = i), (this.animation = null), this.isInfinite && this.clearInfinite(), this.isPrevInfinite && this.clearPrevInfinite(); |
| 126 | } |
| 127 | moveAnimateAbort() { |
| 128 | this.animation && (window.cancelAnimationFrame(this.animation), this.onAnimationEnd()); |
| 129 | } |
| 130 | animateLeft(t, i, e, s) { |
| 131 | const n = t - this.animationStart, |
| 132 | o = ((r = n / s), 1 - Math.pow(1 - r, 5)); |
| 133 | var r; |
| 134 | const a = (i * o + this.animationCurrentTrans * (1 - o)).toFixed(2); |
| 135 | (this.track.style.left = `calc(${a}% - ${e}px)`), |
| 136 | n >= s |
| 137 | ? this.onAnimationEnd() |
| 138 | : (this.animation = window.requestAnimationFrame((t) => { |
| 139 | this.animateLeft(t, i, e, s); |
| 140 | })); |
| 141 | } |
| 142 | moveSlide(t, i) { |
| 143 | this.moveAnimateAbort(); |
| 144 | const e = this.options.spacing * t, |
| 145 | s = -100 * t; |
| 146 | (this.animation = window.requestAnimationFrame((i) => { |
| 147 | t === this.maxIndex && this.setInfinite(), -1 === t && this.setPrevInfinite(), (this.animationStart = i), (this.animationIndex = this.currentIndex), this.animateLeft(i, s, e, this.options.transitionSpeed); |
| 148 | })), |
| 149 | (this.currentIndex = i), |
| 150 | this.setUpAutoplay(), |
| 151 | this.setButtonsVisibility(), |
| 152 | this.hook("moved"); |
| 153 | } |
| 154 | setInfinite() { |
| 155 | this.isInfinite = !0; |
| 156 | const t = this.options.slidesPerView * this.maxIndex; |
| 157 | for (let i = 0; i < this.options.slidesPerView; i++) { |
| 158 | this.slides[i].style.left = `calc((100% * ${t}) + (${this.options.spacing}px * ${t}))`; |
| 159 | } |
| 160 | } |
| 161 | clearInfinite() { |
| 162 | (this.isInfinite = !1), |
| 163 | (this.track.style.left = `calc(${-100 * this.currentIndex}% - ${this.options.spacing * this.currentIndex}px)`), |
| 164 | this.slides.forEach((t, i) => { |
| 165 | i >= this.options.slidesPerView || t.style.removeProperty("left"); |
| 166 | }); |
| 167 | } |
| 168 | next() { |
| 169 | const t = this.currentIndex === this.maxIndex - 1 ? 0 : this.currentIndex + 1; |
| 170 | (!this.options.loop && t < this.currentIndex) || (t < this.currentIndex ? this.moveSlide(this.currentIndex + 1, t) : this.moveSlide(t, t)); |
| 171 | } |
| 172 | setPrevInfinite() { |
| 173 | this.isPrevInfinite = !0; |
| 174 | const t = this.options.slidesPerView * this.maxIndex, |
| 175 | i = t - this.options.slidesPerView; |
| 176 | for (let e = this.slides.length - 1; e >= 0; e--) { |
| 177 | if (e < i) return; |
| 178 | this.slides[e].style.left = `calc((-100% * ${t}) - (${this.options.spacing}px * ${t}))`; |
| 179 | } |
| 180 | } |
| 181 | clearPrevInfinite() { |
| 182 | (this.isPrevInfinite = !1), |
| 183 | (this.track.style.left = `calc(${-100 * this.currentIndex}% - ${this.options.spacing * this.currentIndex}px)`), |
| 184 | this.slides.forEach((t, i) => { |
| 185 | t.style.removeProperty("left"); |
| 186 | }); |
| 187 | } |
| 188 | prev() { |
| 189 | const t = 0 === this.currentIndex ? this.maxIndex - 1 : this.currentIndex - 1; |
| 190 | (!this.options.loop && t > this.currentIndex) || (t > this.currentIndex ? this.moveSlide(this.currentIndex - 1, t) : this.moveSlide(t, t)); |
| 191 | } |
| 192 | moveToSlide(t) { |
| 193 | t !== this.currentIndex && this.moveSlide(t, t); |
| 194 | } |
| 195 | getSlides() { |
| 196 | return this.slides; |
| 197 | } |
| 198 | getCurrentIndex() { |
| 199 | return this.currentIndex; |
| 200 | } |
| 201 | getOptions() { |
| 202 | return this.options; |
| 203 | } |
| 204 | getPageSize() { |
| 205 | return this.maxIndex; |
| 206 | } |
| 207 | }; |
| 208 |