forked from alethes/meteor-pages
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
root
committed
Oct 25, 2013
0 parents
commit f7175b4
Showing
10 changed files
with
464 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.build* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Meteor Paginate | ||
=============== | ||
|
||
State of the art, out of the box Meteor pagination. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
@p = (p) -> | ||
Session.set "paginate.currentPage", p | ||
@sess = (n, v) -> | ||
Session.get "paginate.#{n}.#{v}" | ||
|
||
Handlebars.registerHelper "paginate", (n) -> | ||
content = Template.paginateContent | ||
content.items = -> | ||
Deps.autorun -> | ||
if n in Paginates | ||
Paginates[n].getPage sess n, "currentPage" | ||
content.ready = -> | ||
sess n, "ready" | ||
content.item = -> | ||
Template[Paginates[n].itemTemplate] @ | ||
Meteor.render content | ||
Handlebars.registerHelper "paginateNav", (n) -> | ||
nav = Template.paginateNav | ||
nav.show = -> | ||
1 < Session.get "paginate.#{n}.totalPages" | ||
nav.paginationNeighbors = -> | ||
page = sess n, "currentPage" | ||
total = sess n, "totalPages" | ||
margin = Session.get "paginate.#{n}.paginationMargin" | ||
from = page - margin | ||
to = page + margin | ||
if from < 1 | ||
to += 1 - from | ||
from = 1 | ||
if to > total | ||
from -= to - total | ||
to = total | ||
from = 1 if from < 1 | ||
to = total if to > total | ||
n = [] | ||
n.push | ||
p: "«" | ||
n: "previous" | ||
active: "" | ||
disabled: if page == 1 then "disabled" else "" | ||
for p in [from .. to] | ||
n.push | ||
p: p | ||
n: p | ||
active: if p == page then "active" else "" | ||
disabled: if page > total then "disabled" else "" | ||
n.push | ||
p: "»" | ||
n: "next" | ||
active: "" | ||
disabled: if page >= total then "disabled" else "" | ||
n | ||
nav.events = | ||
"click li": -> | ||
cpage = sess n, "currentPage" | ||
total = sess n, "totalPages" | ||
if @n is "previous" | ||
page = cpage - 1 | ||
else if @n is "next" | ||
page = cpage + 1 | ||
else | ||
page = @p | ||
if page <= total and page > 0 | ||
Session.set "paginate.#{n}.currentPage", page | ||
Meteor.render nav |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
@p = (p) -> | ||
Session.set "paginate.currentPage", p | ||
@P = @Paginate | ||
p = Template.paginate | ||
p.ready = -> | ||
Session.get "paginate.ready" | ||
p.items = -> | ||
Paginate.getPage Session.get "paginate.currentPage" | ||
p.item = -> | ||
Template[Paginate.itemTemplate] @ | ||
|
||
_.extend Template.paginateNav, | ||
show: -> | ||
1 < Session.get "paginate.totalPages" | ||
paginationNeighbors: -> | ||
Session.get "paginate.currentPage" | ||
Paginate.paginationNeighbors() | ||
events: | ||
"click a": _.throttle ( -> | ||
Paginate.onNavClick.call Paginate, @n, @p | ||
), 1000 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Package.describe({ | ||
summary: "State of the art, out of the box Meteor pagination" | ||
}); | ||
|
||
Package.on_use(function(api){ | ||
api.use([ | ||
"deps", | ||
"templating", | ||
"underscore", | ||
"coffeescript", | ||
"handlebars", | ||
"spark", | ||
"session" | ||
], "client"); | ||
|
||
api.use([ | ||
"deps", | ||
"underscore", | ||
"coffeescript" | ||
], "server"); | ||
|
||
api.add_files([ | ||
"templates.html", | ||
"client/main.coffee", | ||
"loader.gif" | ||
], "client"); | ||
|
||
api.export([ | ||
"_Paginate", | ||
"_PaginateInstances" | ||
], ["client", "server"]); | ||
api.add_files("paginate.coffee", ["client", "server"]); | ||
}); |
Oops, something went wrong.