$(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); } }); //立即購買_取得商品詳細資料 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.FBQ){eval(d.FBQ)} $.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){ //$(".shopping-cartbox").css('display','none'); $("#Header_Shopcart").html(d); $("#Header_Shopcart").parent(".shopping-cartbox").animate({'opacity':1,'maxHeight':'999px'}).css('z-index','100'); setTimeout(function(){ $("#Header_Shopcart").parent(".shopping-cartbox").animate({'maxHeight':'0px','opacity':0},function(){ $(this).removeAttr('style'); $(".shopping-cartbox").removeAttr('style'); }); },3000); } }) }else{ alert(d.Alert); } } }); } //立即購買_數量- $('.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); } }); // 首頁主廣告 if($("#slideshow .slide-item").length>=1){ let slideTimeOut = $("#slideshow").data("millisecond") if(!slideTimeOut){ slideTimeOut = 10000 } $("#slideshow").owlCarousel({ loop : true, items : 1, nav : false, navText : ['',''], dots:true, autoplay:true, animateOut:'fadeOut', autoplayTimeout: slideTimeOut, }); } // 首頁主廣告 if($(".slideshow-004").length!=0){ var AID = $(".today-wrapper").find(".slide-item").eq(0).attr("AID"); $("#Today_Title_Url").attr("href","/activities9/"+AID) $(".today-wrapper").owlCarousel({ loop : false, responsive:{ 0:{ items : 2 }, 660:{ items : 3 }, 1024:{ items : 1 } }, nav : false, navText : ['',''], dots:true, autoplay:true, navSpeed:1000, autoplayTimeout:8000, autoplaySpeed:1000, }); $(".today-wrapper").on('changed.owl.carousel',function(d){ var AID = $(".today-wrapper").find(".slide-item").eq(d.item.index).attr("AID"); $("#Today_Title_Url").attr("href","/activities9/"+AID) }); } // 限時商品 $('.todaySell-silde').owlCarousel({ // loop : true, // items : 5, responsive:{ 0:{ items : 1 }, 480:{ items : 2 }, 960:{ items : 3 } }, nav : true, navText : ['',''], dots:true, }); // 限時商品 $('.hairBaike-wrapper').owlCarousel({ items : 1, nav : true, navText : ['',''], dots:true, animateOut:'fadeOut', // animateIn:'endAnimate' }); var _window = $(window); if(_window.width() <= 768){ $('.video_listWrapper').owlCarousel({ // loop : true, // items : 5, responsive:{ 0:{ items : 3 }, }, margin:5, merge:true, nav :false, navText : ['',''], dots:true, }); } // 限時商品 $('.video-silde').owlCarousel({ // loop : true, // items : 5, responsive:{ 0:{ items : 1 }, 660:{ items : 3 } }, nav : true, navText : ['',''], }); // IG $('.igpicbox-wrapper').owlCarousel({ // loop : true, margin:10, responsive:{ 0:{ stagePadding:50, items : 2 }, 660:{ stagePadding:60, items : 3 }, 1024:{ stagePadding:80, items : 4 }, 1300:{ stagePadding:100, items : 5 } }, loop:true, dots:false, nav : true, navText : ['',''], }); /*setTimeout(function(){ $('#slide_new').fadeIn('slow',function(){ $(this).css({'opacity':1}); }); },1000)*/ //專欄文章 /*$('.columnBaike .wrapper').owlCarousel({ loop : false, // items : 5, margin:15, responsive:{ 0:{ items : 1, }, 660:{ items : 2, }, 1300:{ items : 3, } }, navText : ['',''], nav :false, dots:true, });*/ //試用評價 $('.review-001 .warpper').owlCarousel({ // loop : true, // items : 5, responsive:{ 0:{ items : 2, margin: 15 }, 1025:{ items : 3, margin: 30 }, }, navText : ['',''], nav :false, dots:true, }); $('.picbox').on('translated.owl.carousel',function(event){ var id = $(this).find('.active').eq(0).find('.pic-item').attr('did'); ajax_topic_content(id, $(this)); }); function ajax_topic_content(topic_id, topic_box){ $.ajax({ url:"/module/ajax/ajax_get_topic_content-p.php", type:"POST", cache:false, async:false, dataType:"json", data:{ID:topic_id}, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ topic_box.parents(".compilation-box").find(".web-editor").html(d.Content); } }); } //今日限定 /*$(".todaySale").find(".sellbox").each(function(){ var num = parseInt($(this).find(".timerbox").attr("second"),10), _this = $(this); setInterval(function(){ num--; if(num <= 0) { window.location.reload(); } var hour = Math.floor(num/3600), min = Math.floor((num - (hour*3600) )/60 ), second = num - (hour*3600) - (min*60), pad = '00'; _this.find(".timer").eq(0).html(pad.substring(hour.toString().length)+hour); _this.find(".timer").eq(1).html(pad.substring(min.toString().length)+min); _this.find(".timer").eq(2).html(pad.substring(second.toString().length)+second); },1000); });*/ //今日限定-整個檔期 todaySaleFull($(".todaySale-event-countdown")) // ========================================================== // 折價券 // ========================================================== $('.index-coupon .coupon-list').owlCarousel({ loop : true, margin: 25, navText : ['',''], responsive:{ 0:{ items : 1, nav : false, dots: true, }, 769:{ items : 2, nav : false, dots: true, }, 1201:{ items : 3, nav : true, dots: false, } }, }); //================================= // 浮動廣告 start //================================= //檢查localStorage let floatAd = $(".index-float-ad") if(localStorage.getItem("floatAdCloseDate")){ //曾經關掉過 let today = new Date() let todayString = today.getFullYear() + "-" + (today.getMonth()+1) + "-" + today.getDate() if(localStorage.getItem("floatAdCloseDate") != todayString){ //不是今天 floatAd.removeClass("hide") } }else{ //沒有紀錄 floatAd.removeClass("hide") } floatAd.on("click", function(e){ if(!$(this).hasClass("open") && !$(e.target).hasClass("index-float-close")){ $(this).addClass("open") } }) floatAd.on("click", ".float-ad-close", function(e){ e.stopPropagation() let floatAd = $(".index-float-ad") if(floatAd.hasClass("open")){ floatAd.removeClass("open") floatAd.addClass("hide") let today = new Date() //月份由0~11所以要+1 localStorage.setItem("floatAdCloseDate",(today.getFullYear() + "-" + (today.getMonth()+1) + "-" + today.getDate())) } }) //================================= // 浮動廣告 end //================================= //=============================== // 首頁分頁區塊 //=============================== $(".index-page-group").on("click", ".page", function(){ let targetPage = $(this).attr("send"), pageBox = $(this).parent(".pure-bottom-page"), nowPage = pageBox.find(".now").attr("send"), totalPage = pageBox.data("total-page"), prodWrapper = pageBox.parents(".index-module-prodwrapper"), targetUrl = pageBox.data("target-url"), pageItem = pageBox.data("page-item"), extraID = pageBox.data("extra-id") || '', parent = $(this).parents(".index-page-group") if(targetPage != nowPage){ $.ajax({ url: targetUrl, type:"POST", data:{ "totalPage": totalPage, //總頁數 "targetPage": targetPage, //目標頁數 "pageItem": pageItem, //一頁幾個 "extraID": extraID //若有需要才賦值 }, success:function(d){ prodWrapper.html(d) //換頁後回到頂端 if(parent[0].getBoundingClientRect().top < $(".header-01").height()){ $("html,body").animate({ scrollTop: parent[0].getBoundingClientRect().top + $(window).scrollTop() - $(".header-01").height() }, 200) } }, error:function(d){ alert('網路連線過慢,網頁請重新整理'); } }) } }) //首頁專題/型錄廣告 $(".compilation-carousel").owlCarousel({ items:1, nav:false, dots:true }) //================== //首頁輪播 //================== adboxCarousel($("#adbox_3 .col-33"), $("#adbox_3 .floatBox")) adboxCarousel($(".adbox4-item"), $(".adbox4-box")) //prodCarousel($(".prodwrapper-item"), $("#slide_new")) //videoCarousel($(".video-item"), $(".video-carousel")) $(window).on("resize", function(){ adboxCarousel($("#adbox_3 .col-33"), $("#adbox_3 .floatBox")) adboxCarousel($(".adbox4-item"), $(".adbox4-box")) //prodCarousel($(".prodwrapper-item"), $("#slide_new")) //videoCarousel($(".video-item"), $(".video-carousel")) }) //================== // 推薦主題商品 //================== $(document).on("change",".tag-radio", function(){ let _this = $(this) target = _this.data("target"), parent = _this.parents(".tags-001") parent.find(".itembox").removeClass("show") parent.find("." + target).addClass("show") }) }); //三/四個小廣告 function adboxCarousel(item, carouselbox){ if($(window).width() < 481){ if(item.length > 0){ carouselbox.owlCarousel({ items: 1, nav : true, dots: false, }) } }else{ carouselbox.trigger("destroy.owl.carousel") } } //新品/ function prodCarousel(item, carouselbox){ if($(window).width() < 768){ carouselbox.trigger("destroy.owl.carousel") }else{ if(item.length > 0){ carouselbox.owlCarousel({ responsive:{ 0:{ items:2, margin:15, slideBy:2 }, 769:{ items:3, margin:30, slideBy:3 }, 1025:{ items:3, margin:43, slideBy:3 }, 1681:{ items:3, margin:60, slideBy:3 } }, nav : true, dots: false, }) } } } //video function videoCarousel(item, carouselbox){ if($(window).width() < 768){ carouselbox.trigger("destroy.owl.carousel") }else{ if(item.length > 0){ carouselbox.owlCarousel({ responsive:{ 0:{ items:1, margin:0, slideBy:1 }, 769:{ items:2, margin:30, slideBy:2 }, 1025:{ items:3, margin:43, slideBy:3 } }, nav: true, dots: false }) } } } //今日限定-整個檔期 function todaySaleFull(target){ /*var num = parseInt($(this).find(".timerbox").attr("second"),10), _this = $(this); setInterval(function(){ num--; if(num <= 0) { window.location.reload(); } var hour = Math.floor(num/3600), min = Math.floor((num - (hour*3600) )/60 ), second = num - (hour*3600) - (min*60), pad = '00'; _this.find(".timer").eq(0).html(pad.substring(hour.toString().length)+hour); _this.find(".timer").eq(1).html(pad.substring(min.toString().length)+min); _this.find(".timer").eq(2).html(pad.substring(second.toString().length)+second); },1000);*/ let num = parseInt(target.data("time"),10), rotors = target.find(".countdown-rotor") let temp = num, timeArray = "" let day = Math.floor(temp/86400) temp = temp % 86400 let hour = Math.floor(temp / 3600) temp = temp % 3600 let min = Math.floor(temp / 60) temp = temp % 60 let second = temp timeArray += (day < 10) ? "0" + day : day timeArray += (hour < 10) ? "0" + hour : hour timeArray += (min < 10) ? "0" + min : min timeArray += (second < 10) ? "0" + second : second if(timeArray.length > 8){ for(let i = 0; i < timeArray.length - 8; i++){ target.find(".day-group .countdown-rotor").eq(0).before(`
0
`) } rotors = target.find(".countdown-rotor") } for(let i in timeArray){ let rotor = rotors.eq(i), num = timeArray[i] rotor.text(num) } setInterval(function(){ num-- let tempNum = 0, carryFlag = false, tempCount = 0 if(num <= 0){ window.location.reload(); } //sec個位 tempCount = num % 10 carryFlag = (tempCount == 9) ? true : false tempNum = Math.floor(num/10) flipUpdate(rotors.eq(-1), tempCount) //sec十位 if(carryFlag){ tempCount = tempNum % 6 carryFlag = (tempCount == 5) ? true : false tempNum = Math.floor(tempNum/6) flipUpdate(rotors.eq(-2), tempCount) } //min個位 if(carryFlag){ tempCount = tempNum % 10 carryFlag = (tempCount == 9) ? true : false tempNum = Math.floor(tempNum/10) flipUpdate(rotors.eq(-3), tempCount) } //min十位 if(carryFlag){ tempCount = tempNum % 6 carryFlag = (tempCount == 5) ? true : false tempNum = Math.floor(tempNum/6) flipUpdate(rotors.eq(-4), tempCount) } //hour個位/十位 if(carryFlag){ tempCount = tempNum % 24 carryFlag = (tempCount == 23) ? true : false tempNum = Math.floor(tempNum/24) let hourDigits = tempCount % 10, hourTens = Math.floor(tempCount/10) flipUpdate(rotors.eq(-5), hourDigits) if(tempCount == 9 || tempCount == 19 || tempCount == 23){ flipUpdate(rotors.eq(-6), hourTens) } } for(let i = 7; i < timeArray.length+1; i++){ //day if(carryFlag){ tempCount = tempNum % 10 carryFlag = (tempCount == 9) ? true : false tempNum = Math.floor(tempNum/10) flipUpdate(rotors.eq(-i), tempCount) } } },1000) } function flipUpdate(target,num){ setTimeout(function(){ target.text(num) },500) }