Skip to content

Commit 3b028bd

Browse files
[TEX-15833] Modify and change version of the pagination-blaze package
1 parent f2cda13 commit 3b028bd

File tree

4 files changed

+134
-109
lines changed

4 files changed

+134
-109
lines changed

.versions

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ [email protected]
55
66
77
8-
carlosalvidrez:[email protected].1
9-
carlosalvidrez:[email protected].1
8+
carlosalvidrez:[email protected].2
9+
carlosalvidrez:[email protected].2
1010
1111
1212

README.md

+31-12
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,52 @@
11
carlosalvidrez:pagination-blaze
22
=================
33

4-
Forked from Kurounin:Pagination-Blaze
4+
Forked from Kurounin:Pagination-Blaze in order to make it compatible with Meteor 3.
55

6-
This package provides a bootstrap 5 paginator Blaze template to be used with the [carlosalvidrez:pagination](https://atmospherejs.com/carlosalvidrez/pagination) package. It can also be configured to use custom styling.
6+
This package provides a Bootstrap 5 Paginator Blaze template to be used with the [carlosalvidrez:pagination](https://atmospherejs.com/carlosalvidrez/pagination) package. It can also be configured to use custom styling.
77

88
# Usage
99
In the template helpers you need to define a helper to return the pagination instance and you can define an optional callback which should be called right before changing the page
1010
```js
1111
Template.myList.helpers({
12-
templatePagination: function () {
13-
return Template.instance().pagination;
14-
},
15-
clickEvent: function() {
16-
return function(e, templateInstance, clickedPage) {
12+
13+
templatePagination: () => Template.instance().pagination,
14+
15+
clickEvent: () => {
16+
return (e, templateInstance, clickedPage) => {
1717
e.preventDefault();
18-
console.log('Changing page from ', templateInstance.data.pagination.currentPage(), ' to ', clickedPage);
18+
console.log(
19+
'Changing page from ',
20+
templateInstance.data.pagination.currentPage(),
21+
' to ',
22+
clickedPage
23+
);
1924
};
20-
}
25+
}
26+
2127
});
2228
```
2329

2430
In the template html file add the paginator
2531
```html
26-
{{> defaultBootstrapPaginator pagination=templatePagination onClick=clickEvent limit=10 containerClass="text-center"}}
32+
{{> defaultBootstrapPaginator
33+
pagination=templatePagination
34+
onClick=clickEvent
35+
limit=10
36+
containerClass="text-center"
37+
}}
2738
```
2839

2940
For Semantic UI, use the following configuration
3041
```html
31-
{{> defaultBootstrapPaginator pagination=templatePagination onClick=clickEvent limit=10 paginationClass="ui pagination menu" itemClass="item" wrapLinks=false}}
42+
{{> defaultBootstrapPaginator
43+
pagination=templatePagination
44+
onClick=clickEvent
45+
limit=10
46+
paginationClass="ui pagination menu"
47+
itemClass="item"
48+
wrapLinks=false
49+
}}
3250
```
3351

3452
Available template parameters are:
@@ -38,4 +56,5 @@ Available template parameters are:
3856
* `paginationClass`: optional class for the *ul* element (defaults to `pagination`)
3957
* `itemClass`: optional class for the page links elements
4058
* `wrapLinks`: if set to true page links will be wrapped in *li* elements (defaults to `true`)
41-
* `onClick`: optional callback to be called when page link is clicked (default callback runs `e.preventDefault()`)
59+
* `onClick`: optional callback to be called when page link is clicked (default callback runs `e.preventDefault()`)
60+

client/template.js

+99-93
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,111 @@
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+
};
1014

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+
})
3034
};
3135

3236
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());
6165

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+
}
6973
});
7074

7175
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());
9880
}
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+
}
99103
});
100104

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;
105111
};

package.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package.describe({
22
"name": "carlosalvidrez:pagination-blaze",
33
"summary": "Blaze paginator Bootstrap 5 template for carlosalvidrez:pagination package",
4-
"version": "0.0.1",
4+
"version": "0.0.2",
55
"git": "https://github.com/carlosalvidrez/pagination-blaze.git"
66
});
77

@@ -10,7 +10,7 @@ Package.onUse(function (api) {
1010

1111
api.use([
1212
"underscore",
13-
"carlosalvidrez:[email protected].1"
13+
"carlosalvidrez:[email protected].2"
1414
]);
1515

1616
api.use([

0 commit comments

Comments
 (0)