/** * AKSRT Hero & Swiper Initialization */ (function () { "use strict"; window.AksrtSwipers = { new: [], scroll: [], tab: [] }; function initHeroSlider() { if (typeof Swiper === "undefined") return; // ===== Type A: .swiper-scroll ===== document.querySelectorAll(".swiper-scroll:not(.swiper-initialized)").forEach(function (el, index) { var c_w = el.offsetWidth; var firstSlide = el.querySelector(".swiper-wrapper > *"); var i_w = firstSlide ? firstSlide.offsetWidth : 200; var slidesPerGroup = Math.max(1, Math.floor(c_w / i_w)); var option = { slidesPerView: "auto", freeMode: true, freeModeSticky: true, mousewheel: { forceToAxis: true }, slidesPerGroup: slidesPerGroup, autoplay: el.dataset.autoplay ? { delay: parseInt(el.dataset.interval || "4000", 10), disableOnInteraction: false, } : false, loop: !!el.dataset.loop, navigation: { nextEl: el.querySelector(".swiper-button-next"), prevEl: el.querySelector(".swiper-button-prev"), }, }; el.classList.add("swiper-scroll-eq-" + index); el.setAttribute("swiper-scroll-index", String(index)); window.AksrtSwipers.scroll[index] = new Swiper(el, option); }); // ===== Type B: .swiper-tab ===== document.querySelectorAll(".swiper-tab:not(.swiper-initialized)").forEach(function (el, index) { var speed = parseInt(el.dataset.speed || "0", 10) || Math.floor((el.offsetWidth + 1200) / 170) * 50; speed = Math.max(300, speed); var initialSlide = parseInt(el.getAttribute("active-index") || "0", 10); var option = { loop: false, initialSlide: initialSlide, autoHeight: true, spaceBetween: 20, autoplay: false, speed: speed, pagination: { el: el.querySelector(".swiper-pagination"), clickable: true, }, }; var tabId = el.getAttribute("swiper-tab"); if (tabId) { var tabNav = document.querySelector('[swiper-tab-nav="' + tabId + '"]'); if (tabNav && tabNav.swiper) { option.thumbs = { swiper: tabNav.swiper, autoScrollOffset: 2, }; } } el.classList.add("swiper-tab-eq-" + index); el.setAttribute("swiper-tab-index", String(index)); window.AksrtSwipers.tab[index] = new Swiper(el, option); }); // ===== Type C: .new-swiper ===== // Prefer data-swiper-config JSON (used by hero/banner templates), then data-* attrs. document.querySelectorAll(".new-swiper:not(.swiper-initialized)").forEach(function (el, index) { var jsonConfig = null; if (el.dataset.swiperConfig) { try { jsonConfig = JSON.parse(el.dataset.swiperConfig); } catch (e) { jsonConfig = null; } } if (!jsonConfig || typeof jsonConfig !== "object") { jsonConfig = {}; } var delay = parseInt(el.dataset.interval || "6000", 10); if (jsonConfig.autoplay && typeof jsonConfig.autoplay === "object" && jsonConfig.autoplay.delay) { delay = parseInt(jsonConfig.autoplay.delay, 10) || delay; } var autoplay; if (Object.prototype.hasOwnProperty.call(jsonConfig, "autoplay")) { autoplay = jsonConfig.autoplay; } else if (el.dataset.autoplay !== undefined) { autoplay = { delay: delay, disableOnInteraction: false, }; } else { autoplay = false; } var speed = parseInt(el.dataset.speed || "0", 10) || Math.floor((el.offsetWidth + 1000) / 22) * 10; if (jsonConfig.speed) { speed = parseInt(jsonConfig.speed, 10) || speed; } speed = Math.max(400, speed); if (!autoplay) speed = Math.floor(speed / 1.6); var loop = Object.prototype.hasOwnProperty.call(jsonConfig, "loop") ? !!jsonConfig.loop : !!el.dataset.loop; var parallax = !!el.querySelector("[data-swiper-parallax],[data-swiper-parallax-scale]"); var effect = jsonConfig.effect || el.dataset.effect || "slide"; var direction = jsonConfig.direction || el.dataset.direction || "horizontal"; var spaceBetween = Object.prototype.hasOwnProperty.call(jsonConfig, "spaceBetween") ? parseInt(jsonConfig.spaceBetween, 10) || 0 : parseInt(el.dataset.spaceBetween || "0", 10); var paginationType = el.dataset.paginationType || "bullets"; var autoHeight = Object.prototype.hasOwnProperty.call(jsonConfig, "autoHeight") ? !!jsonConfig.autoHeight : el.hasAttribute("auto-height"); // Fixed-ratio modules (banner card) must not use autoHeight — it collapses absolute slides. if (el.classList.contains("banner-module__swiper") || el.classList.contains("scale-height")) { autoHeight = false; } var paginationEl = el.querySelector(".swiper-pagination, .header-components__pagination"); var prevBtn = el.querySelector(".swiper-button-prev, .banner-module__prev"); var nextBtn = el.querySelector(".swiper-button-next, .banner-module__next"); var pagination = false; if (Object.prototype.hasOwnProperty.call(jsonConfig, "pagination")) { if (jsonConfig.pagination === false) { pagination = false; } else if (jsonConfig.pagination && typeof jsonConfig.pagination === "object") { pagination = Object.assign( { el: paginationEl, clickable: true, }, jsonConfig.pagination ); if (!pagination.el) pagination.el = paginationEl; if (!pagination.el) pagination = false; } else if (jsonConfig.pagination) { pagination = paginationEl ? { el: paginationEl, type: paginationType, clickable: true } : false; } } else { pagination = paginationEl ? { el: paginationEl, type: paginationType, clickable: true } : false; } var navigation = false; if (Object.prototype.hasOwnProperty.call(jsonConfig, "navigation")) { if (jsonConfig.navigation === false) { navigation = false; } else if (jsonConfig.navigation === true || jsonConfig.navigation) { navigation = prevBtn && nextBtn ? { nextEl: nextBtn, prevEl: prevBtn } : false; } } else { navigation = { nextEl: nextBtn, prevEl: prevBtn, }; } var keyboard = Object.prototype.hasOwnProperty.call(jsonConfig, "keyboard") ? jsonConfig.keyboard : { enabled: true }; el.classList.add("swiper-new-eq-" + index); el.setAttribute("swiper-new-index", String(index)); var swiperArgs = { loop: loop, autoHeight: autoHeight, direction: direction, spaceBetween: spaceBetween, parallax: parallax, effect: effect, lazy: { loadPrevNext: true }, autoplay: autoplay, speed: speed, pagination: pagination, navigation: navigation, keyboard: keyboard, a11y: { prevSlideMessage: "上一张", nextSlideMessage: "下一张" }, on: { lazyImageReady: function (slideEl, imageEl) { if (imageEl) imageEl.classList.add("lazyloaded"); }, slideChange: function () { el.querySelectorAll(".aksrt-dplayer, video").forEach(function (media) { if (media.pause) media.pause(); var dp = media.closest("[data-dplayer]"); if (dp && dp._dplayer) dp._dplayer.pause(); }); }, init: function () { if (loop) { el.querySelectorAll(".swiper-slide-duplicate img").forEach(function (img) { img.classList.add("no-imgbox"); }); } }, }, }; if (effect === "fade") { swiperArgs.fadeEffect = Object.assign( { crossFade: true }, (jsonConfig.fadeEffect && typeof jsonConfig.fadeEffect === "object") ? jsonConfig.fadeEffect : {} ); } if (pagination && paginationType === "thumbnail") { swiperArgs.pagination.type = "bullets"; swiperArgs.pagination.bulletClass = "pagination-thumbnail-item"; swiperArgs.pagination.bulletActiveClass = "pagination-thumbnail-item-active"; swiperArgs.pagination.renderBullet = function (idx, className) { var slide = this.slides[idx]; if (!slide) return ""; var img = slide.querySelector("img"); var src = img ? (img.dataset.src || img.src) : ""; if (src) { return '