var getUrlVars = function(){ var vars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for(var i = 0; i < hashes.length; i++){ hash = hashes[i].split('='); vars.push(decodeURIComponent(hash[0])); vars[decodeURIComponent(hash[0])] = decodeURIComponent(hash[1]); } if(vars[0] == window.location.href){ vars =[]; } return vars; } function goBackTop(txt, speed) { var doc = document; var top = document.createElement('div'); top.className = 'go-back-top no-print'; top.textContent = txt || 'top'; doc.body.appendChild(top); // 判斷是否顯示按鈕 $(window).scroll(function() { if ($(this).scrollTop() !== 0) { $('.go-back-top').fadeIn(); } else { $('.go-back-top').fadeOut(); } }); // 捲動效果 $('.go-back-top').on('click', function() { $('body, html').animate({ scrollTop: 0 }, speed || 300); return false; }); } var constructPagination = function(current_page, total_pages, type){ var ul = $(""), first_li = $("
  • First
  • "), last_li = $("
  • Last
  • "), prev_li = $(""), next_li = $(""), limit = 3, start = 1; start = ((current_page - 1) < 1 ? 1 : (current_page - 1)); limit = (total_pages > limit ? limit : total_pages); end = ((current_page + 1) > total_pages ? total_pages : (current_page + 1)); if(total_pages == limit){ start = 1; end = limit; } if(end == 2 && total_pages > 2){ end++; } if(current_page == total_pages && start > 1){ start--; } for(i = start;i <= end; i++){ var li = $("
  • " + i + "
  • "); if(i == current_page){ li.addClass("active"); } ul.append(li); } if(current_page > 1){ ul.prepend(prev_li); ul.prepend(first_li); } if(current_page != total_pages){ ul.append(next_li); ul.append(last_li); } ul.find("a").on("click",function(){ $("*").animate({scrollTop:0}, '300'); if(type == "tickets"){ getTickets($(this).data("page")); }else if(type == "sites"){ getSites($(this).data("page")); } return false; }) paginationArea.show(); paginationArea.find("nav").html(ul); } $(document).ready(function(){ goBackTop('top', 500); });