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) { if(!target.data("endTime")){ const totalSeconds = parseInt(target.attr('data-second'), 10) const endTime = Date.now() + totalSeconds * 1000 target.data("endTime", endTime) } const diff = Math.ceil((target.data("endTime") - Date.now()) / 1000) const leftTime = Math.max(0, diff) 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) setTimeout(countDown, 500, target) } else { target.closest(".marquee-countdown").addClass("theme-countover") target.remove() //$(".top-marquee").hide(); $("body").addClass("no-marquee") } } })($) // ========================================================== // 客服開關 // ========================================================== $(function(){ let contactBox = $("#contactbox") $(document).on("click", ".contactbox-toggle", function(e){ contactBox.toggleClass("in-open") }) const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if(entry.isIntersecting){ contactBox.addClass("hide") }else{ contactBox.removeClass("hide") } }) }, { root: null, threshold: 0.01 }) observer.observe($("footer")[0]) }) // 螢幕滾動 ;(function($) { let lastScrolltop = 0 $(window).on('scroll', function(e) { let body = $("body") let currentScrolltop = $(this).scrollTop() if(!body.data("locked")){ 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 }else{ //頁內導轉鎖住header不要讓顯示跳動 body.removeClass('is-upwards').addClass('is-sticky'); } }) })($) // 主選單 ;(function($) { let navbarStep = '' checkMenuBanner() $(window).on('resize', function(e) { checkMenuBanner() 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() }) } }) //選單內banner輪播 function checkMenuBanner(){ $(".navbar-banner-box").each(function(){ let box = $(this) let carouselFlag = false if($(window).width() > 1200){ if(box.find(".navbar-banner").length > 2){ carouselFlag = true } }else{ if(box.find(".navbar-banner").length > 1){ carouselFlag = true } } if(carouselFlag){ box.owlCarousel({ nav : true, navText : ['', ''], dots:false, responsive: { 0: { items : 1, margin: 12 }, 1200: { items : 2, margin: 20 } } }) box.trigger("refresh.owl.carousel") }else{ box.trigger("destroy.owl.carousel") } }) } })($) // gotop ;(function($) { $('.gotop').on('click', function(e){ e.preventDefault() $("html, body").animate({scrollTop: 0},800); }); })($) // 切換國別 ;(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)) }) })($) // ========================================================== // 轉大寫 // ========================================================== ;(function($) { $(document).on("input", ".uppercase", function(){ this.value = this.value.toUpperCase() }) })($) // ========================================================== // 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") }) $(document).on("click", ".popup-trigger-ajax", function(){ //取得說明類編輯器 let _this = $(this) let target = _this.data("target") if(_this.data("loading") !== "1"){ _this.data("loading", "1") $.ajax({ url:Project_Country+"ajax/ajax_get_content.php", type:"POST", data:{ target:target }, dataType:'json', error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d) { if(d.html && d.status =="OK"){ $("body").append(d.html) } _this.data("loading", "") } }) } }) $('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.inform", ".informButton", function () { // $("#informID").val($(this).attr('SID')); $(".popupBox-wrapper[data-index='ArrivalNotify']").removeClass("hide") }); $(document).on("click.informSend", "#informSend", function () { // var email = $("#informEmail").val(); if (!email) { alert('請輸入E-mail'); return false; } var emailRule = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]+$/; if (email.search(emailRule) == -1) { alert('E-mail格式錯誤'); return false; } $.ajax({ url: Project_Country + 'products/ajax/common/ajax_add_prod_inform.php', type: "POST", cache: false, async: false, data: {SID: $("#informID").val(), email: email}, error: function (d) { alert('網路連線過慢,網頁請重新整理'); }, success: function (d) { if (d == 'OK') { alert(_jsLang.您已成功新增一筆補貨通知當商品有貨時我們會儘快通知您); } else { alert(_jsLang.資料庫忙線中); } $(".popupBox-wrapper[data-index='ArrivalNotify']").addClass("hide") } }); }); })($) // ========================================================== // 再買一次 // ========================================================== ;(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 == 'part_ok' && d.msg) { alert(d.msg); if(d.dataLayer)eval(d.dataLayer); window.location.href = d.url; } else if (d.status == 'ok') { if(d.dataLayer)eval(d.dataLayer); window.location.href = d.url; } else if (d.status == 'fail') { alert(d.msg || '加入購物車失敗'); } } }); }); })($) // ========================================================== // 置中判斷 // ========================================================== 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 checkClickToggle(target, classNacheckClickToggleme){ $(document).one("click.", function(e){ if(!$(e.target).parents(target).length){ $(target).removeClass(className) } }) } // ========================================================== // 快速購物跳窗 // ========================================================== ;(function($) { let commonShopcartStep = false $('body').on('click', '.QuickShop:not(.js-quick-add)', 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({ navText: ['', ''], dots: true, margin: 10, items: 1, responsive: { 0: { nav: true, }, 768: { nav: false, } } }) } let mainPreview = $('.quickShop-box .preview-slide') function mainPreviewCarousel(){ function updatePage(e){ let current = e.item.index +1 let total = e.item.count if(mainPreview.find(".page-number").length === 0){ mainPreview.find(".owl-prev").after(``) } mainPreview.find(".page-number").text(current + ' / ' + total) } if(mainPreview.data('owl.carousel')){ mainPreview.data('owl.carousel').destroy() } if(mainPreview.children().length > 1) { mainPreview.owlCarousel({ items: 1, dots: false, margin: 12, nav: true, navText: ['', ''], loop: false, onInitialized: updatePage, onTranslated: updatePage }) } } // moreview 輪播 let moreview = $('.quickShop-box .moreview') function moreviewCarousel(){ if(moreview.data('owl.carousel')){ moreview.data('owl.carousel').destroy() } if($(window).width() > 1200){ if(moreview.find('.picitem').length > 3) { moreview.owlCarousel({ nav: true, dots: false, margin: 8, navText: ['', ''], responsive: { 0: { items: 3, }, 768: { items: 3, }, 1440: { items: 4, }, }, }) } } } moreviewCarousel() mainPreviewCarousel() $(window).on("resize", function(){ mainPreviewCarousel() moreviewCarousel() }) mainPreview.on("previewUpdate", function(){ mainPreviewCarousel() }) moreview.on("moreviewUpdate", function(){ moreviewCarousel() }) } checkBlockScroll() }).fail(function(x, y, z) { console.log(x) }).always(function() { commonShopcartStep = false }) } }) $('body').on('click', '.add_need_login:not(.js-quick-add)', function(e) { AlertPop({ icon: '', string: _jsLang.請先登入會員 || '請先登入會員', }) }) $('body').on('click', '.vip_can_not_add:not(.js-quick-add)', function(e) { AlertPop({ icon: '', string: _jsLang.您不符合此商品的購買資格 || '您不符合此商品的購買資格', }) }) })($) // ========================================================== // 開關上方商品介紹 // ========================================================== ;(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", ".mobile-aside-closer", function(){ $(this).parents(".select-dropdown").toggleClass("in-open") }) $(document).on('click', '.panel-title:not(.theme-link)', function(e){ e.preventDefault() let _this = $(this) if(!_this.parents(".dropdown-list").length){ let panel = _this.closest(".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 = null){ let currentSwitch = $(".float-shopcart .switch-btn.in-current") if(!type){ if(currentSwitch.length){ type = currentSwitch.data("type") }else{ 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)) } shopcartTarget.addClass("in-open") }) .fail(function(x, y, z) { console.log(x); }) .always(function() { CanShowShopcart = true }); } } shopcartTarget.on('click', function(e) { if(shopcartTarget.hasClass("in-open")){ if($(e.target).closest(".cart-inner").length <= 0){ shopcartTarget.removeClass("in-open") $("body").removeClass("header-func-open") } }else{ getTopCart() } }) $(document).on("click", ".cart-closer", function(){ shopcartTarget.removeClass("in-open") $("body").removeClass("header-func-open") }) $(document).on("click", ".float-shopcart .switch-btn", function(){ getTopCart($(this).data("type")) }) //右上購物加減 $(document).on('click', '.floatcart-amount-btn', function(e) { let _this = $(this) let amountBox = _this.parents(".floatcart-amount-box") let input = amountBox.find(".floatcart-amount-input") let plus = amountBox.find(".floatcart-amount-plus") let minus = amountBox.find(".floatcart-amount-minus") let max = parseInt(input.attr("max")) let min = parseInt(input.attr("min")) let val = parseInt(input.val()) if(_this.hasClass("floatcart-amount-plus")){ if(val < max){ input.val(val + 1) input.trigger("change") }else{ let msg = (_jsLang['最多可購買數量'] ??'最多可購買數量') + max; if(input.data("one-page-msg")) { msg = input.data("one-page-msg"); } alert(msg) } }else{ if(val > min){ input.val(val - 1) input.trigger("change") } } if(parseInt(input.val()) == max){ plus.addClass("in-disabled") }else{ plus.removeClass("in-disabled") } }) //右上購物數量 $(document).on("change", ".floatcart-amount-input", function(e){ let input = $(this) let amountBox = input.parents(".floatcart-amount-box") let plus = amountBox.find(".floatcart-amount-plus") let minus = amountBox.find(".floatcart-amount-minus") let max = parseInt(input.attr("max")) let min = parseInt(input.attr("min")) let val = parseInt(input.val()) if(!val && val !== 0){ input.val(min) } if(val > max){ let msg = (_jsLang['最多可購買數量'] ??'最多可購買數量') + max; if(input.data("one-page-msg")) { msg = input.data("one-page-msg"); } input.val(max) alert(msg); } if(val < min){ input.val(min) } if(parseInt(input.val()) == max){ plus.addClass("in-disabled") }else{ plus.removeClass("in-disabled") } updateCartAmount(amountBox) }) //右上購物數量變化 function updateCartAmount(amountBox){ amountBox.find(".floatcart-amount-input,.floatcart-amount-btn").addClass("in-forzen") let amountInput = amountBox.find(".floatcart-amount-input") $.ajax({ url: Project_Country + "shopcart/ajax/ajax_update_num.php", type:"POST", cache:false, dataType:'json', data:$.extend({}, amountInput.data(), { value: amountInput.val() }) }).done(function(d){ if(d.Status && d.Status.includes('RET_SUCCESS')){ amountInput.data("before-change", amountInput.val()) if(d.TotalNum >=0){ $(".cart-total").text(d.TotalNum) } if(d.Alert){ alert(d.Alert); } if(d.DataLayer)eval(d.DataLayer); getTopCart() }else{ if(amountInput.data("before-change")){ if(d.Status != 'RET_SUCCESS_OVER_ACT9'){ amountInput.val(amountInput.data("before-change")) } }else{ amountInput.val(0) } if(d.Alert){ alert(d.Alert); }else{ alert("發生錯誤"); } } }).fail(function(d){ if(amountInput.data("before-change")){ amountInput.val(amountInput.data("before-change")) }else{ amountInput.val(0) } alert('網路連線過慢,網頁請重新整理'); }) } // 浮動窗中商品刪除 $('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').removeClass("in-open") // },3000); }).fail(function(x, y, z) { console.log(x) }) } // ========================================================== // header func行動裝置 // ========================================================== ;(function($){ $(document).on("click.openFloat", ".header .func-btn", function(e){ let item = $(this).parent(".func-item") if($(this).hasClass("mobile-prevent") && $(window).width() < 1200){ e.preventDefault() } if(item.hasClass("in-open")){ $(document).off("click.closeFloat") item.removeClass("in-open") $("body").removeClass("header-func-open") }else{ $(".func-item").removeClass("in-open") item.addClass("in-open") if($(this).hasClass("shopcart-item")){ $("body").addClass("header-func-open") } $(document).off("click.closeFloat") $(document).on("click.closeFloat", function(e){ if($(e.target).closest(".func-item").length <= 0){ $(".func-item").removeClass("in-open") $("body").removeClass("header-func-open") $(document).off("click.closeFloat") } }) } }) })($) //=========================================================== // 直接加入購物車 //=========================================================== function addToCart(sid, amount = 1) { $.ajax({ url: Project_Country + "shopcart/ajax/ajax_cart_add.php", type: "POST", cache: false, data: { "ID": sid, "Amount": amount }, dataType: 'json', error: function (d) { alert('網路連線過慢,網頁請重新整理'); }, success: function (d) { switch (d.Status) { case "RET_SUCCESS": if (d.DataLayer) { eval(d.DataLayer) } AlertPop({ icon: '', string: _jsLang.加入購物車成功, }) updateCartTotal(); break; case "RET_NO_MEMBER_NO": alert(_jsLang.欲購買紅利兌換商品請先登入會員並完成會員認證); break; case "RET_RBONUS_OUT": alert(_jsLang.紅利不足); break; case "RET_ERROR": alert(_jsLang.資料庫忙線中); break; case "RET_PROD_ERROR": alert(_jsLang.商品已下架); break; case "RET_NO_PROD": alert(_jsLang.請選擇商品); break; case "RET_STOCK_ERROR": alert(_jsLang.商品庫存不足); break; case "RET_LIMIT_ERROR": alert(_jsLang.數量超過限購量) break; case "RET_DAILY_LIMIT_ERROR": alert(_jsLang.數量超過每日限購量 || '數量超過每日限購量') break; case "RET_MAX_SALE_QTY_ERROR": alert(_jsLang.此商品已達銷售上限 || '此商品已達銷售上限') break; case "RET_OVER_SIT_MAX": alert(_jsLang.數量超過定期購限購量); break; case "RET_PROD_IN_ONESHOPPAGE_ERROR": alert(_jsLang.此商品於一頁式購物推廣中 + ',' + _jsLang.暫無法加入購物車); break; case "GAME_PLAYED": alert(_jsLang.購物車內有遊戲未結商品無法修改購物車); break; default: alert(_jsLang.資料庫忙線中); break; }; } }); } ;(function($) { //直加按鈕 $(document).on("click", ".js-quick-add", function(){ let _this = $(this) let sid = _this.attr("sid") if(sid){ addToCart(sid, amount = 1) } }) })($) // ========================================================== // 影片預設圖 to iframe 撥放器 // ========================================================== ;(function($) { $(document).on('click', '.StaticVideo', function(e) { e.preventDefault() let _this = $(this) const targetVID = _this.attr('data-vid') const start = _this.data("start") ? `&start=${_this.data("start")}` : '' const end = _this.data("end") ? `&end=${_this.data("end")}` : '' let extra = "" //沒填起始/結束時間則啟用循環 if(start || end){ extra = `${start}${end}` }else{ extra = `&loop=1&playlist=${targetVID}` } let iframe = $('