// ========================================================== // 右側懸浮小廣告開關 // ========================================================== ;(function($) { function bellCheck(step) { if(step % 2) { $('#idx-ad-right').removeClass('theme-close') } else { $('#idx-ad-right').addClass('theme-close') } } let nowBellStep = $('#idx-ad-right').data('step') $('#idx-ad-right').on('click', '.toggle-button:not(.disabled), .floatad-closer', function(e) { e.preventDefault() nowBellStep = (nowBellStep + 1) % 2 // nohide != 1 代表可以關閉 if( $('#idx-ad-right').data('canhide')==1 ){ bellCheck(nowBellStep) } }) })($) // ========================================================== // 蓋版廣告功能 // ========================================================== ;(function($) { if($('.popupAdbox').length) { $('body').addClass('overflow-hidden') } })($) // ========================================================== // 天邊廣告功能 // ========================================================== ;(function($) { if($('.top-adbox').length) { const wrapper = $('.top-adbox') wrapper.on('click', '.top-adbox-button', function(e) { wrapper.toggleClass('in-hidden').attr('tag-status', '2') }) if(wrapper.attr('tag-status') !== '1') { wrapper.addClass('in-hidden') } else { wrapper.removeClass('in-hidden') } } })($) // ========================================================== // 紅眼廣告功能 // ========================================================== ;(function($) { const slideTarget = $('#slideshow') if(slideTarget.length && slideTarget.children().length > 1) { slideTarget.owlCarousel({ items: 1, dots: true, margin: 10, nav: false, loop: true, autoplay: true, autoplayTimeout: 8000, autoplayHoverPause: true, autoplaySpeed: 1000, animateOut: 'fadeOut', animateIn: 'fadeIn', navText: ['', ''], }) } })($) // ========================================================== // 輪播型小廣告 // ========================================================== ;(function($) { const slideTarget = $('.adbox-slide') if(slideTarget.length) { slideTarget.each(function(i, ele) { const target = $(ele) let targetType = null if(target.parents('.adbox').hasClass('adbox-01')) { targetType = 1 } else if(target.parents('.adbox').hasClass('adbox-02')) { targetType = 2 } else if(target.parents('.adbox').hasClass('adbox-03')) { targetType = 3 } if(target.children().length > 1) { target.owlCarousel({ dots: true, margin: 20, loop: true, navText: ['', ''], responsive: { 0: { items: 1, nav: false, }, 768: { items: targetType, nav: true, }, }, }) } }); } })($) // ========================================================== // 新品上市輪播 // ========================================================== ;(function($) { const slideTarget = $('.new-arrivals .arrival-ad') if(slideTarget.length) { if(slideTarget.children().length > 1) { slideTarget.owlCarousel({ nav: true, dots: true, navText: ['', ''], items: 1 }) } } })($) // ========================================================== // 商品評價輪播 // ========================================================== ;(function($) { const slideTarget = $('.review-001 .wrapper') if(slideTarget.length) { if(slideTarget.children().length > 2) { slideTarget.owlCarousel({ nav: true, dots: false, navText: ['', ''], responsive: { 0: { items: 2, margin: 15, loop: true, }, 576: { items: 3, margin: 15, loop: true, }, 768: { items: 4, margin: 15, loop: false, }, 992: { items: 5, margin: 20, loop: false, }, 1200: { items: 5, margin: 30, loop: false, }, 1380: { items: 5, margin: 40, loop: false, }, 1500: { items: 5, margin: 50, loop: false, }, }, }) } } })($) // ========================================================== // 抵用券輪播 // ========================================================== ;(function($) { const slideTarget = $('.index-coupon .coupon-list') function couponCarousel(){ if($(window).width() < 1200){ slideTarget.trigger("destroy.owl.carousel") }else{ if(slideTarget.length) { if(slideTarget.children().length > 1) { slideTarget.owlCarousel({ nav: true, dots: false, navText: ['', ''], responsive: { 0: { items: 1, margin: 15, loop: false, }, 768: { items: 2, margin: 25, loop: false, }, 1200: { items: 3, margin: 25, loop: false, }, }, }) } } } } couponCarousel() $(window).on("resize", couponCarousel) })($) // ========================================================== // 最新消息 // ========================================================== ;(function($) { let newsStep = '' const slideTarget = $('.news-list .wrapper') if(slideTarget.length) { const groupingAmount = Math.floor(slideTarget.children('.item').length / 3) $(window).on('resize', function(e) { if($(this).width() < 576 && newsStep !== 'mobile') { newsStep = 'mobile' for (let i = 0; i < groupingAmount; i++) { slideTarget.children(`.item[group="${i}"]`).wrapAll('
') } slideTarget.owlCarousel({ items: 1, loop: true, nav: true, dots: false, navText: ['', ''], margin: 10, }) } else if($(this).width() >= 576 && newsStep !== 'desktop') { newsStep = 'desktop' if(slideTarget.data('owl.carousel')) { slideTarget.data('owl.carousel').destroy() } slideTarget.find('.news-group').children('.item').unwrap(); } }) } })($) // ========================================================== // 推薦主題商品輪播 // ========================================================== ;(function($) { const slideTarget = $('.tags-001 .tags-wrapper') if(slideTarget.length > 0) { let carouselOption = { navText: ['',''], dots: true, nav: false, loop: false, items: 1, } //輪播並在換頁時同步更新頁簽 slideTarget.each(function(){ slideTarget.owlCarousel(carouselOption); slideTarget.on('changed.owl.carousel', function(e){ let idx = e.item.index, btnbox = $(this).prev('.tags-btnbox'), targetBtn = btnbox.find('.tags-btn').eq(idx), offset = targetBtn.position().left - btnbox.position().left + btnbox.scrollLeft() targetBtn.addClass('active').siblings().removeClass('active') btnbox.animate({ scrollLeft: offset }, 250) }) }) //頁簽點擊 $('.tags-001').on('click', '.tags-btn', function(){ let _this = $(this), idx = _this.index(), carousel = _this.parents('.tags-001').find('.tags-wrapper') carousel.trigger('to.owl.carousel', [idx, 250, true]) }) } })($) // ========================================================== // blog function // ========================================================== ;(function($) { let blogStep = '' const parentWrap = $('.index-blogs') const slideTarget = $('.blog-list') if(parentWrap.length) { // 分類切換 parentWrap.on('click', '.tag-link', function(e) { e.preventDefault() const target = $(this).attr('href') $(this).parents('.tag-item').addClass('in-active') .siblings('.tag-item').removeClass('in-active') $(target).addClass('in-active') .siblings('.content-item').removeClass('in-active') }) // 輪播 $(window).on('resize', function(e) { if($(this).width() >= 768 && blogStep !== 'desktop') { blogStep = 'desktop' slideTarget.each(function(i, ele) { if($(ele).data('owl.carousel')) { $(ele).data('owl.carousel').destroy() } }); } else if($(this).width() < 768 && blogStep !== 'mobile') { blogStep = 'mobile' slideTarget.each(function(i, ele) { if($(ele).children().length > 1) { $(ele).owlCarousel({ items: 1, loop: true, nav: true, dots: false, navText: ['', ''], margin: 10, }) } }); } }) } })($) // ========================================================== // 商品櫥窗快速購物區塊 // ========================================================== ;(function($) { if($('.showcase').length) { let showcaseStep = true $('body').on('mouseenter', '.showcase .HoverShopcart', function(e) { e.preventDefault() const appendTarget = $(this).parents('.item') if(showcaseStep && $(this).attr('sid').length > 0) { showcaseStep = false jQuery.ajax({ url: Project_Country+'ajax/ajax_showcase_shopbox.php', type: 'POST', dataType: 'HTML', cache: false, async: true, data: { sid: $(this).attr('sid'), }, }) .done(function(res) { $('.hover-cart').remove() appendTarget.append(res) let popCart = $('.hover-cart'), datum = appendTarget[0].getBoundingClientRect().top, popHeight = popCart.height() centerVal = ($(window).height() - popHeight) / 2 - datum, //使用此值當top會使彈窗在螢幕置中 contactTopMin = -1 * popHeight,//使彈窗和物件相連的最小top contactTopMax = appendTarget.height(),//使彈窗和物件相連的最大top offset = centerVal if(centerVal > contactTopMax){ offset = contactTopMax }else if(centerVal < contactTopMin){ offset = contactTopMin } popCart.css({ "top": offset }) }) .fail(function(x, y, z) { console.log(x); }) .always(function() { showcaseStep = true }); } }).on('mouseleave', '.showcase .item', function(e) { e.preventDefault() $(this).find('.hover-cart').remove() }) } })($) // ========================================================== // 影音購物輪播 // ========================================================== ;(function($) { const videoSlide = $('.video-area .wrapper') if(videoSlide.children('.item').length > 1) { videoSlide.owlCarousel({ nav: true, navText: ['', ''], loop: true, margin: 20, dots: false, items: 1, autoHeight: true, }) } })($) // ========================================================== // 商品櫥窗、加入購物車彈窗 // ========================================================== ;(function($) { //商品內容 var file_Obj = new prod_file({ type :'1', contBox: 'showcase', itemBox:'hover-cart', }); file_Obj.init(); })($) // ========================================================== // 型錄廣告輪播 // ========================================================== ;(function($) { const lookbookSlide = $('.lookbook .wrapper') if(lookbookSlide.children('.item').length > 1) { lookbookSlide.owlCarousel({ nav: true, navText: ['', ''], loop: true, dots: false, margin: 25, // autoWidth: true, responsive: { 0: { items: 1, }, 768: { items: 2, }, }, }) } })($) // ========================================================== // 今日限定區塊腳本 // ========================================================== function LeadingZero(input, strLength = 2) { let str = String(input) if(str.length < strLength) { str = '0' + str // console.log(str) return LeadingZero(str, strLength) } else { return str } } function CountdownTimer(limitTime, runFunc = () => false) { const now = Date.now() if(limitTime > now) { const leftTimes = limitTime - now const leftSec = Math.floor(leftTimes / 1000) % 60 const leftMin = Math.floor(leftTimes / 1000 / 60) % 60 const leftHour = Math.floor(leftTimes / 1000 / 60 / 60) % 24 const leftDate = Math.floor(leftTimes / 1000 / 60 / 60 / 24) const dateString = (leftDate > 0)? `${LeadingZero(leftDate)}${_jsLang.天}`: ''; runFunc(` ${_jsLang.距離結束}${dateString} ${LeadingZero(leftHour)}${_jsLang.時} ${LeadingZero(leftMin)}${_jsLang.分} ${LeadingZero(leftSec)}${_jsLang.秒} `) setTimeout(CountdownTimer, 1000, limitTime, runFunc) } else { runFunc(`${_jsLang.活動結束}`) } } function CountDown(secondsTarget, runFunc = () => false) { const seconds = secondsTarget.attr('second') let title = secondsTarget.data('title') if(!title){ title = _jsLang.距離結束 } if(seconds > 0) { const leftSec = Math.floor(seconds / 1) % 60 const leftMin = Math.floor(seconds / 1 / 60) % 60 const leftHour = Math.floor(seconds / 1 / 60 / 60) runFunc(` ${title} ${LeadingZero(leftHour)}${_jsLang.時} ${LeadingZero(leftMin)}${_jsLang.分} ${LeadingZero(leftSec)}${_jsLang.秒} `) secondsTarget.attr('second', seconds - 1) setTimeout(CountDown, 1000, secondsTarget, runFunc) } else { runFunc(`${_jsLang.活動結束}`) } } ;(function($) { const todaySale = $('.todaySale') if(todaySale.length) { // 標題文字區塊處理 todaySale.find('.sale-title').each(function(i, ele) { const titleTarget = $(ele) const titleString = titleTarget.text() const appendStr = titleString.split('').reduce(function(prev, ele) { return prev + `${ele}` }, '') titleTarget.html(appendStr) }); // 倒數計時器 todaySale.find('.timerbox').each(function(i, ele) { const target = $(ele) // const targetSeconds = $(ele).attr('second') function outputFunc(input) { target.html(input) } CountDown(target, outputFunc) }); } //商品內容 var file_Obj = new prod_file({ type :'1', contBox: 'todaySale', itemBox:'sale-box', price1Box:'xxx', PopPrice1:'font-insert', specUrl: Project_Country+'activities/ajax/act9/ajax_get_item.php', informUrl : Project_Country+'activities/ajax/act9/ajax_add_notify.php' }); file_Obj.init(); })($) // ========================================================== // trigger function // ========================================================== ;(function($) { $(window).triggerAll('scroll resize') })($)