9 $.fn.filterItems = function(condition)
11 settings.items = $('p', this);
13 if(condition) settings.items = settings.items.filter(function() {
14 return condition( $(this).attr('title') );
17 var pageCount = Math.ceil(settings.items.length / settings.itemsPerPage);
18 var buttons = $('.page-nav-wrap button', this.parent());
19 buttons.show().filter(function(i) { return i >= pageCount; }).hide();
23 $.fn.switchToPage = function(index)
25 index = index || settings.page;
26 var start = index * settings.itemsPerPage;
27 var end = start + settings.itemsPerPage;
30 var visibleItems = settings.items.filter(function(i) { return i >= start && i < end; });
34 $.fn.paginate = function(options)
39 if (options) $.extend(settings, options);
40 settings.items = $('p', list);
42 var nav = $('<p class="page-nav-wrap"></p>');
44 var pageCount = Math.floor(settings.items.length / settings.itemsPerPage);
45 var orphanCount = settings.items.length - (pageCount * settings.itemsPerPage);
48 for(var i=0; i < pageCount; i++)
50 button = $("<button type='button'>"+(i+1)+"</button>");
51 button.bind('click', i, function(event) { list.switchToPage(event.data); });
58 button = $("<button type='button'>"+(i+1)+"</button>");
59 button.bind('click', i, function(event) { list.switchToPage(event.data); });
63 list.filterItems(function(){return true;});