$(function(){ let loadBox = $(".vote-list-wrapper"); //彈窗 $(document).on("click", ".vote-list-item", function(e){ if(!$(e.target).hasClass("item-btn")){ getVotePopup("vote",$(this).data("id")) } }) //關閉跳窗 $(document).on("click", ".votePopup-close", function(){ $(".vote-popup").removeClass("in-active") }) $(document).on("click", ".vote-popup", function(e){ if($(e.target).hasClass("vote-popup")){ $(".vote-popup").removeClass("in-active") } }) //錨點跳轉 $(document).on("click", ".vote-anchor-item", function(){ let target = $(this).data("target") $("html,body").animate({scrollTop: $("#" + target).position().top - 100},800) }) //投票 $(document).on("click", ".voteItem-votebtn-btn, .item-btn", function(){ var votedBox = `

感謝您的投票,您可以在官方LINE快速查詢得獎公告。

https://irootw.page.link/line

` let _this = $(this), voteID = _this.data("id") if(_this.hasClass("disabled")){ return false; } _this.attr("disabled",true); //防呆避免重複投票 $.ajax({ url: "/vote/ajax/ajax_vote_execute.php", type:"POST", cache:false, dataType: "json", data:{ id: voteID }, error:function(d){ _this.attr("disabled",false); //防呆避免重複投票 alert('網路連線過慢,網頁請重新整理'); }, success:function(res) { _this.attr("disabled",false); //防呆避免重複投票 //報名成功 if(res.status == "OK"){ alert("投票成功") _this.parents('.voteItem-wrapper').find('.voteItem-vote-num').html(res.vote_num) $(".vote-list-item[data-id="+voteID+"]").find('.item-vote-num').html(res.vote_num) if(res.voted == '0') { $('body').append(votedBox); } }else if(res.status == "ERROR"){ alert(res.msg); if(res.url){ window.location.href = res.url; } } if(res.remain <= 0){ $(".item-btn").addClass("disabled"); _this.addClass("disabled") } } }) }) //搜尋 $(document).on("click", ".vote-search-btn", function(){ let keyword = $("#VoteSearch").val() if(keyword){ $.ajax({ url: "/vote/ajax/ajax_search_votelist.php", type:"POST", cache:false, data:{ keyword: keyword, cid: $('#Vote_Class_ID').val() }, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(res){ loadBox.html(res) } }) }else{ alert("請輸入關鍵字") } }) //複製連結 $(document).on("click", ".voteItem-community-copy", function(e){ window.navigator.clipboard.writeText($(this).data("copy")) alert("複製成功") }) }) // ========================================================== // 關閉voted-box // ========================================================== ;(function($) { $('body').on('click', '.voted-popup', function(e) { if(e.target === e.currentTarget || $(e.target).hasClass('closer')) { e.preventDefault() $(e.currentTarget).remove() } }) })($) function getVotePopup(type, id = "0"){ $.ajax({ url: "/vote/ajax/ajax_vote_popup.php", type:"POST", cache:false, data:{ type : type, //type signup/vote id : id }, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(res){ //報名成功 $(".votePopup-box").html(res) $(".vote-popup").addClass("in-active") } }); }