PageSourceSearch

https://xn----7sblvlgns.xn--j1amh/wp-content/themes/sday-lom/assets/guide-promo-slider.js?ver=1.8.38

js xn----7sblvlgns.xn--j1amh collected 2026-10-08 07:17:23 UTC 6,524 bytes, 208 lines download raw bytes

1/**
2 * Metal guide promo carousel (listing + analytics widget).
3 */
4(function (window, document) {
5  'use strict';
6
7  function qs(sel, root) {
8    return (root || document).querySelector(sel);
9  }
10
11  function qsa(sel, root) {
12    return Array.prototype.slice.call((root || document).querySelectorAll(sel));
13  }
14
15  var resizeBound = false;
16  var resizeTimer = 0;
17
18  function syncSlider(slider) {
19    var api = slider && slider._sdayGuidePromo;
20    if (!api || typeof api.sync !== 'function') return;
21    api.sync();
22  }
23
24  function bindResize() {
25    if (resizeBound) return;
26    resizeBound = true;
27    window.addEventListener('resize', function () {
28      window.clearTimeout(resizeTimer);
29      resizeTimer = window.setTimeout(function () {
30        qsa('[data-guide-promo-slider][data-slider-ready="1"]').forEach(syncSlider);
31      }, 120);
32    });
33  }
34
35  function initGuidePromoSliders(root) {
36    bindResize();
37    var nodes = qsa('[data-guide-promo-slider]', root || document);
38    nodes.forEach(function (slider) {
39      if (slider.getAttribute('data-slider-ready') === '1') return;
40      var track = qs('.sday-guide-promo-slider__track', slider);
41      var slides = qsa('.sday-guide-promo-slider__slide', slider);
42      if (!track || slides.length === 0) return;
43
44      slider.setAttribute('data-slider-ready', '1');
45      var index = 0;
46      var count = slides.length;
47      var dots = qsa('.sday-guide-promo-slider__dot', slider);
48      var prevBtn = qs('.sday-guide-promo-slider__nav--prev', slider);
49      var nextBtn = qs('.sday-guide-promo-slider__nav--next', slider);
50      var startX = 0;
51      var startY = 0;
52      var dragging = false;
53      var locked = false;
54
55      function equalizeHeight() {
56        var maxH = 0;
57        track.style.minHeight = '';
58        slides.forEach(function (slide) {
59          slide.style.minHeight = '';
60        });
61        slides.forEach(function (slide) {
62          var h = slide.offsetHeight;
63          if (h > maxH) maxH = h;
64        });
65        if (maxH > 0) {
66          track.style.minHeight = maxH + 'px';
67          slides.forEach(function (slide) {
68            slide.style.minHeight = maxH + 'px';
69          });
70        }
71      }
72
73      function goTo(next, wrap) {
74        if (count < 1) return;
75        if (count === 1) {
76          index = 0;
77        } else if (wrap !== false) {
78          index = ((next % count) + count) % count;
79        } else {
80          index = Math.max(0, Math.min(count - 1, next));
81        }
82        track.style.transform = 'translateX(-' + index * 100 + '%)';
83        slides.forEach(function (slide, i) {
84          var active = i === index;
85          slide.classList.toggle('is-active', active);
86          if (active) {
87            slide.removeAttribute('aria-hidden');
88          } else {
89            slide.setAttribute('aria-hidden', 'true');
90          }
91          var link = qs('.sday-guide-promo__link', slide);
92          if (link) {
93            if (active) {
94              link.removeAttribute('tabindex');
95            } else {
96              link.setAttribute('tabindex', '-1');
97            }
98          }
99        });
100        dots.forEach(function (dot, i) {
101          var active = i === index;
102          dot.classList.toggle('is-active', active);
103          dot.setAttribute('aria-selected', active ? 'true' : 'false');
104        });
105      }
106
107      function sync() {
108        equalizeHeight();
109        goTo(index, false);
110      }
111
112      slider._sdayGuidePromo = { sync: sync, goTo: goTo };
113
114      if (prevBtn) {
115        prevBtn.addEventListener('click', function (e) {
116          e.preventDefault();
117          e.stopPropagation();
118          goTo(index - 1);
119        });
120      }
121      if (nextBtn) {
122        nextBtn.addEventListener('click', function (e) {
123          e.preventDefault();
124          e.stopPropagation();
125          goTo(index + 1);
126        });
127      }
128      dots.forEach(function (dot) {
129        dot.addEventListener('click', function (e) {
130          e.preventDefault();
131          e.stopPropagation();
132          var to = parseInt(dot.getAttribute('data-slide-to'), 10);
133          if (!isNaN(to)) goTo(to, false);
134        });
135      });
136
137      slider.addEventListener('keydown', function (e) {
138        if (count < 2) return;
139        if (e.key === 'ArrowLeft') {
140          e.preventDefault();
141          goTo(index - 1);
142        } else if (e.key === 'ArrowRight') {
143          e.preventDefault();
144          goTo(index + 1);
145        }
146      });
147
148      function onPointerDown(e) {
149        if (count < 2) return;
150        var t = e.touches && e.touches[0] ? e.touches[0] : e;
151        startX = t.clientX;
152        startY = t.clientY;
153        dragging = true;
154        locked = false;
155      }
156
157      function onPointerMove(e) {
158        if (!dragging || count < 2) return;
159        var t = e.touches && e.touches[0] ? e.touches[0] : e;
160        var dx = t.clientX - startX;
161        var dy = t.clientY - startY;
162        if (!locked) {
163          if (Math.abs(dx) < 8 && Math.abs(dy) < 8) return;
164          locked = Math.abs(dx) > Math.abs(dy);
165          if (!locked) {
166            dragging = false;
167            return;
168          }
169        }
170        if (locked && e.cancelable) e.preventDefault();
171      }
172
173      function onPointerUp(e) {
174        if (!dragging || count < 2) {
175          dragging = false;
176          return;
177        }
178        var t = e.changedTouches && e.changedTouches[0] ? e.changedTouches[0] : e;
179        var dx = t.clientX - startX;
180        dragging = false;
181        if (!locked) return;
182        if (dx <= -40) goTo(index + 1);
183        else if (dx >= 40) goTo(index - 1);
184      }
185
186      var viewport = qs('.sday-guide-promo-slider__viewport', slider) || slider;
187      viewport.addEventListener('touchstart', onPointerDown, { passive: true });
188      viewport.addEventListener('touchmove', onPointerMove, { passive: false });
189      viewport.addEventListener('touchend', onPointerUp, { passive: true });
190
191      if (!slider.hasAttribute('tabindex')) {
192        slider.setAttribute('tabindex', '0');
193      }
194
195      sync();
196    });
197  }
198
199  window.sdayInitGuidePromoSliders = initGuidePromoSliders;
200
201  if (document.readyState === 'loading') {
202    document.addEventListener('DOMContentLoaded', function () {
203      initGuidePromoSliders(document);
204    });
205  } else {
206    initGuidePromoSliders(document);
207  }
208})(window, document);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.