Advertisement
mspotilas

Shuffle and limit count of Blogger popular posts

Dec 5th, 2011
890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type='text/javascript'>
  2. //<![CDATA[
  3. // Shuffle and limit count of Blogger popular posts using jQuery / MS-potilas 2011
  4. // Put this code in a html/javascript gadget or before </body>.
  5. // See http://yabtb.blogspot.com/2011/12/shuffle-and-limit-popular-post-gadget.html
  6. var popcount = 8;
  7. var ul = $('.popular-posts ul');
  8. var lis = $('.popular-posts ul li').detach();
  9. if(lis.length>1) {
  10.   for(var i=lis.length-1;i;i--) {       // fisher-yates/knuth
  11.     var j=parseInt(Math.random()*i);
  12.     lis[j] = lis.splice(i,1,lis[j])[0]; // swap lis[i]&lis[j]
  13.   }
  14.   lis.slice(-popcount).appendTo(ul);
  15. }
  16. //]]>
  17. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement