$(function(){ var _window = $(window); var _body = $("body"); var userAgent = navigator.userAgent; var width_change = 0; _window.on('scroll', function(event) { var scrollTop = _window.scrollTop(); if(scrollTop > 0){ _body.addClass('is-sticky'); }else{ _body.removeClass('is-sticky'); } }); $(document).on("click", ".menuToggle-btn", function(){ let wrapper = $(".menu-wrapper") if($(this).hasClass("open")){ $(this).removeClass("open") wrapper.removeClass("open") }else{ $(this).addClass("open") wrapper.addClass("open") } }) //子選單展開 $(document).on("click", ".quicklink-link.with-child", function(){ if($(window).width() < 1200){ $(this).toggleClass("in-active") } }) //點擊率 $(".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('這是錯誤的連結'); } }); }); var pageCode = function(option) { var sets = { type : '', contentBoxId : 'Main_Content', pageBox : 'pagebox', pageClass : 'page', nowClass : 'now', mainClass : 'Main_Page' }; var _this = this; //更新設定 $.extend(sets, option); //取得參數 this.params = function() { }; //初始化JS this.init = function() { //取得現在頁數 var now = $('.'+sets.pageBox).find('.'+sets.nowClass).eq('0').attr('send'); $('#'+sets.contentBoxId).on('click','.'+sets.pageClass,function(){ var change = $(this).attr('send'); //和原本的頁數相同時不動作 if(sets.now == change) { return false; } //取得其他參數 var params = _this.params(); _this.update('page='+change+'&'+params); //更新現在頁數 now = $('.'+sets.pageBox).find('.'+sets.nowClass).eq('0').attr('send'); }); }; //更新頁面 this.update = function(data) { //檢查類型設定 if(!sets.type) { alert('請先設定類型'); return false; } var post = 'type='+sets.type; if(data) { post += '&'+data; } $.ajax({ url:'/ajax/ajax_change_page.php', type:'POST', data:post, cache:false, success:function(d) { $('#'+sets.contentBoxId).html(d); } }); }; } function changeCartNum(num){ $('a .cartAmount').html(num); } // ========================================================== // input 數字加減功能 // ========================================================== ;(function($) { $('.amount-wrapper').each(function(i, item) { const target = $(item).find('.amountBox') const targetStep = target.attr('step') * 1 || 1 const targetMax = target.attr('max') * 1 || 99 const targetMin = target.attr('min') * 1 || 0 $(this).on('click', '.fa-minus', function(e) { if(target.val() > targetMin) { const value = target.val() || 0 target.val(value * 1 - targetStep) } }) $(this).on('click', '.fa-plus', function(e) { if(target.val() < targetMax) { const value = target.val() || 0 target.val(value * 1 + targetStep) } }) }) })($) $(function(){ //==================================================== // 搜尋 start //==================================================== $(".search-btn").on("click", function(){ let keyword = $("#siteSearch").val(); let site = $(this).attr("site"); if(keyword){ window.open("https://www.google.com/search?sitesearch="+site+"&as_q="+keyword) } }) //enter觸發 $("#siteSearch").keyup(function(e){ if(e.keyCode === 13){ $(".search-btn").click() } }) //==================================================== // 搜尋 end //==================================================== //==================================================== // 回頁首 end //==================================================== $('#goTop').on('click',function(){ $("html,body").animate({scrollTop: 0},800); }); $(window).on('scroll', function(event) { let scrollTop = $(window).scrollTop(); let topBtn = $("#goTop") let bottom = ($(document).height() - $(window).height() - scrollTop) if(scrollTop>0){ topBtn.css("opacity","1"); }else{ topBtn.css("opacity","0"); } }) //==================================================== // 回頁首 end //==================================================== //==================================================== // 關閉跳窗 end //==================================================== $(document).on("click", ".popup-wrapper", function(e){ let target = $(e.target) if(target.hasClass("popup-wrapper") || target.hasClass("popup-close")){ $(".popup-wrapper").removeClass("open") $("body").removeClass("overflow-hidden") } }) //==================================================== // 關閉跳窗 end //==================================================== //==================================================== // 表單欄位切換 start //==================================================== $(document).on("click", ".form-switch-group .form-switch-btn", function(){ let _this = $(this), target = _this.data("target") $(".form-switch-block input").attr('fun', ''); $(".form-switch-block select").attr('fun', ''); //.form-ignore-switch再切換時不會將input設為checkNull $(".form-switch-block:not(.form-ignore-switch)[data-name='"+target+"'] input").each(function(){ let _input = $(this), specialFun = _input.data("special-fun") _input.attr('fun', (specialFun) ? specialFun : 'checkNull'); }) if(!_this.hasClass("now")){ _this.parents(".form-switch-group").find(".form-switch-btn").removeClass("now") _this.addClass("now") let target = $(this).attr("for") //觸發change $('.form-address-group[group_type="'+target+'"]').find(".form-input").trigger("change"); $("#" + target).prop("checked",true) switch(_this.attr('for')){ case "Domestic": $("#Address_Type").val(1); $("#City_ID").attr('fun', 'checkNull'); $("#Area_ID").attr('fun', 'checkNull'); break; case "AddressMail": $("#Address_Type").val(2); $("#City_ID2").attr('fun', 'checkNull'); $("#Area_ID2").attr('fun', 'checkNull'); $("#Post_Address").attr('fun', 'checkAddressNull'); break; case "OverSeas": $("#Address_Type").val(3); $("#Abroad_Address").attr('fun', 'checkAddressNull'); break; } } }) //==================================================== // 表單欄位切換 end //==================================================== //==================================================== // 表單欄位提示 start //==================================================== $(document).on("focus", ".form-focus-wrapper .form-input", function(){ let _this = $(this) focusString = _this.parents(".form-focus-wrapper").find(".form-focus-string"), itemRect = _this[0].getBoundingClientRect(), windowWidth = $(window).width() if(itemRect.left < 100){ focusString.css({ left: "-10px", right: "auto" }) }else if((windowWidth - itemRect.right) < 90){ focusString.css({ right: "-10px", left: "auto" }) }else{ focusString.css({ left: "-85px", right: "auto" }) } }) //==================================================== // 表單欄位提示 end //==================================================== //==================================================== // 表單密碼顯示切換 start //==================================================== $(document).on("click", ".form-vision-btn", function(){ let targetInput = $(this).parents(".form-vision-row").find(".form-input") if($(this).hasClass("close")){ $(this).removeClass("close") targetInput.attr("type", "password") }else{ $(this).addClass("close") targetInput.attr("type", "text") } }) //==================================================== // 表單密碼顯示切換 start //==================================================== //==================================================== // 監聽捐款查詢日期變化 start //==================================================== $(document).on("change", ".donate-date-input", function(e){ let FirstDate = $("#FirstDate"), LastDate = $("#LastDate"), FirstDateVal = FirstDate.val(), LastDateVal = LastDate.val(), FirstDateObj = new Date(FirstDateVal), LastDateObj = new Date(LastDateVal), MinDateObj = new Date(FirstDate.attr("min")), MaxDateObj = new Date(FirstDate.attr("max")), targetId = $(e.target)[0].id, edgeDate = { "First":FirstDateVal, "Last":LastDateVal }, errorMsg = "", outRangeFlag = false, overflowFlag = false if((FirstDateObj == "Invalid Date") || (LastDateObj == "Invalid Date")){ alert("請輸入有效日期格式YYYY-MM-DD 如2020-01-01") return false; } if(FirstDateObj > LastDateObj){ alert("開始日期須早於結束日期") return false; } //範圍超出三年內 或是日期選擇未來 將對應超界的值改為最大最小值 if(MinDateObj > FirstDateObj){ FirstDateObj = MinDateObj edgeDate["First"] = FirstDate.attr("min") outRangeFlag = true } if(MinDateObj > LastDateObj){ LastDateObj = MinDateObj edgeDate["Last"] = LastDate.attr("min") outRangeFlag = true } if(MaxDateObj < FirstDateObj){ FirstDateObj = MaxDateObj edgeDate["First"] = FirstDate.attr("max") outRangeFlag = true } if(MaxDateObj < LastDateObj){ LastDateObj = MaxDateObj edgeDate["Last"] = LastDate.attr("max") outRangeFlag = true } //區間超過一年 if((LastDateObj.getTime() - FirstDateObj.getTime()) > 31536000000){ //31536000000 = 86400 * 1000 * 365 overflowFlag = true let edgeDateObj if(targetId === "FirstDate"){ FirstDateObj.setDate(FirstDateObj.getDate() + 365) edgeDate["Last"] = FirstDateObj.toISOString().slice(0, 10) }else if(targetId === "LastDate"){ LastDateObj.setDate(LastDateObj.getDate() - 365) edgeDate["First"] = LastDateObj.toISOString().slice(0, 10) } } if(outRangeFlag && overflowFlag){ alert("僅能查詢三年內且查詢區間區間小於一年的歷史資料") }else if(overflowFlag){ alert("僅能查詢區間一年內資料") }else if(outRangeFlag){ alert("僅能查詢三年內歷史資料") } FirstDate.val(edgeDate["First"]) LastDate.val(edgeDate["Last"]) }) //==================================================== // 監聽捐款查詢日期變化 end //==================================================== }) //==================================================== //更新頁碼 start //==================================================== function updatePage(page_data, pagebox){ let total = parseInt(page_data.total_page); let now = parseInt(page_data.now_page); //now不是第一頁就n-1是第一頁就1 let prev = (now !== 1) ? (now - 1) : 1 //now不是最後頁就n+1是最後頁就n let next = (now !== total) ? (now + 1) : (now) let pagesHtml = ``, innerHtml = ``, fewPageFlag = true if(total <= 1){ //只有一頁隱藏 fewPageFlag = true pagebox.addClass("hide") }else if(total === 2){ //只有兩頁判斷誰是now fewPageFlag = true pagebox.removeClass("hide") innerHtml = ` ` }else if(total > 2){ fewPageFlag = false pagebox.removeClass("hide") //三頁以上 分now為第一 最後 中間 三種情況 if(now === 1){ innerHtml = ` ` }else if(now === total){ innerHtml = ` ` }else{ innerHtml = ` ` } } pagesHtml = `
${innerHtml}
${now} / ${total}
` pagebox.html(pagesHtml) } //==================================================== //更新頁碼 end //====================================================