Skip to content

Commit 41634c4

Browse files
[TEX-15041] Create a new public repository for the custom blaze pagination library
1 parent 693b7fb commit 41634c4

10 files changed

+333
-2
lines changed

.idea/.gitignore

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

+40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/pagination-blaze.iml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSE

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
MIT License
1+
The MIT License (MIT)
22

3-
Copyright (c) 2024 Carlos Alvidrez
3+
Copyright (c) 2015 Kurounin
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -19,3 +19,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
SOFTWARE.
22+

README.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
carlosalvidrez:pagination-blaze
2+
=================
3+
4+
Forked from Kurounin:Pagination-Blaze
5+
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.
7+
8+
# Usage
9+
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
10+
```js
11+
Template.myList.helpers({
12+
templatePagination: function () {
13+
return Template.instance().pagination;
14+
},
15+
clickEvent: function() {
16+
return function(e, templateInstance, clickedPage) {
17+
e.preventDefault();
18+
console.log('Changing page from ', templateInstance.data.pagination.currentPage(), ' to ', clickedPage);
19+
};
20+
}
21+
});
22+
```
23+
24+
In the template html file add the paginator
25+
```html
26+
{{> defaultBootstrapPaginator pagination=templatePagination onClick=clickEvent limit=10 containerClass="text-center"}}
27+
```
28+
29+
For Semantic UI, use the following configuration
30+
```html
31+
{{> defaultBootstrapPaginator pagination=templatePagination onClick=clickEvent limit=10 paginationClass="ui pagination menu" itemClass="item" wrapLinks=false}}
32+
```
33+
34+
Available template parameters are:
35+
* `pagination`: pagination instance
36+
* `limit`: the maximum number of page links to display
37+
* `containerClass`: optional container class for the paginator
38+
* `paginationClass`: optional class for the *ul* element (defaults to `pagination`)
39+
* `itemClass`: optional class for the page links elements
40+
* `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()`)

client/template.html

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<template name="defaultBootstrapPaginator">
2+
<div class="pagination-container {{containerClass}}" >
3+
{{#if hasPages}}
4+
<ul class="{{getPaginationClass}}">
5+
6+
{{#if shouldWrapLinks}}
7+
<li class="{{#if isInFirstPage}}disabled{{/if}} {{getItemClass}}">
8+
<a href="#" class="page-link previous-page" title="Previous page"> &lt; </a>
9+
</li>
10+
{{else}}
11+
<a href="#" class="previous-page {{#if isInFirstPage}}disabled{{/if}} {{getItemClass}}" title="Previous page"> &lt; </a>
12+
{{/if}}
13+
14+
{{! Previous pages }}
15+
{{#if arePreviousPagesHidden}}
16+
{{#if shouldWrapLinks}}
17+
{{#with 1}}
18+
<li class="{{getItemClass}}">
19+
<a href="#" class="page-link" title="Go to page {{.}}"> {{.}} </a>
20+
</li>
21+
{{/with}}
22+
{{else}}
23+
{{#with 1}}
24+
<a href="#" class="page-link {{getItemClass}}" title="Go to page {{.}}"> {{.}} </a>
25+
{{/with}}
26+
{{/if}}
27+
28+
{{#if shouldWrapLinks}}
29+
<li class="{{getItemClass}}">
30+
<a href="#" class="page-link show-prev" title="Show previous pages"> ... </a>
31+
</li>
32+
{{else}}
33+
<a href="#" class="show-prev {{getItemClass}}" title="Show previous pages"> ... </a>
34+
{{/if}}
35+
{{/if}}
36+
37+
{{#if shouldWrapLinks}}
38+
{{#each pagesToDisplay}}
39+
<li class="{{#if isActive}}active{{/if}} {{getItemClass}}">
40+
<a href="#" class="page-link" title="page {{.}}">{{.}}</a>
41+
</li>
42+
{{/each}}
43+
{{else}}
44+
{{#each pagesToDisplay}}
45+
<a href="#" class="page-link {{getItemClass}}" title="page {{.}}">{{.}}</a>
46+
{{/each}}
47+
{{/if}}
48+
49+
{{! Next pages }}
50+
{{#if areNextPagesHidden}}
51+
{{#if shouldWrapLinks}}
52+
<li class="{{getItemClass}}">
53+
<a href="#" class="page-link show-next" title="Show next pages"> ... </a>
54+
</li>
55+
{{else}}
56+
<a href="#" class="show-next {{getItemClass}}" title="Show next pages"> ... </a>
57+
{{/if}}
58+
{{#if shouldWrapLinks}}
59+
{{#with lastPage}}
60+
<li class="{{getItemClass}}">
61+
<a href="#" class="page-link" title="Go to page {{.}}"> {{.}} </a>
62+
</li>
63+
{{/with}}
64+
{{else}}
65+
{{#with lastPage}}
66+
<a href="#" class="page-link {{getItemClass}}" title="Go to page {{.}}"> {{.}} </a>
67+
{{/with}}
68+
{{/if}}
69+
{{/if}}
70+
71+
{{#if shouldWrapLinks}}
72+
<li class="{{#if isInLastPage}}disabled{{/if}} {{getItemClass}}">
73+
<a href="#" class="page-link next-page" title="Next page"> &gt; </a>
74+
</li>
75+
{{else}}
76+
<a href="#" class="next-page {{#if isInLastPage}}disabled{{/if}} {{getItemClass}}" title="Next page"> &gt; </a>
77+
{{/if}}
78+
79+
</ul>
80+
{{/if}}
81+
</div>
82+
</template>

client/template.js

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+
};
10+
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+
})
30+
};
31+
32+
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());
61+
62+
},
63+
isInLastPage: function () {
64+
return this.pagination.currentPage() == this.pagination.totalPages();
65+
},
66+
lastPage: function(){
67+
return this.pagination.totalPages();
68+
}
69+
});
70+
71+
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));
98+
}
99+
});
100+
101+
let getIntArray = function(min, max){
102+
let result = [];
103+
for(let i = min; i < max; ++i) {result.push(i);}
104+
return result;
105+
};

package.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Package.describe({
2+
"name": "carlosalvidrez:pagination-blaze",
3+
"summary": "Blaze paginator Bootstrap 5 template for carlosalvidrez:pagination package",
4+
"version": "0.0.1",
5+
"git": "https://github.com/carlosalvidrez/pagination-blaze.git"
6+
});
7+
8+
Package.onUse(function (api) {
9+
api.versionsFrom("2.16");
10+
11+
api.use([
12+
//"meteor-base",
13+
"underscore",
14+
"carlosalvidrez:pagination"
15+
]);
16+
17+
api.use([
18+
"reactive-var",
19+
"reactive-dict"
20+
], "client");
21+
22+
api.use([
23+
"templating",
24+
"blaze"
25+
], "client");
26+
27+
api.addFiles([
28+
"client/template.html",
29+
"client/template.js"
30+
], "client");
31+
});

0 commit comments

Comments
 (0)