// JQ 功能擴增 $.fn.triggerAll = function(list) { return this.each(function() { const $this = $(this) $.each(list.split(' '), function(key, val) { $this.trigger(val) }) }) } function errorbox(title,content,button){ var html=''; $('body').append(html); $('body').on('click', '#popupBox .close', function(event) { $('#popupBox').remove(); }); }; function noisePop(){ if($(window).width()>= 992){ 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); } } function tinyMce_Front(selector, width, height){ tinymce.init({ language: "zh_TW", width: width, height: height, selector:selector, resize: true, convert_urls:false, mode :'textareas', valid_children: "+body[style]", skin_url: "/plugin/tinymce/skins/lightgray", fontsize_formats: "12px 14px 16px 18px 20px 24px 36px 48px 64px 72px 84px 96px", extended_valid_elements: 'i[*],video[src|crossorigin|preload|autoplay|loop|muted|width|height|buffered|playsinline|class|id|loading=lazy],img[src|width|height|alt=|class|id|loading=lazy|title|border=0|hspace|vspace|align|name|onmouseover|onmouseout],iframe[id|class|width|height|border=0|allowfullscreen|src|title|frameborder=0|allow|loading=lazy]', plugins: [ "advlist autolink lists link charmap print preview anchor", "searchreplace visualblocks code fullscreen", "insertdatetime media table contextmenu paste textcolor,image" ], toolbar: "insertfile undo redo | styleselect fontselect forecolor backcolor | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image" }); } $(function(){ var _window = $(window); var _body = $('body'); var userAgent = navigator.userAgent; noisePop(); // ========================================================== // 頁首次選單會員功能區塊 // ========================================================== $("#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","label,button",function(){ $.post('/ajax/ajax_change_language.php', {Name: $(this).attr('sid')}, function(h){ window.location.reload(); }, 'html'); }); //貨到通知改為連至門市 $(document).on('click','.informForPorter',function(){ window.location.href = '/store/'; }); // ========================================================== // 商品相關折疊區塊 // ========================================================== $('.collapse-list').on('click', '.collapse-list-toggle', function(e) { $(this).parent('.collapse-list-item').toggleClass('in-active'); }); }); $(".table-center").find(function(){ $(".menu_sub_a").parents(".subitembox").prevAll(".m-item-title").addClass("show-fa") }) $('main').on('click', '.club-aside', function(event) { $('body').css('position','fixed'); }); $('main').on('click', '.close-m', function(event) { $('body').removeAttr('style'); }); // ========================================================== // 滾動鎖定 class 變化 // ========================================================== ;(function($) { $(window).on('scroll', function(event) { var scrollTop = $(this).scrollTop(); if(scrollTop > 0){ $("body").addClass('is-sticky'); }else{ $("body").removeClass('is-sticky'); } }); })($) // ========================================================== // 天邊跑馬燈 // ========================================================== ;(function($) { $('.marquee').owlCarousel({ loop : true, items : 1, autoplay:true, autoplayTimeout:3000, nav :false, navText : ['',''], dots: false, }); })($) // ========================================================== // 主選單開關、次級選單手機版開關 // ========================================================== ;(function($) { let menuStep = '' $(window).on('resize', function(e) { if($(this).width() >= 992 && menuStep !== 'desktop') { menuStep = 'desktop' // 主選單 $('.menu-toggle').off('click') $('.navbar').off('click') $('body').removeClass('menu-open'); // 次級選單 $('.header-submenu').off('click', '.member-group .submenu-button') $('.header-submenu-item').removeClass('in-active') } else if($(this).width() < 992 && menuStep !== 'mobile') { menuStep = 'mobile' // 主選單 $('.menu-toggle').on('click', function(e) { $('body').toggleClass('menu-open'); }) $('.navbar').on('click', function(e) { if(e.target === e.currentTarget) { e.preventDefault() $('body').removeClass('menu-open'); } }) // 次級選單 $('.header-submenu').on('click', '.member-group .submenu-button', function(e) { e.preventDefault() $(this).parent('.header-submenu-item').toggleClass('in-active') .siblings('.header-submenu-item').removeClass('in-active') }) } }) // search toggle function $('.header-submenu').on('click', '.header-search .submenu-button', function(e) { e.preventDefault() $(this).parent('.header-submenu-item').toggleClass('in-active') .siblings('.header-submenu-item').removeClass('in-active') }) })($) // ========================================================== // 主選單 toggle 功能 // ========================================================== ;(function($) { $('.header').on('click', '.with-child', function(e) { if($(window).width() < 992) { e.preventDefault() $(this).parent().toggleClass('child-open') .siblings().removeClass('child-open') .end() .find('.child-open').removeClass('child-open') } }) })($) // ========================================================== // 購物車細節 // ========================================================= ;(function($) { //天邊購物車hover下拉 $('#Shop_Cart_Total').on('click', function(e) { e.preventDefault(); $("#Header_Shopcart").load('/ajax/ajax_get_cart.php',''); $('.shopping-cartbox').toggleClass('in-open'); }); })($) // ========================================================== // 主選單hover更換廣告圖 // ========================================================== ;(function($) { $('.navbar').on('mouseenter', '.sub-title', function(e) { const imgPath = $(this).attr('pic') const targetUrl = $(this).attr('url') let appendHTML = '' if(targetUrl) { appendHTML = ` ` } else { appendHTML = ` ` } if(imgPath) { $(this).parents('.item-subitembox').find('.menu-preview').html(appendHTML) } }) })($) // ========================================================== // footer 選單功能 // ========================================================== ;(function($) { let footerStep = '' $(window).on('resize', function(e) { if($(this).width() >= 660 && footerStep !== 'desktop') { footerStep = 'desktop' $('.footer').off('click', '.sitemap-list .title') $('.sitemap-list .item').removeClass('in-open') } else if($(this).width() < 660 && footerStep !== 'mobile') { footerStep = 'mobile' $('.footer').on('click', '.sitemap-list .title', function(e) { if($(this).parent('.item').hasClass('with-child')) { e.preventDefault() $(this).parent('.item').toggleClass('in-open') .siblings('.item').removeClass('in-open') } }) } }) })($) // ========================================================== // video lazyload // ========================================================== ;(function($) { $('.video-lazyload').each(function(i, ele) { const $wrapper = $(this) const $button = $(this).find('.lazy-button') const videoID = $wrapper.attr('data-video') $button.on('click', function(e) { const apprendVideo = `` $wrapper.html(apprendVideo) }) }) })($) // ========================================================== // float buttons // ========================================================== ;(function($) { $('.item-toggle').on('click', function(e) { e.preventDefault() $(this).toggleClass('in-active'); }) })($) // ========================================================== // gotop // ========================================================== ;(function($) { $('.gotop').on('click',function(e){ e.preventDefault() $("html,body").animate({ scrollTop: 0 }, 750); }); })($) // ========================================================== // 側欄選單開關 // ========================================================== ;(function($) { $('.aside-panel').on('click', '.link', function(e) { if($(this).parent().hasClass('with-children')) { e.preventDefault() $(this).parent('.with-children').toggleClass('in-active') .siblings('.with-children').removeClass('in-active') } }) $('.aside-panel').on('click', '.collapse-title', function(e) { e.preventDefault() $(this).parent('.item').toggleClass('in-active') .siblings('.item').removeClass('in-active') }) })($) // ========================================================== // trigger // ========================================================== ;(function($) { $(window).triggerAll('scroll resize') })($) // ========================================================== // 商品列表tag點擊數 // ========================================================== ;(function($) { $('.prodlist-main').on('click', '.prod-tag-click', function(e) { e.preventDefault() const hid = $(this).attr('hid'); const hdid = $(this).attr('hdid'); const thisHref = $(this).attr('href'); $.ajax({ url:"/ajax/ajax_add_ad_hits-p.php", type:"POST", data:{Hid: hid, Hdid: hdid}, dataType: 'JSON', }).done(function(res) { console.log(res) // setTimeout(function() { document.location.href = thisHref // }, 3000) }).fail(function(x, y, z) { console.log('error') console.log(x, y, z) alert('網路連線過慢,網頁請重新整理'); }) }); })($) // ========================================================== // 編輯器index // ========================================================== ;(function($) { //展開 $(".editor-index").on("click", ".index-switch", function(){ $(this).parents(".editor-index").toggleClass("theme-collapse") }) //跳轉 $(".editor-index").on('click', '.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埋設 $(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); } }); });