//立即購買_取得商品詳細資料 function get_prod_item(SID){ $.ajax({ url:"/module/ajax/ajax_get_pop_prod_item-p.php", type:"POST", cache:false, async:false, dataType:"json", data:{SID:SID}, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ if(d.Size_Sel==''){ if(d.Stock>0){ add_to_cart(SID,1); }else{ alert(_jsLang.商品庫存不足); } }else{ $(".buypop-title").html(d.Name); $('.buypop-word').html(d.Name_Sub); $('.buypop-picbox').html(d.Pic_Path); $('.buypop-price').html('NT$'+d.Price1); $('.buypop-selectbox').html(d.Size_Sel); if(d.Stock>0){ $('.text-smail').val(1); }else{ $('.buypop-buttonbox').html(_jsLang.商品庫存不足); } $('.text-smail').attr('max',d.Stock); $('.buypop-button').attr('sid',d.ID); $('.buypopbox').css('display','flex'); } } }); } //立即購買_加入購物車 function add_to_cart(SID,num){ $.ajax({ url:"/ajax/ajax_add_to_cart.php", type:"POST", cache:false, async:false, data:{SID:SID, num:num, webcacheno:$('#webcacheno').val()}, dataType: 'json', error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ if(d.Stock && d.Stock != 'null'){ d.Stock = (d.Stock>20)?'20':d.Stock; if(d.Stock>0){ $('.text-smail').val(1); }else{ $('.text-smail').val(0); } $('.text-smail').attr('max',d.Stock); } if(d.Alert == 'OK'){ if(d.GA && typeof ga == 'function') { for(var key in d.GA) { ga('ec:addProduct',d.GA[key]); } ga('ec:setAction','add'); ga('send','event','購物車','加入購物車'); } if(d.GA_conversion && typeof gtag == 'function') { gtag('event', 'conversion', {'send_to':d.GA_conversion}); } if(d.GA_conversion_add_shopcar && typeof gtag == 'function') { gtag('event', 'conversion', {'send_to':d.GA_conversion_add_shopcar}); } if(d.FBQ){eval(d.FBQ)} if(d.Appier){ var appierRtAddToCart = [d.Appier]; window.appier_q = window.appier_q || []; window.appier_q.push( {"t": "register", "content": { "id": "da4e", "site": d.Appier_Site }}, {"t": "type_addcart", "itemList":appierRtAddToCart, "action_id": "AddToCart_8d83", "track_id":d.Appier_Track_ID} ); } if(d.Criteo){ window.criteo_q = window.criteo_q || []; var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d"; var CriteoAddToCart = [d.Criteo]; window.criteo_q.push( {event: "setAccount", account: d.Criteo_Account}, {event: "setEmail", email: d.email, hash_method: "sha256"}, {event: "setSiteType", type: deviceType}, {event: "setZipcode", zipcode: d.Zip}, {event: "addToCart", item: [{CriteoAddToCart}]} ); } //加入購物車dataLayer if(d.adGeek) { window.dataLayer = window.dataLayer || []; dataLayer.push({ 'event' : 'productAddCart', 'ecommerce' : { 'currencyCode' : 'TWD', 'add' : { 'products' : d.adGeek } } }); } $.ajax({ url:"/ajax/ajax_get_cart.php", type:"POST", async:false, cache:false, data:{Type:'Prod',ID:SID,Act:'Add'}, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ $("#Header_Shopcart").html(d); $("#Header_Shopcart").parent(".one-cartbox").addClass('in-open'); setTimeout(function(){ $("#Header_Shopcart").parent(".one-cartbox").removeClass('in-open'); },3000); } }) }else{ alert(d.Alert); } } }); } // 立即購買相關功能 $(document).ready(function () { //立即購買 $('body').on('click','.index-buyButton',function(){ var SID = $(this).attr('sid'); if(SID){ get_prod_item(SID); } }); //立即購買_關閉 $('.buypop-close').on('click',function(){ $('.buypopbox').removeAttr('style'); }); //立即購買_規格下拉選單 $(".buypop-selectbox").on('change',".color-select, .size-select",function(){ var SID = $(this).val(); if(SID){ get_prod_item(SID); } }); //立即購買_加入購物車按鈕 $(".buypop-buttonbox").on("click",".buypop-button",function(){ var _item = $(this).parents(".buypop-buttonbox"), SID = $(this).attr('sid') || 0, num = _item.find(".amountBox").val() || 0; if(SID == 0){ alert(_jsLang.請選擇尺寸或規格); //errorbox(); }else if(num ==0){ alert(_jsLang.請選擇數量); //errorbox(); }else{ add_to_cart(SID,num); } }); //立即購買_數量- $('.buypop-num').on('click','.fa-minus',function(){ var now_num = $('.amountBox').val(); now_num = parseInt(now_num); if(now_num>1){ $('.amountBox').val(now_num-1); } }); //立即購買_數量+ $('.buypop-num').on('click','.fa-plus',function(){ var now_num = $('.amountBox').val(); var max_num = $('.amountBox').attr('max'); now_num = parseInt(now_num); max_num = parseInt(max_num); if(now_num < max_num){ $('.amountBox').val(now_num+1); } }); //立即購買_輸入 $('.amountBox').keyup(function(){ var now_num = $('.amountBox').val(); var max_num = $('.amountBox').attr('max'); now_num = parseInt(now_num); max_num = parseInt(max_num); $('.amountBox').val(now_num); if(now_num>max_num){ $('.amountBox').val(max_num); } if(now_num<1){ $('.amountBox').val(1); } if(isNaN(now_num)){ $('.amountBox').val(1); } }); }); // ========================================================== // 首頁蓋版跳窗 // ========================================================== ;(function($) { const popupBlock = $('.pop-block') function popupCheck(checkNum) { if(checkNum === '1') { $('body').addClass('overflow-hidden') } else { $('body').removeClass('overflow-hidden') } } if(popupBlock.length) { popupCheck(popupBlock.attr('popup-status')) popupBlock.on('click', function(e) { if(e.target === e.currentTarget || $(e.target).hasClass('closer')) { popupBlock.attr('popup-status', '0') popupCheck(popupBlock.attr('popup-status')) } }) } })($) // ========================================================== // 天邊廣告 // ========================================================= ;(function($) { $('.top-adbox').on('click', function(e) { if(e.target === e.currentTarget || $(e.target).hasClass('closer')) { e.preventDefault() let tagStatus = $(this).attr('tag-status') tagStatus = (tagStatus * 1 + 1) % 2 if(tagStatus) { tagStatus = tagStatus } else { tagStatus = 2 } console.log(e.target) $(this).attr('tag-status', tagStatus ) } }) })($) // ========================================================== // 紅眼廣告 // ========================================================== ;(function($) { // 首頁主廣告 if($("#slideshow .slide-item").length > 1){ $("#slideshow").owlCarousel({ items: 1, nav: true, dots: true, animateOut: 'fadeOut', animateIn: 'fadeIn', lazyLoad: true, loop: true, autoplayTimeout: 8500, autoplaySpeed: 1000, autoplay: true, autoplayHoverPause: true, }); } // 首頁主廣告 if($(".today-wrapper").length){ var AID = $(".today-wrapper").find(".item").eq(0).attr("AID"); $("#Today_Title_Url").attr("href","/activities9/"+AID) if($(".today-wrapper").children('.item').length > 1) { $(".today-wrapper").owlCarousel({ responsive:{ 0:{ items : 1 }, 480:{ items : 2 }, 768:{ items : 3 }, 992:{ items : 1 } }, margin: 2, nav: false, dots: true, autoplay: true, navSpeed: 1000, autoplayTimeout: 8000, autoplaySpeed: 1000, autoplayHoverPause: true, }); $(".today-wrapper").on('changed.owl.carousel',function(d){ var AID = $(".today-wrapper").find(".item").eq(d.item.index).attr("AID"); $("#Today_Title_Url").attr("href","/activities9/"+AID) }) } } })($) // ========================================================== // 首頁評價區塊 // ========================================================== ;(function($) { let indexWitness = '' $(window).on('resize', function(e) { if($(this).width() < 660 && indexWitness !== 'mobile') { indexWitness = 'mobile' $('.index-witness').each(function(i, ele) { $(ele).owlCarousel({ items: 1, margin: 30, dots: false, nav: true, loop: true, autoplay: true, autoplayTimeout: 5000, autoplaySpeed: 1000, autoplayHoverPause: true, }) }) } else if($(this).width() >= 660 && indexWitness !== 'desktop') { indexWitness = 'desktop' $('.index-witness').each(function(i, ele) { if($(ele).data('owl.carousel')) { $(ele).data('owl.carousel').destroy() } }) } }) })($) // ========================================================== // LOOKBOOK // ========================================================== ;(function($) { if($('.index-lookbook').children('.item').length > 1) { $('.index-lookbook').owlCarousel({ items: 1, dots: false, nav: true, autoplay: true, autoplayHoverPause: true, autoplaySpeed: 1000, autoplayTimeout: 8000, loop: true, }) } })($) // ========================================================== // blog // ========================================================== ;(function($) { if($('.index-blogs').children('.item').length > 1) { $('.index-blogs').owlCarousel({ dots: false, nav: true, autoplay: true, autoplayHoverPause: true, autoplaySpeed: 1000, autoplayTimeout: 5000, loop: true, responsive: { 0: { items: 1, margin: 15, }, 480: { items: 2, margin: 20, }, 660: { items: 3, margin: 25, }, 992: { items: 4, margin: 30, }, }, }) } })($) // ========================================================== // 推薦主題商品 // ========================================================== ;(function($) { let indexTopic = '' $(window).on('resize', function(e) { if($(this).width() >= 660 && indexTopic !== 'desktop') { indexTopic = 'desktop' $('.topic-box').each(function(i, ele) { if($(ele).children('.item').length > 2) { $(ele).owlCarousel({ dots: false, nav: true, loop: true, autoplay: true, autoplaySpeed: 1000, autoplayTimeout: 5000, autoplayHoverPause: true, responsive: { 0: { items: 2, margin: 20, }, 768: { items: 3, margin: 30, }, }, }) } }) } else if($(this).width() < 660 && indexTopic !== 'mobile') { indexTopic = 'mobile' $('.topic-box').each(function(i, ele) { if($(ele).data('owl.carousel')) { $(ele).data('owl.carousel').destroy() } }) } }) })($) // ========================================================== // 今日限定區塊 // ========================================================== ;(function($) { let todaySale = '' $(window).on('resize', function(e) { if($(this).width() >= 660 && todaySale !== 'desktop') { todaySale = 'desktop' $('.todaySale').each(function(i, ele) { if($(ele).data('owl.carousel')) { $(ele).data('owl.carousel').destroy() } }) } else if($(this).width() < 660 && todaySale !== 'mobile') { todaySale = 'mobile' $('.todaySale').each(function(i, ele) { if($(ele).children('.item').length > 1) { $(ele).owlCarousel({ loop: true, nav: true, dots: false, autoplay: true, autoplaySpeed: 1000, autoplayTimeout: 5000, autoplayHoverPause: true, margin: 2, responsive: { 0: { items: 1, }, 480: { items: 2, }, }, }) } }) } }) })($) // ========================================================== // 今日限定倒數 // ========================================================== ;(function($) { $('.todaySale .sale-hint').each(function(i, ele) { function timerCountdown() { const leftSecond = $(ele).attr('second') if(leftSecond) { const toSecond = leftSecond % 60 const toMinute = Math.floor(leftSecond / 60) % 60 const toHour = Math.floor(leftSecond / 60 / 60) let timerString = '' if(toHour < 10) { timerString = timerString + '0' + toHour + ':' } else { timerString = timerString + toHour + ':' } if(toMinute < 10) { timerString = timerString + '0' + toMinute + ':' } else { timerString = timerString + toMinute + ':' } if(toSecond < 10) { timerString = timerString + '0' + toSecond } else { timerString = timerString + toSecond } $(ele).text(timerString) const responseSecond = ((leftSecond - 1) >= 0)? leftSecond - 1: 0 $(ele).attr('second', responseSecond) setTimeout(timerCountdown, 1000) } } timerCountdown() }); })($) // ========================================================== // trigger // ========================================================== ;(function($) { $(window).triggerAll('scroll resize') })($)