Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Oct 25, 2013
0 parents commit f7175b4
Show file tree
Hide file tree
Showing 10 changed files with 464 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.build*
4 changes: 4 additions & 0 deletions README.md
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.
65 changes: 65 additions & 0 deletions client/main._coffee
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
21 changes: 21 additions & 0 deletions client/main.coffee
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
Binary file added loader.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions package.js
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"]);
});
Loading

0 comments on commit f7175b4

Please sign in to comment.