$(document).ready(function() { // Handle data-background attributes - must run immediately function applyDataBackgrounds() { $('[data-background]').each(function() { var bgImage = $(this).attr('data-background'); if (bgImage) { var currentBg = $(this).css('background-image'); // Only apply if not already set or is 'none' if (!currentBg || currentBg === 'none' || currentBg === '') { $(this).css('background-image', 'url(' + bgImage + ')'); } } }); } // Apply immediately applyDataBackgrounds(); // Apply again after images load $(window).on('load', function() { applyDataBackgrounds(); }); // Initialize Swiper sliders if (typeof Swiper !== 'undefined') { // Banner Slider var bannerSlider = new Swiper('.banner-slider', { loop: true, speed: 1000, autoplay: { delay: 5500, disableOnInteraction: false, }, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, pagination: { el: '.swiper-pagination', clickable: true, }, }); // Brand Slider var brandSlider = new Swiper('.band__slider', { loop: true, speed: 1000, autoplay: { delay: 3000, disableOnInteraction: false, }, slidesPerView: 5, spaceBetween: 30, breakpoints: { 0: { slidesPerView: 2, }, 576: { slidesPerView: 3, }, 768: { slidesPerView: 4, }, 992: { slidesPerView: 5, }, }, }); // Apply backgrounds after Swiper initialization setTimeout(function() { applyDataBackgrounds(); }, 100); } else { console.warn('Swiper not loaded'); } // Initialize Nice Select plugin if ($.fn.niceSelect) { // Initialize all select elements with nice-select $('select').niceSelect(); // Refresh nice-select when page is fully loaded $(window).on('load', function() { if ($.fn.niceSelect) { $('select').niceSelect('update'); } }); } else { console.warn('Nice Select plugin not loaded'); } // Dropdown on mouse hover const $dropdown = $(".dropdown"); const $dropdownToggle = $(".dropdown-toggle"); const $dropdownMenu = $(".dropdown-menu"); const showClass = "show"; $(window).on("load resize", function() { if (this.matchMedia("(min-width: 992px)").matches) { $dropdown.hover( function() { const $this = $(this); $this.addClass(showClass); $this.find($dropdownToggle).attr("aria-expanded", "true"); $this.find($dropdownMenu).addClass(showClass); }, function() { const $this = $(this); $this.removeClass(showClass); $this.find($dropdownToggle).attr("aria-expanded", "false"); $this.find($dropdownMenu).removeClass(showClass); } ); } else { $dropdown.off("mouseenter mouseleave"); } }); // Scroll Up Button $(window).scroll(function() { if ($(this).scrollTop() > 100) { $('.scroll-up').fadeIn(); } else { $('.scroll-up').fadeOut(); } }); $('.scroll-up').click(function() { $("html, body").animate({ scrollTop: 0 }, 600); return false; }); // Reinitialize nice-select for dynamically added elements $(document).on('DOMNodeInserted', function(e) { if ($.fn.niceSelect && $(e.target).find('select').length) { $(e.target).find('select').niceSelect(); } // Handle data-background for dynamically added elements (e.g., Swiper slides) if ($(e.target).is('[data-background]')) { var bgImage = $(e.target).attr('data-background'); if (bgImage) { $(e.target).css('background-image', 'url(' + bgImage + ')'); } } $(e.target).find('[data-background]').each(function() { var bgImage = $(this).attr('data-background'); if (bgImage) { $(this).css('background-image', 'url(' + bgImage + ')'); } }); }); });