-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathsimplePagination.js
64 lines (50 loc) · 1.27 KB
/
simplePagination.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
56
57
58
59
60
61
62
63
64
(function() {
"use strict";
var paginationModule = angular.module('simplePagination', []);
paginationModule.factory('Pagination', function() {
var pagination = {};
pagination.getNew = function(perPage) {
perPage = perPage === undefined ? 5 : perPage;
var paginator = {
numPages: 1,
perPage: perPage,
page: 0
};
paginator.prevPage = function() {
if (paginator.page > 0) {
paginator.page -= 1;
}
};
paginator.nextPage = function() {
if (paginator.page < paginator.numPages - 1) {
paginator.page += 1;
}
};
paginator.toPageId = function(id) {
if (id >= 0 && id <= paginator.numPages - 1) {
paginator.page = id;
}
};
return paginator;
};
return pagination;
});
paginationModule.filter('startFrom', function() {
return function(input, start) {
if (input === undefined) {
return input;
} else {
return input.slice(+start);
}
};
});
paginationModule.filter('range', function() {
return function(input, total) {
total = parseInt(total);
for (var i = 0; i < total; i++) {
input.push(i);
}
return input;
};
});
})();