-
Notifications
You must be signed in to change notification settings - Fork 0
/
paginationblogger.js
10 lines (9 loc) · 6.86 KB
/
paginationblogger.js
1
2
3
4
5
6
7
8
9
10
var perPage = 5;
var numPages = 2;
var firstText = 'Primera';
var lastText = 'Última';
var prevText = '« Anterior';
var nextText = 'Siguiente »';
var urlactivepage = location.href;
var home_page = "/";
var noPage,currentPage,currentPageNo,postLabel;function looppagecurrentg(e){var a='<ul class="pagination justify-content-center my-4">';pageNumber=parseInt(numPages/2),pageNumber==numPages-pageNumber&&(numPages=2*pageNumber+1),pageStart=currentPageNo-pageNumber,pageStart<1&&(pageStart=1),lastPageNo=parseInt(e/perPage)+1,lastPageNo-1==e/perPage&&--lastPageNo,pageEnd=pageStart+numPages-1,pageEnd>lastPageNo&&(pageEnd=lastPageNo),a+="<li class='showpageOf'>Page "+currentPageNo+" of "+lastPageNo+"</li>",e=parseInt(currentPageNo)-1,1<currentPageNo&&(a+="page"==currentPage?'<li class="page-item firstpage d-none d-sm-block"><a class="page-link" href="'+home_page+'">'+firstText+"</a></li>":'<li class="page-item firstpage d-none d-sm-block"><a class="page-link" href="/search/label/'+postLabel+"?&max-results="+perPage+'">'+firstText+"</a></li>"),2<currentPageNo&&(a+=3==currentPageNo?"page"==currentPage?'<li class="page-item d-none d-sm-block"><a class="page-link" href="#" onclick="redirectpage('+(currentPageNo-1)+');return false">'+prevText+"</a></li>":'<li class="page-item d-none d-sm-block"><a class="page-link" href="#" onclick="redirectlabel('+(currentPageNo-1)+');return false">'+prevText+"</a></li>":"page"==currentPage?'<li class="page-item d-none d-sm-block"><a class="page-link" href="#" onclick="redirectpage('+e+');return false">'+prevText+"</a></li>":'<li class="page-item d-none d-sm-block"><a class="page-link" href="#" onclick="redirectlabel('+e+');return false">'+prevText+"</a></li>"),1<pageStart&&(a+="page"==currentPage?'<li class="page-item"><a class="page-link" href="'+home_page+'">1</a></li>':'<li class="page-item"><a class="page-link" href="/search/label/'+postLabel+"?&max-results="+perPage+'">1</a></li>'),2<pageStart&&(a+='<li class="page-item disabled"><a class="page-link" href="#!">...</a></li>');for(var t=pageStart;t<=pageEnd;t++)a+=currentPageNo==t?'<li class="page-item active" aria-current="page"><a class="page-link" href="'+urlactivepage+'">'+t+"</a></li>":1==t?"page"==currentPage?'<li class="page-item"><a class="page-link" href="'+home_page+'">1</a></li>':'<li class="page-item"><a class="page-link" href="/search/label/'+postLabel+"?&max-results="+perPage+'">1</a></li>':"page"==currentPage?'<li class="page-item"><a class="page-link" href="#" onclick="redirectpage('+t+');return false">'+t+"</a></li>":'<li class="page-item"><a class="page-link" href="#" onclick="redirectlabel('+t+');return false">'+t+"</a></li>";pageEnd<lastPageNo-1&&(a+='<li class="page-item disabled"><a class="page-link" href="#!">...</a></li>'),pageEnd<lastPageNo&&(a+="page"==currentPage?'<li class="page-item"><a class="page-link" href="#" onclick="redirectpage('+lastPageNo+');return false">'+lastPageNo+"</a></li>":'<li class="page-item"><a class="page-link" href="#" onclick="redirectlabel('+lastPageNo+');return false">'+lastPageNo+"</a></li>"),e=parseInt(currentPageNo)+1,currentPageNo<lastPageNo-1&&(a+="page"==currentPage?'<li class="page-item d-none d-sm-block"><a class="page-link" href="#" onclick="redirectpage('+e+');return false">'+nextText+"</a></li>":'<li class="page-item d-none d-sm-block"><a class="page-link" href="#" onclick="redirectlabel('+e+');return false">'+nextText+"</a></li>"),currentPageNo<lastPageNo&&(a+="page"==currentPage?'<li class="page-item lastpage d-none d-sm-block"><a class="page-link" href="#" onclick="redirectpage('+lastPageNo+');return false">'+lastText+"</a></li>":'<li class="page-item lastpage d-none d-sm-block"><a class="page-link" href="#" onclick="redirectlabel('+lastPageNo+');return false">'+lastText+"</a></li>"),a+="</ul>";for(var s=document.getElementsByName("pageArea"),e=document.getElementById("blog-pager"),l=0;l<s.length;l++)s[l].innerHTML=a;s&&0<s.length&&(a=""),e&&(e.innerHTML=a)}function totalcountdata(e){e=e.feed,looppagecurrentg(parseInt(e.openSearch$totalResults.$t,10))}function pagecurrentg(){var e,a=urlactivepage;-1!=a.indexOf("/search/label/")&&(postLabel=-1!=a.indexOf("?updated-max")?a.substring(a.indexOf("/search/label/")+14,a.indexOf("?updated-max")):-1!=a.indexOf("?m=")?a.substring(a.indexOf("/search/label/")+14,a.indexOf("?m=")):a.substring(a.indexOf("/search/label/")+14,a.indexOf("?&max"))),-1==a.indexOf(".html")&&(-1==a.indexOf("/search/label/")?(currentPage="page",currentPageNo=-1!=urlactivepage.indexOf("#PageNo=")?urlactivepage.substring(urlactivepage.indexOf("#PageNo=")+8,urlactivepage.length):1,-1==a.indexOf("q=")?((e=document.createElement("script")).async=!0,e.src="https://"+window.location.host+"/feeds/posts/summary?max-results=1&alt=json-in-script&callback=totalcountdata"):((e=document.createElement("script")).async=!0,e.src="https://"+window.location.host+"/feeds/posts/summary?q="+a.split("?")[1].split("q=")[1].split("&")[0]+"&alt=json-in-script&callback=totalcountdata")):(currentPage="label",-1==a.indexOf("&max-results=")&&(perPage=20),currentPageNo=-1!=urlactivepage.indexOf("#PageNo=")?urlactivepage.substring(urlactivepage.indexOf("#PageNo=")+8,urlactivepage.length):1,(e=document.createElement("script")).async=!0,e.src="https://"+window.location.host+"/feeds/posts/summary/-/"+postLabel+"?alt=json-in-script&callback=totalcountdata&max-results=1"),e.type="text/javascript",(a=document.getElementsByTagName("script")[0]).parentNode.insertBefore(e,a))}function redirectpage(e){jsonstart=(e-1)*perPage,noPage=e;var a=document.getElementsByTagName("head")[0];(e=document.createElement("script")).type="text/javascript",-1==urlactivepage.indexOf("?q=")?e.setAttribute("src",home_page+"feeds/posts/summary?start-index="+jsonstart+"&max-results=1&alt=json-in-script&callback=finddatepost"):e.setAttribute("src",home_page+"feeds/posts/summary?start-index="+jsonstart+"&alt=json-in-script&q="+urlactivepage.split("?")[1].split("q=")[1].split("&")[0]+"&callback=finddatepost"),a.appendChild(e)}function redirectlabel(e){jsonstart=(e-1)*perPage,noPage=e;var a=document.getElementsByTagName("head")[0];(e=document.createElement("script")).type="text/javascript",e.setAttribute("src",home_page+"feeds/posts/summary/-/"+postLabel+"?start-index="+jsonstart+"&max-results=1&alt=json-in-script&callback=finddatepost"),a.appendChild(e)}function finddatepost(e){post=e.feed.entry[0],e=post.published.$t.substring(0,19)+post.published.$t.substring(23,29),e=encodeURIComponent(e),e="page"==currentPage?-1==urlactivepage.indexOf("?q=")?"/search?updated-max="+e+"&max-results="+perPage+"#PageNo="+noPage:"/search?q="+urlactivepage.split("?")[1].split("q=")[1].split("&")[0]+"&updated-max="+e+"&max-results="+perPage+"&start="+(perPage*noPage-perPage)+"&by-date=false#PageNo="+noPage:"/search/label/"+postLabel+"?updated-max="+e+"&max-results="+perPage+"#PageNo="+noPage,location.href=e}"undefined"==typeof firstText&&(firstText="First"),"undefined"==typeof lastText&&(lastText="Last"),pagecurrentg();