// 裝置判斷 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=''; $('body').append(html); $('body').on('click', '#popupBox .close', function(event) { $('#popupBox').remove(); }); }; $('main').on('click', '.club-aside', function(event) { $('body').css('position','fixed'); }); $('main').on('click', '.close-m', function(event) { $('body').removeAttr('style'); }); // ========================================================== // 通用折疊區塊 // ========================================================== $(function(){ $(document).on("click", ".collapse-title", function(){ let wrapper = $(this).parent(".collapse-wrapper") wrapper.toggleClass("in-open") }) }) // ========================================================== // 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(){ //購物彈窗 $(document).on('click','button.shopping-link',function(){ var sid = $(this).attr('SID'), wrapper = $(this).parent(".wrapper") $.ajax({ url:Project_Country + "products/ajax/list/ajax_get_prod_quick.php", type:"POST", data:{type:1,SID:sid,prodlimit:wrapper.data("limit"),prodtype:wrapper.data("type")}, dataType: 'json', async: false, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ let quickWrapper = $('.quickshop-wrapper') quickWrapper.html(d.data); quickWrapper.addClass("open") quickWrapper.data("limit",wrapper.data("limit")) quickWrapper.data("type",wrapper.data("type")) //$("body").addClass("overflow-hidden") } }) }); //關閉快速購物彈窗 $(document).on("click", ".quickshop-close", function(e){ $(this).parents(".quickshop-wrapper").removeClass("open") $("body").removeClass("overflow-hidden") }) $(".quickshop-wrapper").on("click", function(e){ if($(e.target).hasClass("quickshop-wrapper")){ $(this).removeClass("open") $("body").removeClass("overflow-hidden") } }) }) //=========================================================== // 桌機橫式scrollbar拖動 start //=========================================================== $(function(){ function updateScrollPosition(e, containerJqueryObj, position){ containerJqueryObj.scrollLeft(position.left + position.x - e.clientX) } //載入時定位 let mallNow = $(".hall-nav-item.focus") if(mallNow.length > 0){ let offset = mallNow[0].getBoundingClientRect().left - ($(window).width() - mallNow.width()) / 2 + 15 if(offset > 0){ $(".hall-scroll").scrollLeft( mallNow[0].getBoundingClientRect().left - ($(window).width() - mallNow.width()) / 2 ) } } $(".hall-scroll").each(function(){ let _target = $(this) let _grabed = false let _position = {left: 0, x: 0} let specialChild = _target.find("img, a") let clickFlag = false let bindMousemove = function(e){ if(_grabed){ updateScrollPosition(e, _target, _position) } } let bindMouseup = function(e){ _grabed = false _target.css({ "cursor": "grab", "user-select": "initial" }) $(document).off("mouseup", bindMouseup) $(document).off("mousemove", bindMousemove) } specialChild.prop("draggable", false).on("dragstart", function(){ return false; }) _target.on({ "mousedown": function(e){ if(_target[0].clientWidth < _target[0].scrollWidth){ _target.css({ "cursor": "grabbing", "user-select": "none" }) _grabed = true _position = { left: _target.scrollLeft(), x: e.clientX } $(document).on("mouseup", bindMouseup) $(document).on("mousemove", bindMousemove) clickFlag = true setTimeout(function(){ //短觸視為click clickFlag = false },200) }else{ clickFlag = true } }, "click": function(e){ if(!clickFlag){ e.preventDefault() } } }) }) }) // ========================================================== // 購物車細節 // ========================================================= ;(function($) { //天邊購物車 $('#Shop_Cart_Total').on('click', function(e) { if($(window).width() > 1199){ e.preventDefault(); let item = $(this).parents(".func-item") $("#Header_Shopcart").load(Project_Country+'ajax/ajax_get_cart.php',''); $('.shopping-cartbox').toggleClass('in-open'); if(item.hasClass('in-active')){ item.removeClass('in-active'); }else{ $('.func-item').removeClass('in-active') item.addClass('in-active'); } } }); })($) // 列表更多資訊開關 ;(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') })($) // ========================================================= // footer menu // ========================================================= $(function(){ $(document).on("click", ".footer .menu-item", function(e){ let winWidth = $(window).width(), target = $(e.target) if(winWidth < 1200 && (target.hasClass("menu-item") || target.hasClass("menu-title") )){ $(this).toggleClass("open") } }) })