|
1 |
| -Template.defaultBootstrapPaginator.created = function(){ |
2 |
| - let self = this; |
3 |
| - if (!this.data.pagination) {return;} |
4 |
| - this.displayedPages = new ReactiveVar([]); |
5 |
| - this.runOnClick = function(e, clickedPage) { |
6 |
| - if (typeof self.data.onClick === 'function') { |
7 |
| - self.data.onClick(e, self, clickedPage); |
8 |
| - } else {e.preventDefault();} |
9 |
| - }; |
| 1 | +Template.defaultBootstrapPaginator.created = function () { |
| 2 | + let self = this; |
| 3 | + if (!this.data.pagination) { |
| 4 | + return; |
| 5 | + } |
| 6 | + this.displayedPages = new ReactiveVar([]); |
| 7 | + this.runOnClick = function (e, clickedPage) { |
| 8 | + if (typeof self.data.onClick === 'function') { |
| 9 | + self.data.onClick(e, self, clickedPage); |
| 10 | + } else { |
| 11 | + e.preventDefault(); |
| 12 | + } |
| 13 | + }; |
10 | 14 |
|
11 |
| - //auto slice displayedPages to fit in one line |
12 |
| - this.autorun(function(){ |
13 |
| - if (!self.data.pagination.ready()) {return;} |
14 |
| - let pageCount = self.data.pagination.totalPages(); |
15 |
| - let current = self.data.pagination.currentPage(); |
16 |
| - let displayedPages; |
17 |
| - if (pageCount > self.data.limit){ |
18 |
| - let min = 0; |
19 |
| - if (current > self.data.limit / 2) { |
20 |
| - if (current > pageCount - self.data.limit / 2) |
21 |
| - min = pageCount - self.data.limit; |
22 |
| - else |
23 |
| - min = Math.floor(current - self.data.limit/2); |
24 |
| - } |
25 |
| - displayedPages = getIntArray(min + 1, min + 1 + self.data.limit); |
26 |
| - } |
27 |
| - else displayedPages = getIntArray(1, pageCount + 1); |
28 |
| - self.displayedPages.set(displayedPages); |
29 |
| - }) |
| 15 | + //auto slice displayedPages to fit in one line |
| 16 | + this.autorun(function () { |
| 17 | + if (!self.data.pagination.ready()) |
| 18 | + return; |
| 19 | + let pageCount = self.data.pagination.totalPages(); |
| 20 | + let current = self.data.pagination.currentPage(); |
| 21 | + let displayedPages; |
| 22 | + if (pageCount > self.data.limit) { |
| 23 | + let min = 0; |
| 24 | + if (current > self.data.limit / 2) { |
| 25 | + if (current > pageCount - self.data.limit / 2) |
| 26 | + min = pageCount - self.data.limit; |
| 27 | + else |
| 28 | + min = Math.floor(current - self.data.limit / 2); |
| 29 | + } |
| 30 | + displayedPages = getIntArray(min + 1, min + 1 + self.data.limit); |
| 31 | + } else displayedPages = getIntArray(1, pageCount + 1); |
| 32 | + self.displayedPages.set(displayedPages); |
| 33 | + }) |
30 | 34 | };
|
31 | 35 |
|
32 | 36 | Template.defaultBootstrapPaginator.helpers({
|
33 |
| - hasPages: function () { |
34 |
| - return this.pagination && this.pagination.totalPages() > 1 && this.limit; |
35 |
| - }, |
36 |
| - getPaginationClass: function () { |
37 |
| - return this.paginationClass || "pagination"; |
38 |
| - }, |
39 |
| - getItemClass: function () { |
40 |
| - return this.itemClass || "page-item"; |
41 |
| - }, |
42 |
| - shouldWrapLinks: function () { |
43 |
| - return this.wrapLinks !== false; |
44 |
| - }, |
45 |
| - isActive : function(){ |
46 |
| - return this.valueOf() == Template.instance().data.pagination.currentPage(); |
47 |
| - }, |
48 |
| - pagesToDisplay: function(){ |
49 |
| - return Template.instance().displayedPages.get(); |
50 |
| - }, |
51 |
| - isInFirstPage: function () { |
52 |
| - return this.pagination.currentPage() == 1; |
53 |
| - }, |
54 |
| - arePreviousPagesHidden: function () { |
55 |
| - var displayedPages = Template.instance().displayedPages.get(); |
56 |
| - return displayedPages && displayedPages.length && displayedPages[0] > 1; |
57 |
| - }, |
58 |
| - areNextPagesHidden: function () { |
59 |
| - var displayedPages = Template.instance().displayedPages.get(); |
60 |
| - return displayedPages && displayedPages.length && (displayedPages[displayedPages.length - 1] < this.pagination.totalPages()); |
| 37 | + hasPages: function () { |
| 38 | + return this.pagination && this.pagination.totalPages() > 1 && this.limit; |
| 39 | + }, |
| 40 | + getPaginationClass: function () { |
| 41 | + return this.paginationClass || "pagination"; |
| 42 | + }, |
| 43 | + getItemClass: function () { |
| 44 | + return this.itemClass || "page-item"; |
| 45 | + }, |
| 46 | + shouldWrapLinks: function () { |
| 47 | + return this.wrapLinks !== false; |
| 48 | + }, |
| 49 | + isActive: function () { |
| 50 | + return this.valueOf() == Template.instance().data.pagination.currentPage(); |
| 51 | + }, |
| 52 | + pagesToDisplay: function () { |
| 53 | + return Template.instance().displayedPages.get(); |
| 54 | + }, |
| 55 | + isInFirstPage: function () { |
| 56 | + return this.pagination.currentPage() == 1; |
| 57 | + }, |
| 58 | + arePreviousPagesHidden: function () { |
| 59 | + var displayedPages = Template.instance().displayedPages.get(); |
| 60 | + return displayedPages && displayedPages.length && displayedPages[0] > 1; |
| 61 | + }, |
| 62 | + areNextPagesHidden: function () { |
| 63 | + var displayedPages = Template.instance().displayedPages.get(); |
| 64 | + return displayedPages && displayedPages.length && (displayedPages[displayedPages.length - 1] < this.pagination.totalPages()); |
61 | 65 |
|
62 |
| - }, |
63 |
| - isInLastPage: function () { |
64 |
| - return this.pagination.currentPage() == this.pagination.totalPages(); |
65 |
| - }, |
66 |
| - lastPage: function(){ |
67 |
| - return this.pagination.totalPages(); |
68 |
| - } |
| 66 | + }, |
| 67 | + isInLastPage: function () { |
| 68 | + return this.pagination.currentPage() == this.pagination.totalPages(); |
| 69 | + }, |
| 70 | + lastPage: function () { |
| 71 | + return this.pagination.totalPages(); |
| 72 | + } |
69 | 73 | });
|
70 | 74 |
|
71 | 75 | Template.defaultBootstrapPaginator.events({
|
72 |
| - 'click .page-link': function(e, templateInstance){ |
73 |
| - if(typeof this.valueOf() === 'number') { |
74 |
| - templateInstance.runOnClick(e, this.valueOf()); |
75 |
| - templateInstance.data.pagination.currentPage(this.valueOf()); |
76 |
| - } |
77 |
| - }, |
78 |
| - 'click .previous-page': function(e, templateInstance){ |
79 |
| - templateInstance.runOnClick(e, templateInstance.data.pagination.currentPage() - 1); |
80 |
| - templateInstance.data.pagination.currentPage(templateInstance.data.pagination.currentPage() - 1); |
81 |
| - }, |
82 |
| - 'click .next-page': function(e, templateInstance){ |
83 |
| - templateInstance.runOnClick(e, templateInstance.data.pagination.currentPage() + 1); |
84 |
| - templateInstance.data.pagination.currentPage(templateInstance.data.pagination.currentPage() + 1); |
85 |
| - }, |
86 |
| - 'click .show-prev': function(e, templateInstance){ |
87 |
| - e.preventDefault(); |
88 |
| - let displayedPages = templateInstance.displayedPages.get(); |
89 |
| - let min = Math.max(1, displayedPages[0] - templateInstance.data.limit); |
90 |
| - templateInstance.displayedPages.set(getIntArray(min, min + templateInstance.data.limit)); |
91 |
| - }, |
92 |
| - 'click .show-next': function(e, templateInstance){ |
93 |
| - e.preventDefault(); |
94 |
| - let pageCount = templateInstance.data.pagination.totalPages(); |
95 |
| - let displayedPages = templateInstance.displayedPages.get(); |
96 |
| - let min = Math.min(pageCount - templateInstance.data.limit, displayedPages[displayedPages.length - 1]) + 1; |
97 |
| - templateInstance.displayedPages.set(getIntArray(min, min + templateInstance.data.limit)); |
| 76 | + 'click .page-link': function (e, templateInstance) { |
| 77 | + if (typeof this.valueOf() === 'number') { |
| 78 | + templateInstance.runOnClick(e, this.valueOf()); |
| 79 | + templateInstance.data.pagination.currentPage(this.valueOf()); |
98 | 80 | }
|
| 81 | + }, |
| 82 | + 'click .previous-page': function (e, templateInstance) { |
| 83 | + templateInstance.runOnClick(e, templateInstance.data.pagination.currentPage() - 1); |
| 84 | + templateInstance.data.pagination.currentPage(templateInstance.data.pagination.currentPage() - 1); |
| 85 | + }, |
| 86 | + 'click .next-page': function (e, templateInstance) { |
| 87 | + templateInstance.runOnClick(e, templateInstance.data.pagination.currentPage() + 1); |
| 88 | + templateInstance.data.pagination.currentPage(templateInstance.data.pagination.currentPage() + 1); |
| 89 | + }, |
| 90 | + 'click .show-prev': function (e, templateInstance) { |
| 91 | + e.preventDefault(); |
| 92 | + let displayedPages = templateInstance.displayedPages.get(); |
| 93 | + let min = Math.max(1, displayedPages[0] - templateInstance.data.limit); |
| 94 | + templateInstance.displayedPages.set(getIntArray(min, min + templateInstance.data.limit)); |
| 95 | + }, |
| 96 | + 'click .show-next': function (e, templateInstance) { |
| 97 | + e.preventDefault(); |
| 98 | + let pageCount = templateInstance.data.pagination.totalPages(); |
| 99 | + let displayedPages = templateInstance.displayedPages.get(); |
| 100 | + let min = Math.min(pageCount - templateInstance.data.limit, displayedPages[displayedPages.length - 1]) + 1; |
| 101 | + templateInstance.displayedPages.set(getIntArray(min, min + templateInstance.data.limit)); |
| 102 | + } |
99 | 103 | });
|
100 | 104 |
|
101 |
| -let getIntArray = function(min, max){ |
102 |
| - let result = []; |
103 |
| - for(let i = min; i < max; ++i) {result.push(i);} |
104 |
| - return result; |
| 105 | +let getIntArray = function (min, max) { |
| 106 | + let result = []; |
| 107 | + for (let i = min; i < max; ++i) { |
| 108 | + result.push(i); |
| 109 | + } |
| 110 | + return result; |
105 | 111 | };
|
0 commit comments