1
1
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 ) {
3
3
var self = this ,
4
4
ngModelCtrl = { $setViewValue : angular . noop } , // nullModelCtrl
5
5
setNumPages = $attrs . numPages ? $parse ( $attrs . numPages ) . assign : angular . noop ;
@@ -73,7 +73,7 @@ angular.module('ui.bootstrap.pagination', [])
73
73
} ;
74
74
} ] )
75
75
76
- . constant ( 'paginationConfig ' , {
76
+ . constant ( 'uibPaginationConfig ' , {
77
77
itemsPerPage : 10 ,
78
78
boundaryLinks : false ,
79
79
directionLinks : true ,
@@ -84,7 +84,7 @@ angular.module('ui.bootstrap.pagination', [])
84
84
rotate : true
85
85
} )
86
86
87
- . directive ( 'pagination ' , [ '$parse' , 'paginationConfig ' , function ( $parse , paginationConfig ) {
87
+ . directive ( 'uibPagination ' , [ '$parse' , 'uibPaginationConfig ' , function ( $parse , paginationConfig ) {
88
88
return {
89
89
restrict : 'EA' ,
90
90
scope : {
@@ -95,8 +95,8 @@ angular.module('ui.bootstrap.pagination', [])
95
95
lastText : '@' ,
96
96
ngDisabled :'='
97
97
} ,
98
- require : [ 'pagination ' , '?ngModel' ] ,
99
- controller : 'PaginationController ' ,
98
+ require : [ 'uibPagination ' , '?ngModel' ] ,
99
+ controller : 'UibPaginationController ' ,
100
100
controllerAs : 'pagination' ,
101
101
templateUrl : function ( element , attrs ) {
102
102
return attrs . templateUrl || 'template/pagination/pagination.html' ;
@@ -194,14 +194,170 @@ angular.module('ui.bootstrap.pagination', [])
194
194
} ;
195
195
} ] )
196
196
197
- . constant ( 'pagerConfig ' , {
197
+ . constant ( 'uibPagerConfig ' , {
198
198
itemsPerPage : 10 ,
199
199
previousText : '« Previous' ,
200
200
nextText : 'Next »' ,
201
201
align : true
202
202
} )
203
203
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 ) {
205
361
return {
206
362
restrict : 'EA' ,
207
363
scope : {
@@ -218,6 +374,9 @@ angular.module('ui.bootstrap.pagination', [])
218
374
} ,
219
375
replace : true ,
220
376
link : function ( scope , element , attrs , ctrls ) {
377
+ if ( ! $paginationSuppressWarning ) {
378
+ $log . warn ( 'pager is now deprecated. Use uib-pager instead.' ) ;
379
+ }
221
380
var paginationCtrl = ctrls [ 0 ] , ngModelCtrl = ctrls [ 1 ] ;
222
381
223
382
if ( ! ngModelCtrl ) {
0 commit comments