// ========================================================== // 商品列表篩選器開關 // ========================================================== ;(function($) { let filterStep = 0 let asideType = '' $(window).on('resize', function(e) { if (asideType !== 'mobile' && $(window).width() <= 1024) { asideType = 'mobile' filterStep = 0 } else if (asideType !== 'desktop' && $(window).width() > 1024) { asideType = 'desktop' filterStep = 1 } }) $(window).trigger('resize') function filterCheck(step) { if(step) { $('#Main_Content').addClass('aside-open') $('.filter-toggle.func-toggle').text('隱藏搜尋列').prev('span').text('<') } else { $('#Main_Content').removeClass('aside-open') $('.filter-toggle.func-toggle').text('顯示搜尋列').prev('span').text('>') } } $('body').on('click', '.filter-toggle', function(e) { filterStep = (filterStep + 1) % 2 filterCheck(filterStep) }) $('#Main_Content').on('click', function(e) { if(e.target === $('.left-aside')[0] || e.target === $('.aside-closer')[0]) { filterStep = 0 filterCheck(filterStep) } }) filterCheck(filterStep) })($) // ========================================================== // 手機版排序區塊 // ========================================================== ;(function($) { function sortStepCheck(jqElement, step, className) { if(step) { jqElement.addClass(className) } else { jqElement.removeClass(className) } } let sortStep = 0 $('#Main_Content').on('click', '.select-title', function(e) { sortStep = (sortStep + 1) % 2 sortStepCheck($(this).parents('.mobile-select'), sortStep, 'open-click') }) $('#Main_Content').on('click', '.option-list-item', function(e) { const targetText = $(this).text() const targetValue = $(this).data('value') $(this).parents('.mobile-select').find('.select-title').text(targetText) sortStep = 0 sortStepCheck($('.mobile-select'), sortStep, 'open-click') $('#orderbox').val(targetValue) console.log($('#orderbox').val()) }) })($) // ========================================================== // filter group 開關 // ========================================================== ;(function($) { $('#Main_Content').on('click', '.filter-title', function(e) { $(this).parents('.filter-group:not(.checked-group)').toggleClass('in-open'); }) })($) // ========================================================== // 篩選器挑選功能 // ========================================================== ;(function($) { let deviceType = '' const filterArray = [] function filterCount(array, selector) { const arrayAmount = array.length $(selector).text(arrayAmount) } function filterTags(array, wrapper, className) { $(wrapper).empty() array.forEach((item, i) => { const itemEle = `
  • ${item}
  • ` $(wrapper).append(itemEle) }) } function tagCheck(array, value, jqElement, className) { const tagIndex = array.indexOf(value) if(tagIndex !== -1) { array.splice(tagIndex, 1) jqElement.removeClass(className) } else { array.push(value) jqElement.addClass(className) } } function checkedBox(array, selector) { const arrayAmount = array.length if(arrayAmount) { $(selector).slideDown(500) } else { $(selector).slideUp(500) } } $(window).on('resize', function(e) { if ($(this).outerWidth(true) > 1024 && deviceType !== 'desktop') { deviceType = 'desktop' $('.checked-group').removeAttr('style') } else if ($(this).outerWidth(true) <= 1024 && deviceType !== 'mobile') { deviceType = 'mobile' if (filterArray.length) { $('.checked-group').css({ display: 'block', }) } } }) $('#Main_Content').on('click', '.filter-group:not(.checked-group) .filter-list-item', function(e) { const targetValue = $(this).data('value') tagCheck(filterArray, targetValue, $(`[data-value="${targetValue}"]`), 'in-check') filterCount(filterArray, '.filter-box span') filterTags(filterArray, '.checked-group .filter-list', 'filter-list-item cleanItem') if (deviceType === 'mobile') { checkedBox(filterArray, '.checked-group') } }) $('#Main_Content').on('click', '.checked-group span', function(e) { const targetValue = $.trim($(this).parents('.filter-list-item').text()) tagCheck(filterArray, targetValue, $(`[data-value="${targetValue}"]`), 'in-check') filterCount(filterArray, '.filter-box span') filterTags(filterArray, '.checked-group .filter-list', 'filter-list-item') if (deviceType === 'mobile') { checkedBox(filterArray, '.checked-group') } }) $('#Main_Content').on('click', '.filter-clearall', function(e) { filterArray.length = 0 $('.filter-list-item').removeClass('in-check') filterCount(filterArray, '.filter-box span') filterTags(filterArray, '.checked-group .filter-list', 'filter-list-item') if (deviceType === 'mobile') { checkedBox(filterArray, '.checked-group') } }) })($) // ========================================================== // 條件搜尋按鈕 // ========================================================== ;(function($) { function log(obj) { console.log(obj) } $(window).on('scroll', function(e) { const $offsetStart = $('#Main_Content').offset().top + $('#topTitle').outerHeight() - $('.header-fixe').outerHeight() const $offsetEnd = $('.pager').offset().top - $(window).outerHeight(true) + $('.headerBottom').outerHeight() const $winWidth = $(window).outerWidth(true) if($winWidth <= 1024) { if ($(window).scrollTop() >= $offsetStart && $(window).scrollTop() <= $offsetEnd) { $('.mobile-scroll-button').fadeIn('500') } else { $('.mobile-scroll-button').fadeOut('150') } } }) $(window).trigger('scroll') })($) // ========================================================== // 快速購物跳窗 // ========================================================== ;(function($) { $('body').on('click', '.product-quickshop', function(e) { $(this).parents('.productBox').find('.quickshop-box').toggleClass('in-show'); }) })($)