$(function(){ const owlObj = { dots: false, margin: 20, nav: true, navText: ['', ''], responsive: { 0: { items: 2, }, 576: { items: 3, }, 768: { items: 4, }, 1200: { items: 5, }, }, } $('.article-slide').owlCarousel(owlObj) let asideStep = '' $(window).on('resize', function(e) { e.preventDefault() if($(this).width() >= 1200 && asideStep !== 'desktop') { asideStep = 'desktop' $('.article-list').each(function(i, ele) { if($(ele).data('owl.carousel')) { $(ele).data('owl.carousel').destroy() } }) } else if($(this).width() < 1200 && asideStep !== 'mobile') { asideStep = 'mobile' $('.article-list').owlCarousel(owlObj) } }).trigger('resize') }) // ========================================================== // 手機版次級選單開關 // ========================================================== ;(function($) { let menuStep = '' $(window).on('resize', function(e) { if($(this).width() >= 1200 && menuStep !== 'desktop') { menuStep = 'desktop' $(document).off('click', '.with-child > a') } else if($(this).width() < 1200 && menuStep !== 'mobile') { menuStep = 'mobile' $(document).on('click', '.with-child > a', function(e) { e.preventDefault() $(this).parent('.with-child').toggleClass('in-active') .siblings('.with-child').removeClass('in-active') }) } }).trigger('resize') })($) // ========================================================== // 排序展開 // ========================================================== ;(function($) { $(document).on("click", ".dropdown-btn", function(){ let box = $(this).parents(".select-dropdown") if(box.hasClass("in-open")){ box.removeClass("in-open") $(document).off("click.closeDropdown") }else{ $(".select-dropdown").removeClass("in-open") box.addClass("in-open") $(document).on("click.closeDropdown", function(e){ let target = $(e.target) if(target.closest(".select-dropdown").length <= 0){ box.removeClass("in-open") $(document).off("click.closeDropdown") } }) } }) $(document).on("click", ".dropdown-item", function(){ let _this = $(this) let box = _this.parents(".select-dropdown") let target = box.data("target") if(_this.hasClass("selected")){ $(target).val("").trigger("change") _this.removeClass("selected") box.removeClass("in-selected") }else{ $(target).val(_this.data("value")).trigger("change") _this.siblings().removeClass("selected") _this.addClass("selected") box.addClass("in-selected") } }) })($)