Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Wpg.Pager = function(){
- var perpage = 4;
- var colcount = 0;
- var lis = 0;
- var pages = 0;
- function pagerClick(pageclickednumber) {
- $("#pager").pager({ pagenumber: pageclickednumber, pagecount: pages, buttonClickCallback: pagerClick });
- // hide all
- lis.each(function() {
- $(this).hide();
- });
- pageclickednumber = pageclickednumber - 1;
- var start = pageclickednumber * perpage;
- var end = start + perpage;
- // divide start / end by cols - if perpage is 4 and cols is 2, only 2 per col have to be shown.
- if (colcount > 1) {
- start = Math.ceil(start / colcount);
- end = Math.ceil(end / colcount);
- }
- //console.log('clicked: ' + pageclickednumber + ' perpage: ' + perpage + ' start: ' + start + ' end:' + end + ' cols:' + colcount);
- // nth-child starts counting at 1, hence, 0 + 1.
- for (var i = start + 1; i <= end; i++) {
- //console.log('.books-published-recently li:nth-child('+i+')');
- $('.books-published-recently.paged li:nth-child('+i+')').show();
- }
- }
- return {
- init: function() {
- perpageclass = $('div[class*=perpage-]').attr('class');
- // note: only works if perpage is the last class in the list.
- perpage = parseInt(perpageclass.substr(perpageclass.indexOf('perpage-') + 8, perpageclass.length), 10);
- //console.log(perpage);
- cols = $('.books-published-recently.paged > ul.column');
- colcount = cols.size();
- lis = $('.books-published-recently.paged li');
- pages = Math.ceil(lis.size() / perpage);
- var pager = $(document.createElement('div'));
- pager.attr('id', 'pager');
- $('.books-published-recently.paged').before(pager);
- $('#pager').pager({ pagenumber: 1, pagecount: pages, buttonClickCallback: pagerClick });
- // init on page 1.
- pagerClick(1);
- }
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement