// 裝置判斷 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') } }) })($) // 天邊跑馬燈設定 ;(function($) { $(".marquee-list").marquee({ yScroll: 'down', showSpeed: 1000, pauseSpeed: 8000, pauseOnHover: true, }); })($) // 螢幕滾動 ;(function($) { $(window).on('scroll', function(e) { if($(this).scrollTop() > 0) { $('.gotop').fadeIn(400) $("body").addClass('is-sticky'); } else { $('.gotop').fadeOut(400) $("body").removeClass('is-sticky'); } }) })($) // 主選單 ;(function($) { let navbarDevice = '' let navbarTouch = '' $(window).on('resize', function(e) { // 通用選單 if($(this).width() >= 992 && navbarDevice !== 'desktop') { navbarDevice = 'desktop' // 主選單開關 $('body').removeClass('menu-open'); $('.navbar-toggle').off('click') $('.navbar-wrapper').off('click') // 主選單切換(商品/關於) $('.navbar-label').off('click', '.nav-radio') // 第三層選單項目開闔 $('.navbar-wrapper').find('.with-child').removeClass('in-active') $('.navbar-wrapper').off('click', '.with-child > .child-link') } else if($(this).width() < 992 && navbarDevice !== 'mobile') { navbarDevice = 'mobile' // 主選單開關 $('.navbar-toggle').on('click', function(e) { $('body').toggleClass('menu-open'); }) $('.navbar-wrapper').on('click', function(e) { if(e.target === e.currentTarget) { $('body').removeClass('menu-open'); } }) // 主選單切換(商品/關於) $('.navbar-label').on('click', '.nav-radio', function(e) { $(this).addClass('in-active') .siblings('.nav-radio').removeClass('in-active') }) // 第三層選單項目開闔 // $('.navbar-wrapper').find('.with-child').removeClass('in-active') $('.navbar-wrapper').on('click', '.with-child > .child-link', function(e) { e.preventDefault() $(this).parent('.with-child').toggleClass('in-active') .siblings('.with-child').removeClass('in-active') }) } if($(this).width() >= 992 && !DeviceIsTouch() && navbarTouch !== 'hover') { navbarTouch = 'hover' // 第二層選單項目開闔 $('.navbar-wrapper').find('.with-child').removeClass('in-active') $('.navbar-wrapper').on('click', '.with-child > .navbar-link') } else if(($(this).width() < 992 || DeviceIsTouch()) && navbarTouch !== 'click') { navbarTouch = 'click' // 第二層選單項目開闔 // $('.navbar-wrapper').find('.with-child').removeClass('in-active') $('.navbar-wrapper').on('click', '.with-child > .navbar-link', function(e) { e.preventDefault() $(this).parent('.with-child').toggleClass('in-active') .siblings('.with-child').removeClass('in-active') }) } }) $('.navbar-wrapper').on('mouseenter', '.child-item', function(e) { const itemPicture = $(this).attr('pic') || null const itemLink = $(this).attr('url') || 'javascript:;' if(itemPicture !== null) { $(this).parents('.child-content') .find('.picture-link').attr('href', itemLink) .children('.picture-item').attr('src', itemPicture) } }) // function menu toggle $('.func-menu').on('click', '.able-toggle', function(e) { $(this).parents('.func-item').toggleClass('in-active') }) })($) // gotop ;(function($) { $('.gotop').on('click', function(e){ e.preventDefault() $("html, body").animate({scrollTop: 0},800); }); })($) $(function(){ $(".Select_This_Country").on("click","li,label",function(){ $.post('/ajax/ajax_change_country.php', {ID: $(this).attr('sid')}, function(h){ if (typeof updatePage == "function"){ updatePage(); return false; } if(h){ window.location.reload(); } }, 'html'); }); var _window = $(window); var _body = $('body'); var change_1023 = 0; var nav_item =$('#menu-nav .nav-item'); var body_padding = 121; var body_padding_s = 40; var userAgent = navigator.userAgent; /* 回頁首 */ //上方廣告 var button =0; $('.top_adbox_button').on('click',function(){ if(_window.width() <= 1024){ $(".top_adbox").remove(); if(button == 1)button--; } else{ if(button==0){ $(".top_adbox").css('height', 'auto'); $('.top_adbox .fa').removeClass('fa-plus').addClass('fa-times'); $('.top_adbox .inner').stop().animate({'max-height': 800},1000,function(){ button++; }); }else{ $('.top_adbox .fa').removeClass('fa-times').addClass('fa-plus'); $('.top_adbox .inner').stop().animate({'max-height': 0},1000,function(){ button--; }); } } }); var change = 0; noisePop(); /* 手機平板 */ if(_window.width() <= 1024){ //上方廣告 if($('.top_adbox').attr('tag-status') == '1'){ $('.top_adbox .fa').removeClass('fa-plus').addClass('fa-times'); $(".top_adbox").show(); }; }else{ //上方廣告 if($('.top_adbox').attr('tag-status') == '1'){ $(".top_adbox").show(); $(".top_adbox_button").trigger('click'); }; } /* 手機 */ if(_window.width() <= 480 && change_1023 != 480){ change_1023 = 480; body_padding = 50; /* 平板 */ }else if(_window.width() > 480 && _window.width() <= 1024 && change_1023 != 1023){ change_1023 = 1023; body_padding = 75; body_padding_s = 50; nav_item.find('.subitem').attr('type','checkbox'); /* 電腦 */ }else if(_window.width() > 1023 && change_1023 != 1200){ change_1023 = 1200; body_padding = 121; body_padding_s = 40; //天邊購物車hover下拉 $('#Shop_Cart_Total').on('mouseenter',function(){ $("#Header_Shopcart").load('/ajax/ajax_get_cart.php',''); $('.shopping-cartbox').addClass('open'); }); $('.shopbox').on('mouseleave',function(){ var _this_user=$(this).find('.userbox'), _this_shop=$(this).find('.shopping-cartbox'); if(_this_user.length==1){ $('.userbox').removeClass('open'); }else if(_this_shop.length==1){ $('.shopping-cartbox').removeClass('open'); } }); } var time_id; _window.on('resize',function(){ clearTimeout(time_id); _window = $(window); // noisePop(); if(_window.width() <= 1024 && change_1023 ==1200){ //上方廣告 $('.top_adbox .fa').removeClass('fa-plus').addClass('fa-times'); $('.top_adbox_button').on('click',function(){ $('.top_adbox').remove(); }); $('.shopbox span.fa-user,.shopbox .fa-shopping-cart').off('mouseenter'); //天邊會員登入 var member_click_n=0; $('.shopbox span.fa-user').on('click',function(){ if(member_click_n==0){ member_click_n=1; $('.userbox').addClass('open'); }else{ member_click_n=0; $('.userbox,.shopping-cartbox').removeClass('open'); } }); $('.shopbox').off('mouseleave'); } if(_window.width() <= 480 && change_1023 != 480){ change_1023 = 480; body_padding = 50; }else if(_window.width() > 480 && _window.width() <= 1024 && change_1023 != 1023){ change_1023 = 1023; body_padding = 75; body_padding_s = 50; }else if(_window.width() > 1023 && change_1023 != 1200){ change_1023 = 1200; body_padding = 121; body_padding_s = 40; $('.shopbox span.fa-user').off('click'); //天邊會員登入 $('.shopbox span.fa-user').on('mouseenter',function(){ $('.userbox').addClass('open'); }); //天邊購物車hover下拉 $('.shopbox .fa-shopping-cart').on('mouseenter',function(){ $("#Header_Shopcart").load('/ajax/ajax_get_cart.php',''); $('.shopping-cartbox').addClass('open'); }); $('.shopbox').on('mouseleave',function(){ $('.userbox,.shopping-cartbox').removeClass('open'); }); } }); $("#Noise_Pop").on("click",".fa-times",function(e){ e.preventDefault(); $.ajax({ url:"/ajax/ajax_get_noisePop.php", type:"POST", cache:false, async:false, data:{Type:'Cancel'}, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ $("#Noise_Pop").remove(); } }); }); //點擊率 $(".HITS_BT").on("click",function(e){ e.preventDefault(); if( $.isNumeric($(this).attr('hid')) && $.isNumeric($(this).attr('hdid')) ){ var hid = $(this).attr('hid'); var hdid = $(this).attr('hdid'); var url = $(this).attr('href'); var target = $(this).attr('target'); $.ajax({ url:"/ajax/ajax_add_ad_hits-p.php", type:"POST", cache:false, async:false, data:{Hid: hid , Hdid : hdid}, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ if(url){ if(target == '_blank'){ window.open(url); }else if( ( typeof target === 'undefined' ) || (target == '') ){ window.location = url; }else{ } } } }); }else{ alert(_jsLang.這是錯誤的連結); } }); //讚數加減 $(".Thumbs_BT").on("click",function(e){ e.preventDefault(); if( $.isNumeric($(this).attr('pdid')) ){ var h = $(this); var ID = h.attr('pdid'); var Type = (h.attr('tbup')==1)?'Sub':'Add'; $.ajax({ url:"/ajax/ajax_add_thumbs-p.php", type:"POST", cache:false, async:false, dataType:"json", data:{Type: Type , ID : ID}, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ if(d.Thumbs_Up=='1'){ $('.content').find('.Thumbs'+ID).attr('tbup','1'); $('.content').find('.Thumbs'+ID).find('.Thumbs_icon').removeClass('fa-thumbs-o-up'); $('.content').find('.Thumbs'+ID).find('.Thumbs_icon').addClass('fa-thumbs-up'); }else{ $('.content').find('.Thumbs'+ID).attr('tbup','0'); $('.content').find('.Thumbs'+ID).find('.Thumbs_icon').removeClass('fa-thumbs-up'); $('.content').find('.Thumbs'+ID).find('.Thumbs_icon').addClass('fa-thumbs-o-up'); } $('.content').find('.Thumbs'+ID).find('.Thumbs_Num').html(d.Thumbs_Num); } }); }else{ alert(_jsLang.這是錯誤的連結); } }); //點擊清空輸入框 $(".CLEAR_INPUT").one("click", function(){ $(this).attr('placeholder',''); }); //語系選擇 $(".Select_This_Lang").on("click","li,label",function(){ $.post('/ajax/ajax_change_language.php', {Name: $(this).attr('sid')}, function(h){ window.location.reload(); /*if (typeof updatePage == "function"){ updatePage(); return false; } if(h){ window.location.reload(); }*/ }, 'html'); }); //貨到通知改為連至門市 $(document).on('click','.informForPorter',function(){ window.location.href = '/'+$("#Website_Mall_ID").val()+'/store/'; }); }); function errorbox(title,content,button){ var html=''; $('body').append(html); $('body').on('click', '#popupBox .close', function(event) { $('#popupBox').remove(); }); }; function noisePop(){ if($(window).width()>= 961){ nosise_animate = true; var n = 30;//最大值 var r = Math.floor(Math.random()*n)+1; setTimeout(function(){ $.ajax({ url:"/ajax/ajax_get_noisePop.php", type:"POST", cache:false, async:false, data:{Type:'GET'}, success:function(d){ if(d){ $("#Noise_Pop").prepend(d); setTimeout(function(){ $("#Noise_Pop .noise_box:last").remove(); },5000); setTimeout(function(){ noisePop(); },r*1100); } } }); },r*1000); } } $('main').on('click', '.club-aside', function(event) { $('body').css('position','fixed'); }); $('main').on('click', '.close-m', function(event) { $('body').removeAttr('style'); }); // ========================================================== // footer menu toggle // ========================================================== ;(function($, jQuery, window, document) { let footerMenuStep = ''; $(window).on('resize', function(e) { if($(this).width() >= 768 && footerMenuStep !== 'desktop') { footerMenuStep = 'desktop' $('.footer-menu').off('click', '.title').find('.menu-item').removeClass('in-active') } else if($(this).width() < 768 && footerMenuStep !== 'mobile') { footerMenuStep = 'mobile' $('.footer-menu').on('click', '.title', function(e) { e.preventDefault() $(this).parent('.menu-item').toggleClass('in-active') .siblings('.menu-item').removeClass('in-active') }) } }).trigger('resize') })($, jQuery, window, document) // ========================================================== // 快速購物跳窗規格選擇 // ========================================================== ;(function($) { $('body').on('click', '.choice-item, .checkbox-item', function(e) { $(this).addClass('in-choice').siblings('.choice-item, .checkbox-item').removeClass('in-choice') }) })($) // ========================================================== // 關閉快速購物跳窗 // ========================================================== ;(function($) { //關閉跳窗 $("body").on('click','.selectPopupBox',function(e){ if(e.target === e.currentTarget || $(e.target).hasClass('popup-closer') || $(e.target).hasClass('add_to_cart')) { // e.preventDefault() $('body').removeClass('overflow-hidden') $(".selectPopupBox").removeClass('is-show'); } }); })($) // ========================================================== // 購物車細節 // ========================================================= ;(function($) { //天邊購物車hover下拉 $('#Shop_Cart_Total').on('click', function(e) { e.preventDefault(); $("#Header_Shopcart").load('/ajax/ajax_get_cart.php',''); $('.shopping-cartbox').toggleClass('in-open'); }); })($) // 列表更多資訊開關 ;(function($) { $('main').on('click', '.toggle-expand', function(e) { e.preventDefault(); $(this).parents('.table-row').toggleClass('in-expand') .siblings('.table-row').removeClass('in-expand'); }) })($) // trigger function ;(function($) { $(window).trigger('resize, scroll') })($) // 編輯器index ;(function($) { if($('.web-editor .editor-index').length > 0){ //位置移到第一個h2之後 let indexBox = $(".editor-index"), indexHtml = indexBox.prop("outerHTML"), editor = indexBox.parents(".web-editor") editor.find("h2").eq(0).before(indexHtml) editor.find(".editor-index").eq(1).removeClass("hide") //展開 $(document).on("click", ".editor-index .index-switch", function(){ $(this).parents(".editor-index").toggleClass("theme-collapse") }) //跳轉 $(document).on('click', '.editor-index .index-anchor', function(e) { e.preventDefault() let _this = $(this), headerHeight = $('.header-wrapper').height(), target = $('[data-index=' + _this.data("target") + ']') if(target.length > 0){ $('html, body').animate({ scrollTop: target.offset().top - headerHeight - 10 }) } }) } })($) // ========================================================= // DATALAYER埋設 // ========================================================= //DATALAYER埋設 $(document).on('click','.Prod_Click_DataLayer',function(){ var serial =$(this).attr('serial'); var location =$(this).attr('location'); $.ajax({ url:"/ajax/ajax_click_product.php", type:"POST", cache:false, async:false, data:{ Serial_No:serial, Location:location }, error:function(d){ }, success:function(d){ d = JSON.parse(d); //DATALAYER埋設 if(d.FBQ) { eval(d.FBQ); } } }); });