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

Commit 9aea856

Browse files
BobbieBarkerFoxandxss
authored andcommitted
feat(pagination): add uib- prefix
Closes #4536
1 parent 4e60e22 commit 9aea856

File tree

5 files changed

+278
-59
lines changed

5 files changed

+278
-59
lines changed

src/pagination/docs/demo.html

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<div ng-controller="PaginationDemoCtrl">
22
<h4>Default</h4>
3-
<pagination total-items="totalItems" ng-model="currentPage" ng-change="pageChanged()"></pagination>
4-
<pagination boundary-links="true" total-items="totalItems" ng-model="currentPage" class="pagination-sm" previous-text="&lsaquo;" next-text="&rsaquo;" first-text="&laquo;" last-text="&raquo;"></pagination>
5-
<pagination direction-links="false" boundary-links="true" total-items="totalItems" ng-model="currentPage"></pagination>
6-
<pagination direction-links="false" total-items="totalItems" ng-model="currentPage" num-pages="smallnumPages"></pagination>
3+
<uib-pagination total-items="totalItems" ng-model="currentPage" ng-change="pageChanged()"></uib-pagination>
4+
<uib-pagination boundary-links="true" total-items="totalItems" ng-model="currentPage" class="pagination-sm" previous-text="&lsaquo;" next-text="&rsaquo;" first-text="&laquo;" last-text="&raquo;"></uib-pagination>
5+
<uib-pagination direction-links="false" boundary-links="true" total-items="totalItems" ng-model="currentPage"></uib-pagination>
6+
<uib-pagination direction-links="false" total-items="totalItems" ng-model="currentPage" num-pages="smallnumPages"></uib-pagination>
77
<pre>The selected page no: {{currentPage}}</pre>
88
<button type="button" class="btn btn-info" ng-click="setPage(3)">Set current page to: 3</button>
99

1010
<hr />
1111
<h4>Pager</h4>
12-
<pager total-items="totalItems" ng-model="currentPage"></pager>
12+
<uib-pager total-items="totalItems" ng-model="currentPage"></uib-pager>
1313

1414
<hr />
1515
<h4>Limit the maximum visible buttons</h4>
16-
<pagination total-items="bigTotalItems" ng-model="bigCurrentPage" max-size="maxSize" class="pagination-sm" boundary-links="true"></pagination>
17-
<pagination total-items="bigTotalItems" ng-model="bigCurrentPage" max-size="maxSize" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>
16+
<uib-pagination total-items="bigTotalItems" ng-model="bigCurrentPage" max-size="maxSize" class="pagination-sm" boundary-links="true"></uib-pagination>
17+
<uib-pagination total-items="bigTotalItems" ng-model="bigCurrentPage" max-size="maxSize" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></uib-pagination>
1818
<pre>Page: {{bigCurrentPage}} / {{numPages}}</pre>
1919
</div>

src/pagination/docs/readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ A lightweight pagination directive that is focused on ... providing pagination &
33

44
### Pagination Settings ###
55

6-
Settings can be provided as attributes in the `<pagination>` or globally configured through the `paginationConfig`.
6+
Settings can be provided as attributes in the `<uib-pagination>` or globally configured through the `uibPaginationConfig`.
77

88
* `ng-change`
99
:
@@ -67,7 +67,7 @@ Settings can be provided as attributes in the `<pagination>` or globally configu
6767

6868
### Pager Settings ###
6969

70-
Settings can be provided as attributes in the `<pager>` or globally configured through the `pagerConfig`.
70+
Settings can be provided as attributes in the `<uib-pager>` or globally configured through the `uibPagerConfig`.
7171
For `ng-model`, `total-items`, `items-per-page` and `num-pages` see pagination settings. Other settings are:
7272

7373
* `align`

src/pagination/pagination.js

+166-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
angular.module('ui.bootstrap.pagination', [])
2-
.controller('PaginationController', ['$scope', '$attrs', '$parse', function($scope, $attrs, $parse) {
2+
.controller('UibPaginationController', ['$scope', '$attrs', '$parse', function($scope, $attrs, $parse) {
33
var self = this,
44
ngModelCtrl = { $setViewValue: angular.noop }, // nullModelCtrl
55
setNumPages = $attrs.numPages ? $parse($attrs.numPages).assign : angular.noop;
@@ -73,7 +73,7 @@ angular.module('ui.bootstrap.pagination', [])
7373
};
7474
}])
7575

76-
.constant('paginationConfig', {
76+
.constant('uibPaginationConfig', {
7777
itemsPerPage: 10,
7878
boundaryLinks: false,
7979
directionLinks: true,
@@ -84,7 +84,7 @@ angular.module('ui.bootstrap.pagination', [])
8484
rotate: true
8585
})
8686

87-
.directive('pagination', ['$parse', 'paginationConfig', function($parse, paginationConfig) {
87+
.directive('uibPagination', ['$parse', 'uibPaginationConfig', function($parse, paginationConfig) {
8888
return {
8989
restrict: 'EA',
9090
scope: {
@@ -95,8 +95,8 @@ angular.module('ui.bootstrap.pagination', [])
9595
lastText: '@',
9696
ngDisabled:'='
9797
},
98-
require: ['pagination', '?ngModel'],
99-
controller: 'PaginationController',
98+
require: ['uibPagination', '?ngModel'],
99+
controller: 'UibPaginationController',
100100
controllerAs: 'pagination',
101101
templateUrl: function(element, attrs) {
102102
return attrs.templateUrl || 'template/pagination/pagination.html';
@@ -194,14 +194,170 @@ angular.module('ui.bootstrap.pagination', [])
194194
};
195195
}])
196196

197-
.constant('pagerConfig', {
197+
.constant('uibPagerConfig', {
198198
itemsPerPage: 10,
199199
previousText: '« Previous',
200200
nextText: 'Next »',
201201
align: true
202202
})
203203

204-
.directive('pager', ['pagerConfig', function(pagerConfig) {
204+
.directive('uibPager', ['uibPagerConfig', function(pagerConfig) {
205+
return {
206+
restrict: 'EA',
207+
scope: {
208+
totalItems: '=',
209+
previousText: '@',
210+
nextText: '@',
211+
ngDisabled: '='
212+
},
213+
require: ['uibPager', '?ngModel'],
214+
controller: 'UibPaginationController',
215+
controllerAs: 'pagination',
216+
templateUrl: function(element, attrs) {
217+
return attrs.templateUrl || 'template/pagination/pager.html';
218+
},
219+
replace: true,
220+
link: function(scope, element, attrs, ctrls) {
221+
var paginationCtrl = ctrls[0], ngModelCtrl = ctrls[1];
222+
223+
if (!ngModelCtrl) {
224+
return; // do nothing if no ng-model
225+
}
226+
227+
scope.align = angular.isDefined(attrs.align) ? scope.$parent.$eval(attrs.align) : pagerConfig.align;
228+
paginationCtrl.init(ngModelCtrl, pagerConfig);
229+
}
230+
};
231+
}]);
232+
233+
/* Deprecated Pagination Below */
234+
235+
angular.module('ui.bootstrap.pagination')
236+
.value('$paginationSuppressWarning', false)
237+
.controller('PaginationController', ['$scope', '$attrs', '$parse', '$controller', '$element', '$log', '$paginationSuppressWarning', function($scope, $attrs, $parse, $controller, $element, $log, $paginationSuppressWarning) {
238+
if (!$paginationSuppressWarning) {
239+
$log.warn('PaginationController is now deprecated. Use UibPaginationController instead.');
240+
}
241+
return $controller('UibPaginationController', {
242+
$scope: $scope,
243+
$element: $element,
244+
$attrs: $attrs
245+
});
246+
}])
247+
.directive('pagination', ['$parse', 'uibPaginationConfig', '$log', '$paginationSuppressWarning', function($parse, paginationConfig, $log, $paginationSuppressWarning) {
248+
return {
249+
restrict: 'EA',
250+
scope: {
251+
totalItems: '=',
252+
firstText: '@',
253+
previousText: '@',
254+
nextText: '@',
255+
lastText: '@',
256+
ngDisabled:'='
257+
},
258+
require: ['pagination', '?ngModel'],
259+
controller: 'PaginationController',
260+
controllerAs: 'pagination',
261+
templateUrl: function(element, attrs) {
262+
return attrs.templateUrl || 'template/pagination/pagination.html';
263+
},
264+
replace: true,
265+
link: function(scope, element, attrs, ctrls) {
266+
if (!$paginationSuppressWarning) {
267+
$log.warn('pagination is now deprecated. Use uib-pagination instead.');
268+
}
269+
var paginationCtrl = ctrls[0], ngModelCtrl = ctrls[1];
270+
271+
if (!ngModelCtrl) {
272+
return; // do nothing if no ng-model
273+
}
274+
275+
// Setup configuration parameters
276+
var maxSize = angular.isDefined(attrs.maxSize) ? scope.$parent.$eval(attrs.maxSize) : paginationConfig.maxSize,
277+
rotate = angular.isDefined(attrs.rotate) ? scope.$parent.$eval(attrs.rotate) : paginationConfig.rotate;
278+
scope.boundaryLinks = angular.isDefined(attrs.boundaryLinks) ? scope.$parent.$eval(attrs.boundaryLinks) : paginationConfig.boundaryLinks;
279+
scope.directionLinks = angular.isDefined(attrs.directionLinks) ? scope.$parent.$eval(attrs.directionLinks) : paginationConfig.directionLinks;
280+
281+
paginationCtrl.init(ngModelCtrl, paginationConfig);
282+
283+
if (attrs.maxSize) {
284+
scope.$parent.$watch($parse(attrs.maxSize), function(value) {
285+
maxSize = parseInt(value, 10);
286+
paginationCtrl.render();
287+
});
288+
}
289+
290+
// Create page object used in template
291+
function makePage(number, text, isActive) {
292+
return {
293+
number: number,
294+
text: text,
295+
active: isActive
296+
};
297+
}
298+
299+
function getPages(currentPage, totalPages) {
300+
var pages = [];
301+
302+
// Default page limits
303+
var startPage = 1, endPage = totalPages;
304+
var isMaxSized = angular.isDefined(maxSize) && maxSize < totalPages;
305+
306+
// recompute if maxSize
307+
if (isMaxSized) {
308+
if (rotate) {
309+
// Current page is displayed in the middle of the visible ones
310+
startPage = Math.max(currentPage - Math.floor(maxSize/2), 1);
311+
endPage = startPage + maxSize - 1;
312+
313+
// Adjust if limit is exceeded
314+
if (endPage > totalPages) {
315+
endPage = totalPages;
316+
startPage = endPage - maxSize + 1;
317+
}
318+
} else {
319+
// Visible pages are paginated with maxSize
320+
startPage = ((Math.ceil(currentPage / maxSize) - 1) * maxSize) + 1;
321+
322+
// Adjust last page if limit is exceeded
323+
endPage = Math.min(startPage + maxSize - 1, totalPages);
324+
}
325+
}
326+
327+
// Add page number links
328+
for (var number = startPage; number <= endPage; number++) {
329+
var page = makePage(number, number, number === currentPage);
330+
pages.push(page);
331+
}
332+
333+
// Add links to move between page sets
334+
if (isMaxSized && ! rotate) {
335+
if (startPage > 1) {
336+
var previousPageSet = makePage(startPage - 1, '...', false);
337+
pages.unshift(previousPageSet);
338+
}
339+
340+
if (endPage < totalPages) {
341+
var nextPageSet = makePage(endPage + 1, '...', false);
342+
pages.push(nextPageSet);
343+
}
344+
}
345+
346+
return pages;
347+
}
348+
349+
var originalRender = paginationCtrl.render;
350+
paginationCtrl.render = function() {
351+
originalRender();
352+
if (scope.page > 0 && scope.page <= scope.totalPages) {
353+
scope.pages = getPages(scope.page, scope.totalPages);
354+
}
355+
};
356+
}
357+
};
358+
}])
359+
360+
.directive('pager', ['uibPagerConfig', '$log', '$paginationSuppressWarning', function(pagerConfig, $log, $paginationSuppressWarning) {
205361
return {
206362
restrict: 'EA',
207363
scope: {
@@ -218,6 +374,9 @@ angular.module('ui.bootstrap.pagination', [])
218374
},
219375
replace: true,
220376
link: function(scope, element, attrs, ctrls) {
377+
if (!$paginationSuppressWarning) {
378+
$log.warn('pager is now deprecated. Use uib-pager instead.');
379+
}
221380
var paginationCtrl = ctrls[0], ngModelCtrl = ctrls[1];
222381

223382
if (!ngModelCtrl) {

0 commit comments

Comments
 (0)