// JQ 功能擴增 $.fn.triggerAll = function(list) { return this.each(function() { const $this = $(this) $.each(list.split(' '), function(key, val) { $this.trigger(val) }) }) } // 裝置判斷 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-wrapper .marquee-list").owlCarousel({ items: 1, nav: false, dots: false, autoplay: true, autoplayTimeout: 8000, autoplaySpeed: 1000, autoplayHoverPause: true, animateIn: 'slideInUp', animateOut: 'slideOutUp', mouseDrag: false, loop: true, }); })($) // 螢幕滾動 ;(function($) { let windowScroll = 0 $(window).on('scroll', function(e) { if($(this).scrollTop() > 0) { $("body").addClass('is-scroll') } else { $("body").removeClass('is-scroll') } if(windowScroll > $(this).scrollTop() && $(this).scrollTop() > 0) { $("body").addClass('is-sticky'); } else { $("body").removeClass('is-sticky'); } windowScroll = $(this).scrollTop() }) })($) // 主選單 ;(function($) { let navbarDevice = '' let navbarTouch = '' $(window).on('resize', function(e) { // 通用選單 if($(this).width() >= 992) { if(navbarDevice !== 'desktop') { navbarDevice = 'desktop' // 主選單開關 $('body').removeClass('menu-open'); $('.navbar-toggle, .header').off('click') } if($('body').hasClass('DeviceWithHover')) { $('.header').off('click') $('.header').on('mouseenter', '.main-link', function(e) { e.preventDefault() const thisTarget = $(this).attr('data-target') $(this).parent('.main-item').addClass('in-hover').siblings('.main-item').removeClass('in-hover') $(thisTarget).addClass('in-hover').siblings('.children-content').removeClass('in-hover') }).on('mouseleave', '.navbar-wrapper', function(e) { e.preventDefault() $('.main-item, .children-content').removeClass('in-hover') }) } else { $('.header').off('mouseenter').off('mouseleave') $('.header').on('click', '.main-link', function(e) { e.preventDefault() const thisTarget = $(this).attr('data-target') $(this).parent('.main-item').toggleClass('in-hover').siblings('.main-item').removeClass('in-hover') $(thisTarget).toggleClass('in-hover').siblings('.children-content').removeClass('in-hover') }) } } else if($(this).width() < 992 && navbarDevice !== 'mobile') { navbarDevice = 'mobile' // 主選單開關 $('.navbar-toggle').on('click', function(e) { $('body').toggleClass('menu-open'); }) $('.main-item, .children-content').removeClass('in-hover') $('.header').on('click', '.main-link', function(e) { e.preventDefault() const thisTarget = $(this).attr('data-target') $(this).parent('.main-item').addClass('in-active').siblings('.main-item').removeClass('in-active') $(thisTarget).addClass('in-active').siblings('.children-content').removeClass('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() <= 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'); }; } var time_id; _window.on('resize',function(){ clearTimeout(time_id); _window = $(window); 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(); }); } }); //點擊率 $(".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","li,label",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','.informForPorter',function(){ window.location.href = '/'+$("#Website_Mall_ID").val()+'/store/'; }); }); $('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() >= 992 && footerMenuStep !== 'desktop') { footerMenuStep = 'desktop' $('.footer-menu').off('click', '.menu-title').find('.menu-item').removeClass('in-active') } else if($(this).width() < 992 && footerMenuStep !== 'mobile') { footerMenuStep = 'mobile' $('.footer-menu').on('click', '.menu-title', function(e) { e.preventDefault() $(this).parent('.menu-item').toggleClass('in-active') .siblings('.menu-item').removeClass('in-active') }) } }).trigger('resize') })($, jQuery, window, document) // ========================================================== // 商品規格 tag 切換 // ========================================================== ;(function($) { $('body').on('click', '.tag-box .title-link', function(e) { e.preventDefault() const thisTarget = $(this).attr('href') $(this).parent('.title-item').addClass('in-active') .siblings('.title-item').removeClass('in-active') $(thisTarget).addClass('in-active') .siblings('.content-item').removeClass('in-active') }) })($) // ========================================================== // 商品規格評論區塊輪播 // ========================================================== ;(function($) { let productReviewStep = '' $(window).on('resize', function(e) { if($(this).width() >= 992 && productReviewStep !== 'desktop') { productReviewStep = 'desktop' $('.content-pics').each(function(i, ele) { $(ele).owlCarousel({ autoWidth: true, margin: 15, nav: true, dots: false, navText: ['', ''], }) }); } else if($(this).width() < 992 && productReviewStep !== 'mobile') { productReviewStep = 'mobile' $('.content-pics').each(function(i, ele) { if($(ele).data('owl.carousel')) { $(ele).data('owl.carousel').destroy() } }); } }) })($) // ========================================================== // 評價圖片跳窗 // ========================================================== ;(function($) { $('main').on('click', '.content-pics .OpenSlide', function(e) { e.preventDefault() $('body').addClass('overflow-hidden') const targetPic = $(this).attr('href'); const targetGroup = $(this).attr('group') const targetStep = $(this).attr('data-step') const groupAry = $(this).parents('.content-pics').find('[group=' + targetGroup + ']') const slideAry = [] groupAry.each(function(i, ele) { const pushString = $(ele).attr('href') slideAry.push(pushString) }); // console.log(slideAry) const appendSlides = slideAry.reduce(function(prev, ele, i) { const thisStr = `
` return prev + thisStr }, '') const appendChild = ` ` $('body').append(appendChild) }) })($) // ========================================================== // 通用跳窗功能 // ========================================================== ;(function($) { $('body').on('click', '.popupBox-wrapper', function(e) { if(e.currentTarget === e.target || $(e.target).hasClass('closer') || $(e.target).hasClass('add_to_cart')) { e.preventDefault() $('body').removeClass('overflow-hidden') if(e.currentTarget === e.target) { $(e.target).remove() } else { $(e.target).parents('.popupBox-wrapper').remove() } } }) })($) // ========================================================== // 跳窗型搜尋功能 // ========================================================== ;(function($) { let commonSearchStep = false $('body').on('click', '#TopSearchToggle', function(e) { e.preventDefault() if(!commonSearchStep) { commonSearchStep = true jQuery.ajax({ url: Project_Country + 'ajax/ajax_popup_search.php', type: 'GET', dataType: 'HTML', }) .done(function(res) { $('body').addClass('overflow-hidden').append(res) }) .fail(function(x, y, z) { console.log(x); }) .always(function() { commonSearchStep = false }) } }) })($) // ========================================================== // 快速購物跳窗 // ========================================================== ;(function($) { let commonShopcartStep = false $('body').on('click', '.QuickShop', function(e) { e.preventDefault() if(!commonShopcartStep) { commonShopcartStep = true jQuery.ajax({ url: Project_Country + 'ajax/ajax_popup_shopbox.php', type: 'POST', dataType: 'html', data: { SID: $(this).attr('SID'), serial: $(this).attr('serial'), Amount: $(this).parent().find('.amountBox').val(), }, }).done(function(res) { $('body').addClass('overflow-hidden').append(res) }).fail(function(x, y, z) { console.log(x) }).always(function() { commonShopcartStep = false }) } }) })($) // ========================================================== // 購物車細節 // ========================================================= ;(function($) { // console.log(location.pathname) const pathName = location.pathname const Regex = /activities[78]-detail|activities[12346]/gi let activitiesPage = '' if(pathName.match(Regex)) { activitiesPage = 'activitiesCart' } //天邊購物車hover下拉 $('body').on('click', '.OpenShopcart',function(e) { e.preventDefault(); if($("#Header_Shopcart").length) { $('.shopping-cartbox').removeClass('in-open').remove() } else { $('body').append(`
`) $("#Header_Shopcart").load(Project_Country+'ajax/ajax_get_cart.php',''); $('.shopping-cartbox').addClass('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'); }) })($) // ========================================================== // 摺疊table開關功能 // ========================================================== ;(function($) { $('main').on('click', '.CollapseToggle', function(e) { e.preventDefault() const $targetBox = $(this).parents('.member-row') if($targetBox.hasClass('member-controls')) { $targetBox.toggleClass('in-expand'); } else { $targetBox.prev('.member-controls').toggleClass('in-expand'); } }) })($) // ========================================================== // 側欄選單開關 // ========================================================== ;(function($) { $('.aside-panel').on('click', '.with-children > a', function(e) { 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') }) })($) // ========================================================== // 頁面加載 // ========================================================== $(window).on("pageshow", function(){ $(".common-loading").addClass("hide") }) ;(function($) { $(".common-loading").addClass("hide") $(document).on("click", "a", function(e){ if(!e.isDefaultPrevented()){ let _this = $(this), targetHref = _this.attr("href") if(targetHref && !targetHref.startsWith("#") && (!targetHref.includes("javascript") || _this.hasClass("page"))){ $(".common-loading").removeClass("hide") $(document).one("click", function(){ $(".common-loading").addClass("hide") }) setTimeout(function(){ $(".common-loading").addClass("hide") }, 15000) } } }) })($) // trigger function ;(function($) { $(window).triggerAll('resize, scroll') })($) ;(function($) { //Line分享 let line_btn = true; $('.line-share-btn').click(function(){ if(line_btn == true){ line_btn = false; $.ajax({ url:Project_Country+"ajax/ajax_check_revent.php", type:"POST", cache:false, async:false, dataType:"text", error:function(d){ line_btn = true; alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ line_btn = true; var url = $('#line_share').val(); switch(d){ case 'NO_REVENT': window.open('https://line.naver.jp/R/msg/text/?'+url); break; case 'NO_MEMBER': var res = confirm('是否登入會員參加好友分潤活動?'); if(res == true){ window.location.href = '/dollbao/member-login/'; }else{ window.open('https://line.naver.jp/R/msg/text/?'+url); } break; default: window.open('https://line.naver.jp/R/msg/text/?'+url+encodeURI('?reco='+d)); break; } } }); } }) })($) // ========================================================== // 客服區塊開關 // ========================================================== ;(function($) { if($('.contactbox-toggle').length) { $('body').on('click', '.contactbox-toggle', function(e) { e.preventDefault() $(this).parents('.contactbox-wrapper').toggleClass('in-open'); }) } })($) /* 細節頁影片效果 */ //影片控制 ;(function($) { $(document).on('click','.video-control',function(e){ e.preventDefault() const video = document.getElementById("Video"); if($(video).length) { const controlBtn = $(this).find('.fa') if(video.paused){ $(controlBtn).addClass('fa-pause').removeClass('fa-play'); video.play(); } else { $(controlBtn).addClass('fa-play').removeClass('fa-pause'); video.pause(); } } }); })($) function videoBox(){ if($('#Video').length && $('#video_review').length) { const videoTarget = document.getElementById("Video") const canvas = document.getElementById("video_review") const paintInfo = { width: $(videoTarget).width(), height: $(videoTarget).height(), } //影片預覽圖 if(videoTarget){ canvas.width = paintInfo.width canvas.height = paintInfo.height canvasPaint() } // 影片繪製 function canvasPaint() { canvas.getContext('2d').drawImage(videoTarget, 0, 0, paintInfo.width, paintInfo.height); requestAnimationFrame(canvasPaint) } } }