Skip to content

Instantly share code, notes, and snippets.

@maxx-coffee
Last active August 29, 2015 13:57
Show Gist options
  • Save maxx-coffee/9655849 to your computer and use it in GitHub Desktop.
Save maxx-coffee/9655849 to your computer and use it in GitHub Desktop.
will_paginate with angular
$scope.buildPagination = () ->
c = $scope.current_page
padded = $scope.pagination_padding*2
arr = []
if c <= $scope.total_pages
min = c - $scope.pagination_padding
max = c + $scope.pagination_padding
show_next = true
show_prev = true
if min <= 0
min = 1
max = if padded > $scope.total_pages then $scope.total_pages else padded
else if $scope.total_pages < padded
min = 1
max = $scope.total_pages
else if max > $scope.total_pages
min = $scope.total_pages - padded
max = $scope.total_pages
show_next = if (c < $scope.total_pages) then true else false
show_prev = if (c > 1) then true else false
while min <= max
arr.push(min)
min++
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment