SHARE
TWEET

Post titles to Blogger Older and Newer Post links - reloaded

mspotilas Jun 27th, 2012 863 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <b:if cond='data:blog.pageType == &quot;item&quot;'>
  2. <script type='text/javascript'>
  3. // Post titles to Older Post and Newer Post links (without stats skew) - reloaded!
  4. // by MS-potilas 2012. See http://yabtb.blogspot.com/2012/06/titles-to-older-newer-links-reloaded.html
  5. //<![CDATA[
  6. //
  7. // Configuration:
  8. // In these you can use [title]:
  9. var olderLink = 'Older Post &gt;&gt;<div class="blog-pager-older-link-title">[title]</div>';
  10. var newerLink = '&lt;&lt; Newer Post<div class="blog-pager-newer-link-title">[title]</div>';
  11. // In these you can use [date], [datetime], [title]:
  12. var olderTitle = 'Older Post - posted on [date]';
  13. var newerTitle = 'Newer Post - posted on [date]';
  14. // configuration ends
  15. //
  16. function setLink(selector, link, title, entry) {
  17.   var htm = link.replace("[title]", entry.title.$t);
  18.   $(selector).html(htm);
  19.   var date = entry.published.$t.match(/\d+/g);
  20.   date = new Date(date[0],date[1]-1,date[2],date[3],date[4],date[5]); // convert iso
  21.   title = title.replace('[date]', date.toLocaleDateString());
  22.   title = title.replace('[datetime]', date.toLocaleString());
  23.   title = title.replace("[title]", entry.title.$t);
  24.   $(selector).attr("title", title);
  25. }
  26. function setOlderLink(entry) { setLink("a.blog-pager-older-link", olderLink, olderTitle, entry); }
  27. function setNewerLink(entry) { setLink("a.blog-pager-newer-link", newerLink, newerTitle, entry); }
  28. $(window).load(function() {
  29.   window.setTimeout(function() {
  30.     var timestamp = $(".published").attr("title");
  31.     if(timestamp && timestamp != "")
  32.       $.getJSON("/feeds/posts/default?alt=json-in-script&published-min="+encodeURIComponent(timestamp)+"&max-results=0&callback=?", function(resp) {
  33.         var postindex = parseInt(resp.feed.openSearch$totalResults.$t);
  34.         if(postindex > 1)
  35.           $.getJSON("/feeds/posts/summary?alt=json-in-script&start-index="+(postindex-1)+"&max-results=3&callback=?", function(resp) {
  36.             setNewerLink(resp.feed.entry[0]);
  37.             var postcount = parseInt(resp.feed.openSearch$totalResults.$t);
  38.             var startindex = parseInt(resp.feed.openSearch$startIndex.$t);
  39.             if(postcount - startindex > 1) setOlderLink(resp.feed.entry[2]);
  40.           });
  41.         else
  42.           $.getJSON("/feeds/posts/summary?alt=json-in-script&start-index=2&max-results=1&callback=?", function(resp) { setOlderLink(resp.feed.entry[0]); });
  43.       });
  44.   }, 500);
  45. });
  46. //]]>
  47. </script>
  48. </b:if>
RAW Paste Data
Want to get better at JavaScript?
Learn to code JavaScript in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top