-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpagination.js
55 lines (32 loc) · 1.71 KB
/
pagination.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
(function($){
$.fn.customPaginate = function(options)
{
var paginationContainer = this;
var itemsToPaginate;
var defaults = {
itemsPerPage : 5
};
var settings = {};
$.extend(settings, defaults, options);
var itemsPerPage = settings.itemsPerPage;
itemsToPaginate = $(settings.itemsToPaginate);
var numberOfPaginationLinks = Math.ceil((itemsToPaginate.length / itemsPerPage));
$("<ul></ul>").prependTo(paginationContainer);
for(var index = 0; index < numberOfPaginationLinks; index++)
{
paginationContainer.find("ul").append("<li>"+ (index+1) + "</li>");
}
itemsToPaginate.filter(":gt(" + (itemsPerPage - 1) + ")").hide();
paginationContainer.find("ul li").first().addClass(settings.activeClass).end().on('click', function(){
var $this = $(this);
$this.addClass(settings.activeClass);
$this.siblings().removeClass(settings.activeClass);
var linkNumber = $this.text();
var itemsToHide = itemsToPaginate.filter(":lt(" + ((linkNumber-1) * itemsPerPage) + ")");
$.merge(itemsToHide, itemsToPaginate.filter(":gt(" + ((linkNumber * itemsPerPage) - 1) + ")"));
var itemsToShow = itemsToPaginate.not(itemsToHide);
itemsToHide.hide();
itemsToShow.show();
});
}
}(jQuery));