var upwardsLocked = false const orginalAlert = window.alert; window.alert = function(message){ try { if( typeof message === 'string'){ const parser = new DOMParser(); const doc = parser.parseFromString(message, 'text/html') const decoded = doc.body.textContent || message orginalAlert(decoded) }else{ orginalAlert(message) } }catch(e){ orginalAlert(message) } } // JQ 功能擴增 $.fn.triggerAll = function(list) { return this.each(function() { const $this = $(this) $.each(list.split(' '), function(key, val) { $this.trigger(val) }) }) } // 裝置判斷 function DeviceIsTouch() { const userAgent = navigator.userAgent const regexp = /Android|iPhone|SymbianOS|Windows Phone|iPad|iPod|Touch|Mobile|Tablet|BlackBerry/gi return !!userAgent.match(regexp) } // resize 裝置判斷 ;(function($) { $(window).on('resize', function(e) { if(DeviceIsTouch()) { $('body').removeClass('DeviceWithHover') } else { $('body').addClass('DeviceWithHover') } }) })($) //定義css變數 --vh 避免行動裝置vh計算異常(會被瀏覽器address bar影響) $(function(){ function setVh(){ $('html').attr('style', `--vh: ${window.innerHeight * 0.01}px;`) } setVh() $(window).on('resize', setVh) }) // 天邊跑馬燈設定 ;(function($) { const marqueeTarget = $(".top-marquee") if(marqueeTarget.length && marqueeTarget.children('.marquee-item').length > 1) { marqueeTarget.owlCarousel({ items: 1, nav: false, dots: false, autoplay: true, autoplayTimeout: 5000, autoplaySpeed: 1000, autoplayHoverPause: true, animateIn: 'theme-in', animateOut: 'theme-out', mouseDrag: false, loop: true, }); } //跑馬燈倒數模式 if($('.top-marquee .countdown-box').length) { $('.top-marquee .countdown-box').each(function(){ countDown($(this)) }) } function leadingZero(number) { const num = parseInt(number) if(!isNaN(num)) { if(Math.abs(num) < 10) { return "0" + Math.abs(num) } else { return String(Math.abs(num)) } } else { console.error('輸入格式錯誤') } } function countdownBox(number, string = null) { const numberStr = leadingZero(number) let returnStr = '
' + numberStr + '
' if(string) { return returnStr + '
' + string + '
' } else { return returnStr } } function countDown(target) { const leftTime = target.attr('data-second') if(leftTime > 0) { const leftSec = leftTime % 60 const leftMin = Math.floor(leftTime / 60) % 60 const leftHour = Math.floor(leftTime / 60 / 60) % 24 const leftDate = Math.floor(leftTime / 60 / 60 / 24) if(leftDate > 0) { target.html(`
${countdownBox(leftDate, _jsLang.天)}
${countdownBox(leftHour, _jsLang.時)}
${countdownBox(leftMin, _jsLang.分)}
${countdownBox(leftSec, _jsLang.秒)}
`) } else { target.html(`
${countdownBox(leftHour, _jsLang.時)}
${countdownBox(leftMin, _jsLang.分)}
${countdownBox(leftSec, _jsLang.秒)}
`) } target.attr('data-second', leftTime - 1) setTimeout(countDown, 1000, target) } else { $(".top-marquee").hide(); $("body").addClass("no-marquee") } } })($) // 螢幕滾動 ;(function($) { let lastScrolltop = 0 $(window).on('scroll', function(e) { let currentScrolltop = $(this).scrollTop() if(currentScrolltop > 0){ $('.gotop').fadeIn(400) $("body").addClass('is-sticky'); }else{ $('.gotop').fadeOut(400) $("body").removeClass('is-sticky'); } if(currentScrolltop > lastScrolltop){ $("body").removeClass('is-upwards'); }else{ $("body").addClass('is-upwards'); } lastScrolltop = currentScrolltop }) })($) // 主選單 ;(function($) { let navbarStep = '' $(window).on('resize', function(e) { if($(this).width() >= 1200 && navbarStep !== "desktop") { navbarStep = "desktop" $('body').removeClass('menu-open overflow-hidden'); $('body').off('click.menu', '.navbar-toggle,.navbar-wrapper') $(document).off("click.mainmenu", ".main-item > .main-link .link-anchor") $('.navbar-main').off('click', '.main-menu .navbar-arrow') .find('.with-children').removeClass('in-active') } else if($(this).width() < 1200 && navbarStep !== "mobile") { navbarStep = "mobile" $('body').on('click.menu', '.navbar-toggle,.navbar-wrapper', function(e) { if($(e.target).closest(".navbar-toggle,.navbar-closer").length || $(e.target).hasClass("navbar-wrapper")){ e.preventDefault() $('body').toggleClass('menu-open overflow-hidden'); $('.aside-panel, .function-item').removeClass('in-active'); } }) $('.navbar-main').on('click', '.main-menu .navbar-arrow', function(e) { $(this).closest('.with-children').toggleClass('in-active') .siblings('.with-children').removeClass('in-active') }) $(document).on("click.mainmenu", ".main-item.with-children > .main-link .link-anchor", function(e){ e.preventDefault() $(this).siblings(".navbar-arrow").click() }) } }) })($) // gotop ;(function($) { $('.gotop').on('click', function(e){ e.preventDefault() $("html, body").animate({scrollTop: 0},800); }); })($) // ========================================================== // side menu btn // ========================================================== $(function(){ let asideBtn = $(".aside-quick") const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if(entry.isIntersecting){ asideBtn.addClass("hide") }else{ asideBtn.removeClass("hide") } }) }, { root: null, threshold: 0.01 }) const asideBlock = $("#AsideBlock")[0]; if(asideBlock){ observer.observe($("#AsideBlock")[0]) } }) // 切換國別 ;(function($) { $(document).on("click", ".ship-btn", function(){ let _this = $(this) $.ajax({ type:"POST", url:"/ajax/ajax_change_country.php", dataType:"JSON", data:{ Type:"update", ID: _this.data("id") }, success: function(res){ location.reload() } }) }) })($) // 右上購物車愛心 ;(function($) { $(document).on("click",".favorite-btn",function(){ const _this = $(this) const SID = _this.attr('sid') let icon = _this.find(".icon") let type = 'del' if(!_this.hasClass('in-favorite')){ type = 'add'; } $.ajax({ url: Project_Country+'products/ajax/common/ajax_add_wish_list.php', type:"POST", cache:false, async:false, data:{Type:type,SID:SID}, dataType: 'json', error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ if(d.Msg =='OK'){ if(type == 'add'){ try{ if(d.DataLayer){eval(d.DataLayer)} }catch(e){} _this.addClass("in-favorite"); icon.removeClass("icon-heart-o").addClass("icon-heart") }else{ _this.removeClass("in-favorite"); icon.removeClass("icon-heart").addClass("icon-heart-o") } }else if(d.Msg == 'NO_MEMBER'){ alert(_jsLang.請先登入會員); }else{ alert(_jsLang.資料庫忙線中); } } }); }); })($) //單獨更新購物車紅點 function updateCartTotal(){ $.ajax({ url: Project_Country + "shopcart/ajax/ajax_update_cart_total.php", type:"POST", cache:false, dataType:'json', }).done(function(res){ if(res.TotalNum){ $(".cart-total").text(res.TotalNum) } }).fail(function(d){ alert('網路連線過慢,網頁請重新整理'); }) } // ========================================================== // owl carousel 樣式校正 // ========================================================== ;(function($) { function dotsCheck(jqElement) { const thisTarget = jqElement const checkTarget = thisTarget.find('.owl-dots') if(!checkTarget.hasClass('disabled')) { thisTarget.addClass('with-dots') } else { thisTarget.removeClass('with-dots') } } $('body').on('refreshed.owl.carousel', '.owl-carousel.with-dots', function(e) { dotsCheck($(this)) }) })($) // ========================================================== // footer menu toggle // ========================================================== ;(function($) { $(document).on("click", ".footer-menu .menu-title", function(){ $(this).parents(".menu-item").toggleClass("in-open") }) })($) // ========================================================== // 通用跳窗功能 // ========================================================== ;(function($) { $(document).on("click", ".popup-trigger", function(){ let _this = $(this) let target = _this.data("target") $(".popupBox-wrapper[data-index=" + target + "]").removeClass("hide") }) $('body').on('click', '.popupBox-wrapper:not(.close-disabled)', function(e) { let _this = $(this) if(e.currentTarget === e.target || $(e.target).hasClass('closer') || $(e.target).parent().hasClass('closer') || $(e.target).hasClass('js-popupBox-closer')) { e.preventDefault() if($(e.target).closest(".popupBox-wrapper").hasClass("popupBox-constant")){ $(e.target).closest(".popupBox-wrapper").addClass("hide") }else{ PopupCloseAnimate($(e.currentTarget)) } _this.trigger("popupClose") } }) })($) // ========================================================== // 再買一次 // ========================================================== ;(function($) { //再買一次 $(document).on("click",".Order_Again",function(){ const order_num = $(this).data("order"); $.ajax({ url:Project_Country+"member/ajax/ajax_order_again.php", type:"POST", data:{order_num:order_num,}, dataType:'json', error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d) { if(d.status != 'ok') { alert(d.msg); } else { if(d.dataLayer)eval(d.dataLayer); window.location.href = d.url; } } }); }); })($) // ========================================================== // 置中判斷 // ========================================================== function checkBlockScroll() { let block = $('.check-scroll-block') if(block.length){ if (block[0].scrollWidth > block.innerWidth()) { block.addClass("theme-overwidth") } else { block.removeClass("theme-overwidth") } } } ;(function($) { $(window).on("resize", function () { checkBlockScroll() }) })($) // ========================================================== // 快速購物跳窗 // ========================================================== ;(function($) { let commonShopcartStep = false $('body').on('click', '.QuickShop', function(e) { e.preventDefault() if(!commonShopcartStep) { commonShopcartStep = true jQuery.ajax({ url: Project_Country + 'ajax/ajax_popup_shopbox.php', type: 'POST', dataType: 'html', data: { SID: $(this).attr('SID'), Serial: $(this).attr('serial'), Amount: $(this).parent().find('.amountBox').val(), }, }).done(function(res){ if(res.indexOf('window.location.href=') == 0) { eval(res); } else { $('body').addClass('overflow-hidden').append(res) const slideTarget = $('.quickShop-box .preview-slide') if(slideTarget.length && slideTarget.children('.slide-item').length > 1) { slideTarget.addClass('with-dots').owlCarousel({ nav: true, navText: ['', ''], dots: true, margin: 10, items: 1, }) } } checkBlockScroll() }).fail(function(x, y, z) { console.log(x) }).always(function() { commonShopcartStep = false }) } }) })($) // ========================================================== // 開關上方商品介紹 // ========================================================== ;(function($) { $(document).on('click', '.detail-title', function(e) { let _this = $(this) let box = _this.parents(".detail-wrap") box.toggleClass("in-open") }) })($) // ========================================================== // 展開活動 // ========================================================== ;(function($) { $(document).on('click', '.sale-view-more', function(e) { let _this = $(this) let box = _this.parents(".detail-collapse-box").find(".sale-list") box.toggleClass("in-open") }) })($) // ========================================================== // 跳窗內說明切換 // ========================================================== ;(function($) { $(document).on('click', '.detail-tag', function(e) { let _this = $(this) let target = _this.data("target") $(".detail-wrapper .detail-tag").removeClass("in-active") _this.addClass("in-active") $(".detail-wrapper .detail-content").removeClass("in-active") $(".detail-wrapper .detail-content[data-index='" + target + "']").addClass("in-active") }) })($) // 列表更多資訊開關 ;(function($) { $('main').on('click', '.toggle-expand', function(e) { e.preventDefault(); let parent = $(this).parents('.table-row') if(parent.hasClass("in-expand")){ $(".table-row").removeClass('in-expand') }else{ $(".table-row").removeClass('in-expand') parent.addClass('in-expand') parent.prev(".table-row-normal").addClass('in-expand') parent.next(".table-notebook").addClass('in-expand') } }) })($) // ========================================================== // 側欄選單開關 // ========================================================== ;(function($) { /*$('.aside-panel').on('click', 'a', function(e) { if($(this).parent().hasClass('with-children')) { e.preventDefault() $(this).parent('.with-children').toggleClass('in-active') .siblings('.with-children').removeClass('in-active') } })*/ $('.menu-switch').on('click', function(e){ e.preventDefault() $(this).parents('.with-children').eq(0).toggleClass('in-active') .siblings('.with-children').removeClass('in-active') }) $('.aside-panel').on('click', '.collapse-title', function(e) { e.preventDefault() $(this).parent('.item').toggleClass('in-active') .siblings('.item').removeClass('in-active') }) $(document).on('click', '.panel-title:not(.theme-link)', function(e){ e.preventDefault() let panel = $(this).parents(".aside-panel") panel.find('.panel-body').slideToggle(200, function(){ panel.toggleClass("in-collapse") }) }) })($) // ========================================================== // footer 訂閱電子報功能 // ========================================================== ;(function($) { if($('#EpaperForm').length) { $("body").on('submit', '#EpaperForm', function(e){ e.preventDefault() const enter_str = check_tools.checkEmailNull($("#Epaper_Email")); if( enter_str == "NULL" ){ alert(_jsLang.請輸入Email); return false; }else if( enter_str == "ERROR" ){ alert(_jsLang.您輸入的Email格式錯誤); return false; }else if( enter_str == "PASS" ){ $.ajax({ url: Project_Country + 'include/ajax/ajax_epaper-p.php', type: 'POST', dataType: 'JSON', data: { Epaper_Email: $("#Epaper_Email").val() }, }) .done(function(res) { const status = res.status if(status === "ORDER") { alert(_jsLang.訂閱電子報成功); } else if (status === "CANCEL") { alert(_jsLang.取消訂閱電子報成功); } else if (status === "Usable") { alert(_jsLang.訂閱電子報成功抵用券序號已寄送至您的信箱); } else if(status === "ERROR") { alert(_jsLang.取消訂閱電子報失敗); } }) .fail(function(x, y, z) { console.log(x); }) .always(function() { $("#Epaper_Email").val(''); }); } }); } })($) // ========================================================== // 購物車簡易浮動跳窗 // ========================================================== function FloatShopcart(res) { const returnDOM = `
${res}
` return returnDOM } ;(function($) { const shopcartTarget = $('#Shop_Cart_Total') let CanShowShopcart = true function getTopCart(type = '1'){ if(CanShowShopcart) { CanShowShopcart = false $.ajax({ url: Project_Country + "ajax/ajax_get_cart.php", data:{ Cart_Type : type }, type: 'POST', dataType: 'HTML', }) .done(function(res) { if(shopcartTarget.find(".float-shopcart").length > 0){ shopcartTarget.find(".float-shopcart").empty().html(res) }else{ shopcartTarget.append(FloatShopcart(res)) } }) .fail(function(x, y, z) { console.log(x); }) .always(function() { CanShowShopcart = true }); } } let enterFlag = false shopcartTarget.on('mouseenter', function(e) { if(!enterFlag){ enterFlag = true getTopCart() } }) .on('mouseleave', function(e) { shopcartTarget.children('.float-shopcart').remove() enterFlag = false }) $(document).on("click", ".float-shopcart .switch-btn", function(){ getTopCart($(this).data("type")) }) // 浮動窗中商品刪除 $('body').on('click', '.Left_Top_Del', function(e) { e.preventDefault() // if(confirm(_jsLang.確定刪除嗎+"?")){ $.ajax({ url: Project_Country + "shopcart/ajax/ajax_cart_del.php", type:"POST", cache:false, dataType:'json', data:{ID:$(this).attr("sid"),Type:$(this).data("type"),GroupID: $(this).data("group_id")}, }).done(function(d){ if(d.Status == 'RET_SUCCESS'){ // alert(_jsLang.刪除成功); //window.location.reload(); if (d.DataLayer) { eval(d.DataLayer) } getTopCart() updateCartTotal() }else{ alert(_jsLang.資料庫忙線中); } }).fail(function(d){ alert('網路連線過慢,網頁請重新整理'); }) // } }) })($) function FloatCartPopup(dataObj) { const shopcartTarget = $('#Shop_Cart_Total') $.ajax({ url : Project_Country + "ajax/ajax_get_cart.php", type : "POST", async : true, cache : false, data : dataObj, }).done(function(res) { shopcartTarget.append(FloatShopcart(res)) setTimeout(function(){ shopcartTarget.children('.float-shopcart').remove() },3000); }).fail(function(x, y, z) { console.log(x) }) } // ========================================================== // 影片預設圖 to iframe 撥放器 // ========================================================== ;(function($) { $(document).on('click', '.StaticVideo', function(e) { e.preventDefault() const targetVID = $(this).attr('data-vid') let iframe = $('