Advertisement
Guest User

prut

a guest
Sep 10th, 2010
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Wpg.Pager = function(){
  2.  
  3.     var perpage = 4;
  4.     var colcount = 0;
  5.     var lis = 0;
  6.     var pages = 0;
  7.  
  8.     function pagerClick(pageclickednumber) {
  9.         $("#pager").pager({ pagenumber: pageclickednumber, pagecount: pages, buttonClickCallback: pagerClick });
  10.         // hide all
  11.         lis.each(function() {
  12.             $(this).hide();
  13.         });
  14.        
  15.         pageclickednumber = pageclickednumber - 1;
  16.         var start = pageclickednumber * perpage;
  17.         var end = start + perpage;
  18.        
  19.         // divide start / end by cols - if perpage is 4 and cols is 2, only 2 per col have to be shown.
  20.         if (colcount > 1) {
  21.             start = Math.ceil(start / colcount);
  22.             end = Math.ceil(end / colcount);
  23.         }
  24.         //console.log('clicked: ' + pageclickednumber + ' perpage: ' + perpage + ' start: ' + start + ' end:' + end + ' cols:' + colcount);
  25.        
  26.         // nth-child starts counting at 1, hence, 0 + 1.
  27.         for (var i = start + 1; i <= end; i++) {
  28.             //console.log('.books-published-recently li:nth-child('+i+')');
  29.             $('.books-published-recently.paged li:nth-child('+i+')').show();
  30.         }
  31.     }
  32.        
  33.     return {
  34.         init: function() {
  35.             perpageclass = $('div[class*=perpage-]').attr('class');
  36.             // note: only works if perpage is the last class in the list.
  37.             perpage = parseInt(perpageclass.substr(perpageclass.indexOf('perpage-') + 8, perpageclass.length), 10);
  38.             //console.log(perpage);
  39.             cols = $('.books-published-recently.paged > ul.column');
  40.             colcount = cols.size();
  41.             lis = $('.books-published-recently.paged  li');
  42.             pages = Math.ceil(lis.size() / perpage);
  43.             var pager = $(document.createElement('div'));
  44.             pager.attr('id', 'pager');
  45.             $('.books-published-recently.paged').before(pager);
  46.             $('#pager').pager({ pagenumber: 1, pagecount: pages, buttonClickCallback: pagerClick });
  47.             // init on page 1.
  48.             pagerClick(1);
  49.         }
  50.     };
  51. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement