// ========================================================== // 重設 baike 定位值 // ========================================================== ;(function($) { $('.navBox').on('click', '.menu_class_a', function(e) { const menuLink = $(this).attr('href') if(menuLink === '/baike/') { sessionStorage.setItem('baikeOffset', 0) } }) })($) $(function() { /*後端*/ $(".menu_class_a, .menu_sub_a").mouseover(function() { var pic = $(this).attr('pic'); var url = $(this).attr('url'); var href = (url) ? url : 'javascript:;'; var h = (pic) ? '' : ''; $(this).parents('.item-subitembox').find('.picbox').html(h); }); $(".menu_sub_a").mouseout(function() { var pic = $(this).parents('.nav-item').find('.menu_class_a').attr('pic'); var url = $(this).parents('.nav-item').find('.menu_class_a').attr('url'); var href = (url) ? url : 'javascript:;'; var h = (pic) ? '' : ''; $(this).parents('.nav-item').find('.item-subitembox').children('.picbox').html(h); }); $(".marquee").marquee(); $("#Select_This_Country").on("click", "li", function() { $.post('/ajax/ajax_change_country.php', { ID: $(this).attr('sid') }, function(h) { if (typeof updatePage == "function") { updatePage(); return false; } if (h) { //$("#This_Country_Pic").attr("src","/upload_files/fonlego-rwd/website/"+h); window.location.reload(); } }, 'html'); }); var _window = $(window); var _body = $('body'); var change_1023 = 0; var nav_item = $('#menu-nav .nav-item'); var scroll_switch = true; // scroll_switch=nav_censor(scroll_switch); var body_padding = 121; var body_padding_s = 40; var userAgent = navigator.userAgent; /* 網頁loading */ // _window.on('load',function(){ // $(".loading").hide(); // }); /* 回頁首 */ $('.gotop').on('click', function() { $("#wrapper").animate({ scrollTop: 0 }, 800); }); //上方廣告 var button = 0; $('.top_adbox_button').on('click', function() { if (_window.width() <= 1023) { $(".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(); $(".heartList").owlCarousel({ nav: true, responsive: { 0: { items: 3 }, 768: { items: 4 }, 1024: { items: 6 } }, }); /* 手機平板 */ if (_window.width() <= 1024) { //上方廣告 if ($('.top_adbox').attr('tag-status') == '1') { $('.top_adbox .fa').removeClass('fa-plus').addClass('fa-times'); $(".top_adbox").show().find('.inner').css('max-height', 800) }; //menu開合 if (/Windows/i.test(userAgent)) { $('#menu-nav').on('click', '.item-title', function() { var n = $(this).parent(".open").length; $('#menu-nav .nav-item').removeClass('open'); $('#menu-nav .menu-item').removeClass('open-sub'); if (n == 0) { $(this).parent(".nav-item").addClass('open'); } }).on(' click', '.subtitle', function() { var n = $(this).parent(".open-sub").length; $('#menu-nav .menu-item').removeClass('open-sub'); if (n == 0) { $(this).parent(".menu-item").addClass('open-sub'); } }); } else { $('#menu-nav').on('click', '.item-title', function() { var n = $(this).parent(".open").length; $('#menu-nav .nav-item').removeClass('open'); $('#menu-nav .menu-item').removeClass('open-sub'); if (n == 0) { $(this).parent(".nav-item").addClass('open'); } }).on(' click', '.subtitle', function() { var n = $(this).parent(".open-sub").length; $('#menu-nav .menu-item').removeClass('open-sub'); if (n == 0) { $(this).parent(".menu-item").addClass('open-sub'); } }); } } 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() <= 1023 && 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; $('.menu-002 .menu-item:nth-child(2)').addClass('hover'); $('.menu-002').on('mouseenter', '.subtitle', function() { // console.log($('menu-item .hover')); $('.menu-002').find('.hover').removeClass('hover'); $(this).parents('.menu-item').addClass('hover'); }).on('mouseleave', function() { $('.menu-002').find('.hover').removeClass('hover'); $('.menu-002 .menu-item:nth-child(2)').addClass('hover'); }); //天邊會員登入hover下拉 $('.shopbox span.fa-user').on('mouseenter', function() { $('.userbox').addClass('open'); }); //天邊購物車hover下拉 $('.shopbox #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'); } }); //hover menu-item change subitem height $('#menu-nav .nav-item').hover(function() { var subitemboxheight = $(this).find('.menu-002 .hover .subitembox').outerHeight(); if ($(this).has('hover')) { if (subitemboxheight > 340) { $(this).find('.menu-002').css({ 'min-height': subitemboxheight + 1 }); } } }, function() { $('.menu-002').removeAttr('style'); }); $('#menu-nav .menu-002 .menu-item').hover(function() { if ($(this).hasClass('hover')) { var subitemboxheight = $(this).find('.subitembox').outerHeight(); if (subitemboxheight > 340) { $(this).parents('.menu-002').css({ 'min-height': subitemboxheight + 1 }); } } }); } $('#wrapper').on('scroll', function(event) { var scrollTop = $('#wrapper').scrollTop(); if (scrollTop > 0) { $(".gotop").css("opacity", "1"); $("body").addClass('is-sticky'); } else { $(".gotop").css("opacity", "0"); $("body").removeClass('is-sticky'); } }); var time_id; _window.on('resize', function() { clearTimeout(time_id); // time_id = setTimeout(nav_censor(scroll_switch),500); _window = $(window); // noisePop(); if (_window.width() <= 1023 && 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'); //off submenu-item 自動調整高度 $('#menu-nav .nav-item').off('hover'); $('#menu-nav .menu-007 .menu-item').off('hover'); //menu開合 // console.log(_window.width()); if (/Windows/i.test(userAgent)) { $('#menu-nav').on('click', '.item-title', function() { var n = $(this).parent(".open").length; $('#menu-nav .nav-item').removeClass('open'); $('#menu-nav .menu-item').removeClass('open-sub'); if (n == 0) { $(this).parent(".nav-item").addClass('open'); } }).on(' click', '.subtitle', function() { var n = $(this).parent(".open-sub").length; $('#menu-nav .menu-item').removeClass('open-sub'); if (n == 0) { $(this).parent(".menu-item").addClass('open-sub'); } }); } else { $('#menu-nav').on('click', '.item-title', function() { var n = $(this).parent(".open").length; $('#menu-nav .nav-item').removeClass('open'); $('#menu-nav .menu-item').removeClass('open-sub'); if (n == 0) { $(this).parent(".nav-item").addClass('open'); } }).on(' click', '.subtitle', function() { var n = $(this).parent(".open-sub").length; $('#menu-nav .menu-item').removeClass('open-sub'); if (n == 0) { $(this).parent(".menu-item").addClass('open-sub'); } }); } } if (_window.width() <= 480 && change_1023 != 480) { change_1023 = 480; body_padding = 50; var scrollTop = _window.scrollTop(); } else if (_window.width() > 480 && _window.width() <= 1023 && change_1023 != 1023) { change_1023 = 1023; body_padding = 75; body_padding_s = 50; var scrollTop = _window.scrollTop(); nav_item.find('.subitem').attr('type', 'checkbox'); $('.menu-item .subtitle').off('mouseenter'); $('.menu-007').off('mouseleave'); } else if (_window.width() > 1023 && change_1023 != 1200) { change_1023 = 1200; body_padding = 121; body_padding_s = 40; var scrollTop = _window.scrollTop(); nav_item.find('.subitem').attr('type', 'radio'); $('.menu-007 .menu-item:nth-child(2)').addClass('hover'); $('.menu-item .subtitle').on('mouseenter', function() { //console.log($('menu-item .hover')); $('.menu-item.hover').removeClass('hover'); $(this).parents('.menu-item').addClass('hover'); }); $('.menu-007').on('mouseleave', function() { $('.menu-item.hover').removeClass('hover'); $('.menu-007 .menu-item:nth-child(2)').addClass('hover'); }); //移除menu開合事件 $('#menu-nav').off('click', '.item-title').off('click', '.subtitle'); //hover menu-item subitem 自動調整高度 $('#menu-nav .nav-item').hover(function() { var subitemboxheight = $(this).find('.menu-002 .hover .subitembox').outerHeight(); if ($(this).has('hover')) { if (subitemboxheight > 340) { $(this).find('.menu-002').css({ 'min-height': subitemboxheight + 1 }); } } }, function() { $('.menu-002').removeAttr('style'); }); $('#menu-nav .menu-002 .menu-item').hover(function() { if ($(this).hasClass('hover')) { var subitemboxheight = $(this).find('.subitembox').outerHeight(); if (subitemboxheight > 340) { $(this).parents('.menu-002').css({ 'min-height': subitemboxheight + 1 }); } } }); } }); function nav_censor(scroll_switch) { if (scroll_switch) { for (var i = 1; i < nav_item.length; i++) { if (nav_item.eq(i).find('h3').height() > 45 || nav_item.eq(i).find('a.item-title').height() > 45) { nav_item.eq(i).addClass('nav-item-big'); scroll_switch = false; } } } return scroll_switch; } var nav_n = false; var overflowTop = 0 $('.menu-b').on('click', function() { if (!nav_n) { nav_n = true; $(this).addClass('close'); $('.nav-bg,.navBox').addClass('open-nav'); overflowTop = $('#wrapper').scrollTop() $('#wrapper').addClass('overflow-hidden') } else { nav_n = false; $(this).removeClass('close'); $('.nav-bg,.navBox').removeClass('open-nav'); $('#wrapper').removeClass('overflow-hidden').scrollTop(0) $('#wrapper').scrollTop(overflowTop) } }); $('.navBox').on('click', function(e) { if(e.target === e.currentTarget) { nav_n = false; $('.menu-b').removeClass('close'); $('.nav-bg,.navBox').removeClass('open-nav'); $('#wrapper').removeClass('overflow-hidden').scrollTop(0) $('#wrapper').scrollTop(overflowTop) } }); $('body.overflow-hidden').on('scroll', function(e) { e.preventDefault() }) $("#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' }, success: function(d) { $("#Noise_Pop").remove(); } }); }); $(document).on("click", '.HITS_BT', 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 }, success: function(d) { if (url) { if (target == '_blank') { window.open(url); } else if ((typeof target === 'undefined') || (target == '')) { window.location = url; } else {} } } }); } else { alert("這是錯誤的連結"); } }); $(document).on("click", '.Collect_BT', function(e) { e.preventDefault(); if ($.isNumeric($(this).attr('Type')) && $.isNumeric($(this).attr('Collection_ID'))) { var Type = $(this).attr('Type'); var Collection_ID = $(this).attr('Collection_ID'); var _this = $(this); if (Type != 4) { $.ajax({ url: "/ajax/ajax_add_collection-p.php", type: "POST", cache: false, async: false, data: { "Type": Type, "Collection_ID": Collection_ID }, success: function(d) { if (d == "OK") { _this.addClass('click'); alert('收藏成功'); } else if (d == "Already") { alert("已收藏過!"); } else if (d == "ERROR") { alert('請先登入會員'); } } }); } else { $.ajax({ url: "/ajax/ajax_add_wish_list.php", type: "POST", cache: false, async: false, data: { "Type": 'Add', "SID": Collection_ID }, success: function(d) { if (d == "OK") { _this.addClass('click'); alert('收藏成功'); } else if (d == "NO_MEMBER") { alert('請先登入會員'); } } }); } } else { alert("這是錯誤的連結"); } }); $(document).on('click', '.Collect_Del_BT', function(e) { e.preventDefault(); var ID = $(this).data('id'); $.ajax({ url: "/ajax/ajax_del_collection-p.php", type: "POST", cache: false, async: false, data: { "ID": ID }, success: function(d) { if (d == "OK") { alert('取消收藏成功'); location.reload(); } } }) }) }); 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); } } $(".otherEvent-wrapper .otherEvent-item").first().addClass('open'); $(".otherEvent-wrapper").on('mouseenter', '.otherEvent-item', function(event) { $(".otherEvent-item.open").removeClass('open'); $(this).addClass('open'); }); $('label.float-right').on('click', function() { $('body').toggleClass("fixed"); }); $('label.close').on('click', function() { $('body').toggleClass("fixed"); }); // ========================================================== // 響應功能校正 // ========================================================== ;(function($) { function log(obj) { console.log(obj) } var deviceStep = '' $(window).on('resize', function(e) { // 平板、手機 if(deviceStep !== 'mobile' && $(this).width() <= 1200) { deviceStep = 'mobile' // 天邊功能偵聽刪除 $('.search, #member, .shopbox').off('mouseenter').off('mouseleave').removeClass('open') // 天邊功能偵聽 $('.search .header-toggle').on('click', function(e) { clickToggle(this, '.search', 'open') }) $('#member .header-toggle').on('click', function(e) { clickToggle(this, '#member', 'open') }) // footer 網站地圖開關功能 $('body').on('click', '.footer-nav-title', function(e) { $(this).parents('.footer-nav-item').toggleClass('in-open').siblings('.footer-nav-item').removeClass('in-open') }) } else if(deviceStep !== 'desktop' && $(this).width() > 1200) { // 桌機 deviceStep = 'desktop' // 天邊功能偵聽刪除 $('.search .header-toggle, #member .header-toggle').off('click') $('.search, #member, .shopbox').removeClass('open') // 天邊功能偵聽 $('.search, #member, .shopbox').on('mouseenter', function(e) { $(this).addClass('open') if(this === $('.shopbox')[0]) { $("#Header_Shopcart").load('/ajax/ajax_get_cart.php', ''); } }).on('mouseleave', function(e) { $(this).removeClass('open') }) // footer 網站地圖開關功能刪除 $('body').off('click', '.footer-nav-title') $('.footer-nav-item').removeClass('in-open') } }) $(window).trigger('resize') })($) function clickToggle(itemName, parentName, className) { $(itemName).parents(parentName).toggleClass(className).siblings().removeClass(className); } // ========================================================== // search 功能 // ========================================================== ;(function($) { $('#keywords').on('focus', function(e) { const wrapper = $(this).parent('.input-group') $(this).parents('.search').addClass('in-focus') if(wrapper.find('.hot-link').length === 0) { wrapper.append('') } }).on('blur', function(e) { if(!$(this).val().length) { $(this).parent('.input-group').find('.hot-link').remove() $(this).parents('.search').removeClass('in-focus') } }).on('keyup', function(e) { const nowValue = $(this).val().trim() const postObject = { itemValue: nowValue } if(nowValue.length > 1) { $.ajax({ url: '/ajax/data/ajax_search_list.php', method: 'POST', data: postObject, cache: false, async: false, dataType: "json", }).done(function(res) { //alert(res); const filterStr = res.reduce((prev, ele) => { prev += `
  • ${ele.item}
  • ` return prev }, '') $('.hot-link').empty().prepend(filterStr) }).fail(function(errXHR, textStatus, errorThrown) { console.log(errXHR) console.log(` textStatus: ${textStatus}, errorThrown: ${errorThrown} `) }) } }) })($) $('body').on('click', '.keyword-link', function(e) { $.post("/ajax/data/ajax_search_click.php", {id: $(this).attr('did')}, function(h){}); }); // ========================================================== // 開啟跳窗 // ========================================================== ;(function($) { function log(obj) { console.log(obj) } $('body').on('click', '.open-amount', function(e) { const target = $(this).data('target') $(target).addClass('in-active') }) $('body').on('click', '.amount-warpper', function(e) { if(e.target === e.currentTarget || e.target === $(this).find('.closer')[0] || $(e.target).hasClass('btn')) { $(this).removeClass('in-active') } }) })($) //商品圖延遲載入 function runLazyload(className) { $(className).lazyload({ src: 'data-original', }); } runLazyload('.productImg img, img.lazyimg') //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); } console.log(d); } }); });