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

Commit 682ae66

Browse files
bekospkozlowski-opensource
authored andcommittedJul 25, 2013
refactor(pagination): keep it DRY between pagination & pager
1 parent 8d90486 commit 682ae66

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed
 

‎src/pagination/pagination.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ angular.module('ui.bootstrap.pagination', [])
1515
return this.currentPage === page;
1616
};
1717

18+
this.reset = function() {
19+
$scope.pages = [];
20+
this.currentPage = parseInt($scope.currentPage, 10);
21+
22+
if ( this.currentPage > $scope.numPages ) {
23+
$scope.selectPage($scope.numPages);
24+
}
25+
};
26+
1827
var self = this;
1928
$scope.selectPage = function(page) {
2029
if ( ! self.isActive(page) && page > 0 && page <= $scope.numPages) {
@@ -68,8 +77,7 @@ angular.module('ui.bootstrap.pagination', [])
6877
}
6978

7079
scope.$watch('numPages + currentPage + maxSize', function() {
71-
scope.pages = [];
72-
paginationCtrl.currentPage = parseInt(scope.currentPage, 10);
80+
paginationCtrl.reset();
7381

7482
// Default page limits
7583
var startPage = 1, endPage = scope.numPages;
@@ -132,10 +140,6 @@ angular.module('ui.bootstrap.pagination', [])
132140
var lastPage = makePage(scope.numPages, lastText, false, paginationCtrl.noNext());
133141
scope.pages.push(lastPage);
134142
}
135-
136-
if ( paginationCtrl.currentPage > scope.numPages ) {
137-
scope.selectPage(scope.numPages);
138-
}
139143
});
140144
}
141145
};
@@ -177,19 +181,14 @@ angular.module('ui.bootstrap.pagination', [])
177181
}
178182

179183
scope.$watch('numPages + currentPage', function() {
180-
scope.pages = [];
181-
paginationCtrl.currentPage = parseInt(scope.currentPage, 10);
184+
paginationCtrl.reset();
182185

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

187190
var nextPage = makePage(paginationCtrl.currentPage + 1, nextText, paginationCtrl.noNext(), false, true);
188191
scope.pages.push(nextPage);
189-
190-
if ( paginationCtrl.currentPage > scope.numPages ) {
191-
scope.selectPage(scope.numPages);
192-
}
193192
});
194193
}
195194
};

0 commit comments

Comments
 (0)