Advertisement
mspotilas

Make chronological link with correct paging

Feb 20th, 2013
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <a id="chronLink" href="/search?max-results=7#order=ASC">Articles in chronological order</a>
  2. <script style="text/javascript">  
  3. var chronPerPage = 7;
  4. function makeChronLink(json) {
  5.     var link = "/search?updated-max="+encodeURIComponent(json.feed.entry[0].published.$t.replace(/\.\d{3}/, ""))+"&max-results="+chronPerPage+"#order=ASC";
  6.     var a = document.getElementById('chronLink');
  7.     if(a) a.href = link;
  8. }
  9. function chronNumberOfPosts(json) {  
  10.     var count = parseInt(json.feed.openSearch$totalResults.$t);
  11.     var sc = document.createElement('script');
  12.     sc.type = 'text/javascript';
  13.     var pgcount = count % chronPerPage;
  14.     if(!pgcount) pgcount = chronPerPage;
  15.     sc.src = "/feeds/posts/default?start-index="+(count - pgcount)+"&max-results=1&redirect=false&alt=json-in-script&callback=makeChronLink"+ "&_hash="+Math.random();
  16.     document.getElementsByTagName('head')[0].appendChild(sc);
  17. }  
  18. function doChronLink() {
  19.     var sc = document.createElement('script');
  20.     sc.type = 'text/javascript';
  21.     sc.src = "/feeds/posts/default?alt=json-in-script&redirect=false&max-results=1&callback=chronNumberOfPosts";
  22.     document.getElementsByTagName('head')[0].appendChild(sc);
  23. }
  24. window.addEventListener ? window.addEventListener("load",doChronLink,false) : window.attachEvent && window.attachEvent("onload",doChronLink);
  25. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement