// 裝置判斷 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 .marquee-list").owlCarousel({ items: 1, nav: false, dots: false, autoplay: true, loop: true, autoplayTimeout: 8000, autoplaySpeed: 1000, autoplayHoverPause: true, animateIn: 'slideInUp', animateOut: 'slideOutUp', mouseDrag: false, }); })($) // 螢幕滾動 ;(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() >= 1200 && 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() < 1200 && navbarDevice !== 'mobile') { navbarDevice = 'mobile' // 主選單開關 $('.navbar-toggle').on('click', function(e) { if($('body').hasClass("menu-open")){ $('body').removeClass('menu-open'); }else{ $('.func-item').removeClass('in-active'); $('body').addClass('menu-open'); } }) $('.navbar-wrapper').on('click', function(e) { if(e.target === e.currentTarget) { $('body').removeClass('menu-open'); } }) //形象站主選單開關 $('.display-site .navbar-group').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() >= 1200 && !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() < 1200 || 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) { let item = $(this).parents('.func-item') $('.shopping-cartbox').removeClass('in-open') $('body').removeClass('menu-open') if(item.hasClass('in-active')){ item.removeClass('in-active') }else{ $('.func-item').removeClass('in-active') item.addClass('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(Project_Country+'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 change = 0; /* 手機 */ 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; } var time_id; _window.on('resize',function(){ clearTimeout(time_id); _window = $(window); if(_window.width() <= 1024 && change_1023 ==1200){ $('.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'); }); } }); //點擊率 $(".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:Project_Country+"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:Project_Country+"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",".lang-item",function(){ $.post(Project_Country+'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", ".lang-now", function(){ $('body').removeClass('menu-open') $('.func-item').removeClass('in-active') $(".lang-collapse").addClass("in-active") $(document).one("click", function(e){ if(!$(e.target).parents(".func-lang").length){ $(".lang-collapse").removeClass("in-active") } }) }) //貨到通知改為連至門市 $(document).on('click','.informForPorter',function(){ window.location.href = '/'+$("#Website_Mall_ID").val()+'/store/'; }); }); function errorbox(title,content,button){ var html='