Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
refactor(pagination): keep it DRY between pagination & pager
Browse files Browse the repository at this point in the history
  • Loading branch information
bekos authored and pkozlowski-opensource committed Jul 25, 2013
1 parent 8d90486 commit 682ae66
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/pagination/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ angular.module('ui.bootstrap.pagination', [])
return this.currentPage === page;
};

this.reset = function() {
$scope.pages = [];
this.currentPage = parseInt($scope.currentPage, 10);

if ( this.currentPage > $scope.numPages ) {
$scope.selectPage($scope.numPages);
}
};

var self = this;
$scope.selectPage = function(page) {
if ( ! self.isActive(page) && page > 0 && page <= $scope.numPages) {
Expand Down Expand Up @@ -68,8 +77,7 @@ angular.module('ui.bootstrap.pagination', [])
}

scope.$watch('numPages + currentPage + maxSize', function() {
scope.pages = [];
paginationCtrl.currentPage = parseInt(scope.currentPage, 10);
paginationCtrl.reset();

// Default page limits
var startPage = 1, endPage = scope.numPages;
Expand Down Expand Up @@ -132,10 +140,6 @@ angular.module('ui.bootstrap.pagination', [])
var lastPage = makePage(scope.numPages, lastText, false, paginationCtrl.noNext());
scope.pages.push(lastPage);
}

if ( paginationCtrl.currentPage > scope.numPages ) {
scope.selectPage(scope.numPages);
}
});
}
};
Expand Down Expand Up @@ -177,19 +181,14 @@ angular.module('ui.bootstrap.pagination', [])
}

scope.$watch('numPages + currentPage', function() {
scope.pages = [];
paginationCtrl.currentPage = parseInt(scope.currentPage, 10);
paginationCtrl.reset();

// Add previous & next links
var previousPage = makePage(paginationCtrl.currentPage - 1, previousText, paginationCtrl.noPrevious(), true, false);
scope.pages.unshift(previousPage);

var nextPage = makePage(paginationCtrl.currentPage + 1, nextText, paginationCtrl.noNext(), false, true);
scope.pages.push(nextPage);

if ( paginationCtrl.currentPage > scope.numPages ) {
scope.selectPage(scope.numPages);
}
});
}
};
Expand Down

0 comments on commit 682ae66

Please sign in to comment.