1
1
angular . module ( 'ui.bootstrap.pagination' , [ ] )
2
2
3
- . controller ( 'PaginationController' , [ '$scope' , function ( scope ) {
3
+ . controller ( 'PaginationController' , [ '$scope' , function ( $ scope) {
4
4
5
- scope . noPrevious = function ( ) {
6
- return scope . currentPage === 1 ;
5
+ this . currentPage = 1 ;
6
+
7
+ this . noPrevious = function ( ) {
8
+ return this . currentPage === 1 ;
7
9
} ;
8
- scope . noNext = function ( ) {
9
- return scope . currentPage === scope . numPages ;
10
+ this . noNext = function ( ) {
11
+ return this . currentPage === $ scope. numPages ;
10
12
} ;
11
13
12
- scope . isActive = function ( page ) {
13
- return scope . currentPage === page ;
14
+ this . isActive = function ( page ) {
15
+ return this . currentPage === page ;
14
16
} ;
15
17
16
- scope . selectPage = function ( page ) {
17
- if ( ! scope . isActive ( page ) && page > 0 && page <= scope . numPages ) {
18
- scope . currentPage = page ;
19
- scope . onSelectPage ( { page : page } ) ;
18
+ var self = this ;
19
+ $scope . selectPage = function ( page ) {
20
+ if ( ! self . isActive ( page ) && page > 0 && page <= $scope . numPages ) {
21
+ $scope . currentPage = page ;
22
+ $scope . onSelectPage ( { page : page } ) ;
20
23
}
21
24
} ;
22
25
} ] )
@@ -43,7 +46,7 @@ angular.module('ui.bootstrap.pagination', [])
43
46
controller : 'PaginationController' ,
44
47
templateUrl : 'template/pagination/pagination.html' ,
45
48
replace : true ,
46
- link : function ( scope , element , attrs ) {
49
+ link : function ( scope , element , attrs , paginationCtrl ) {
47
50
48
51
// Setup configuration parameters
49
52
var boundaryLinks = angular . isDefined ( attrs . boundaryLinks ) ? scope . $eval ( attrs . boundaryLinks ) : paginationConfig . boundaryLinks ;
@@ -66,7 +69,8 @@ angular.module('ui.bootstrap.pagination', [])
66
69
67
70
scope . $watch ( 'numPages + currentPage + maxSize' , function ( ) {
68
71
scope . pages = [ ] ;
69
-
72
+ paginationCtrl . currentPage = parseInt ( scope . currentPage , 10 ) ;
73
+
70
74
// Default page limits
71
75
var startPage = 1 , endPage = scope . numPages ;
72
76
var isMaxSized = ( angular . isDefined ( scope . maxSize ) && scope . maxSize < scope . numPages ) ;
@@ -75,7 +79,7 @@ angular.module('ui.bootstrap.pagination', [])
75
79
if ( isMaxSized ) {
76
80
if ( rotate ) {
77
81
// Current page is displayed in the middle of the visible ones
78
- startPage = Math . max ( scope . currentPage - Math . floor ( scope . maxSize / 2 ) , 1 ) ;
82
+ startPage = Math . max ( paginationCtrl . currentPage - Math . floor ( scope . maxSize / 2 ) , 1 ) ;
79
83
endPage = startPage + scope . maxSize - 1 ;
80
84
81
85
// Adjust if limit is exceeded
@@ -85,7 +89,7 @@ angular.module('ui.bootstrap.pagination', [])
85
89
}
86
90
} else {
87
91
// Visible pages are paginated with maxSize
88
- startPage = ( ( Math . ceil ( scope . currentPage / scope . maxSize ) - 1 ) * scope . maxSize ) + 1 ;
92
+ startPage = ( ( Math . ceil ( paginationCtrl . currentPage / scope . maxSize ) - 1 ) * scope . maxSize ) + 1 ;
89
93
90
94
// Adjust last page if limit is exceeded
91
95
endPage = Math . min ( startPage + scope . maxSize - 1 , scope . numPages ) ;
@@ -94,7 +98,7 @@ angular.module('ui.bootstrap.pagination', [])
94
98
95
99
// Add page number links
96
100
for ( var number = startPage ; number <= endPage ; number ++ ) {
97
- var page = makePage ( number , number , scope . isActive ( number ) , false ) ;
101
+ var page = makePage ( number , number , paginationCtrl . isActive ( number ) , false ) ;
98
102
scope . pages . push ( page ) ;
99
103
}
100
104
@@ -113,23 +117,23 @@ angular.module('ui.bootstrap.pagination', [])
113
117
114
118
// Add previous & next links
115
119
if ( directionLinks ) {
116
- var previousPage = makePage ( scope . currentPage - 1 , previousText , false , scope . noPrevious ( ) ) ;
120
+ var previousPage = makePage ( paginationCtrl . currentPage - 1 , previousText , false , paginationCtrl . noPrevious ( ) ) ;
117
121
scope . pages . unshift ( previousPage ) ;
118
122
119
- var nextPage = makePage ( scope . currentPage + 1 , nextText , false , scope . noNext ( ) ) ;
123
+ var nextPage = makePage ( paginationCtrl . currentPage + 1 , nextText , false , paginationCtrl . noNext ( ) ) ;
120
124
scope . pages . push ( nextPage ) ;
121
125
}
122
126
123
127
// Add first & last links
124
128
if ( boundaryLinks ) {
125
- var firstPage = makePage ( 1 , firstText , false , scope . noPrevious ( ) ) ;
129
+ var firstPage = makePage ( 1 , firstText , false , paginationCtrl . noPrevious ( ) ) ;
126
130
scope . pages . unshift ( firstPage ) ;
127
131
128
- var lastPage = makePage ( scope . numPages , lastText , false , scope . noNext ( ) ) ;
132
+ var lastPage = makePage ( scope . numPages , lastText , false , paginationCtrl . noNext ( ) ) ;
129
133
scope . pages . push ( lastPage ) ;
130
134
}
131
135
132
- if ( scope . currentPage > scope . numPages ) {
136
+ if ( paginationCtrl . currentPage > scope . numPages ) {
133
137
scope . selectPage ( scope . numPages ) ;
134
138
}
135
139
} ) ;
@@ -174,15 +178,16 @@ angular.module('ui.bootstrap.pagination', [])
174
178
175
179
scope . $watch ( 'numPages + currentPage' , function ( ) {
176
180
scope . pages = [ ] ;
181
+ paginationCtrl . currentPage = parseInt ( scope . currentPage , 10 ) ;
177
182
178
183
// Add previous & next links
179
- var previousPage = makePage ( scope . currentPage - 1 , previousText , scope . noPrevious ( ) , true , false ) ;
184
+ var previousPage = makePage ( paginationCtrl . currentPage - 1 , previousText , paginationCtrl . noPrevious ( ) , true , false ) ;
180
185
scope . pages . unshift ( previousPage ) ;
181
186
182
- var nextPage = makePage ( scope . currentPage + 1 , nextText , scope . noNext ( ) , false , true ) ;
187
+ var nextPage = makePage ( paginationCtrl . currentPage + 1 , nextText , paginationCtrl . noNext ( ) , false , true ) ;
183
188
scope . pages . push ( nextPage ) ;
184
189
185
- if ( scope . currentPage > scope . numPages ) {
190
+ if ( paginationCtrl . currentPage > scope . numPages ) {
186
191
scope . selectPage ( scope . numPages ) ;
187
192
}
188
193
} ) ;
0 commit comments