@@ -86,15 +86,10 @@ function($parse, $timeout, $ionicScrollDelegate, $controller, $ionicBind) {
86
86
87
87
$ionicBind ( $scope , $attr , {
88
88
//Use $ to stop onRefresh from recursively calling itself
89
- //DEPRECATED, use <ion-infinite-scroll on-infinite-scroll="">
90
89
$onRefresh : '&onRefresh' ,
91
90
$onRefreshOpening : '&onRefreshOpening' ,
92
91
$onScroll : '&onScroll' ,
93
92
$onScrollComplete : '&onScrollComplete' ,
94
- //DEPRECATED, use <ion-infinite-scroll on-infinite-scroll="">
95
- $onInfiniteScroll : '&onInfiniteScroll' ,
96
- refreshComplete : '=' ,
97
- infiniteScrollDistance : '@' ,
98
93
hasBouncing : '@' ,
99
94
scroll : '@' ,
100
95
padding : '@' ,
@@ -154,8 +149,6 @@ function($parse, $timeout, $ionicScrollDelegate, $controller, $ionicBind) {
154
149
if ( attr . refreshComplete ) {
155
150
$scope . refreshComplete = function ( ) {
156
151
if ( $scope . scrollView ) {
157
- scrollCtrl . refresher && scrollCtrl . refresher . classList . remove ( 'active' ) ;
158
- scrollView . finishPullToRefresh ( ) ;
159
152
$scope . $parent . $broadcast ( 'scroll.onRefreshComplete' ) ;
160
153
}
161
154
} ;
@@ -175,24 +168,99 @@ function($parse, $timeout, $ionicScrollDelegate, $controller, $ionicBind) {
175
168
} ;
176
169
} ] )
177
170
178
- . directive ( 'ionRefresher' , function ( ) {
171
+ /**
172
+ * @ngdoc directive
173
+ * @name ionRefresher
174
+ * @module ionic
175
+ * @restrict E
176
+ * @parent ionContent, ionScroll
177
+ * @description
178
+ * Allows you to add pull-to-refresh to a scrollView.
179
+ *
180
+ * Place it as the first child of your {@link ionic.directive:ionContent} or
181
+ * {@link ionic.directive:ionScroll} element.
182
+ *
183
+ * When refreshing is complete, $broadcast the 'scroll.refreshComplete' event
184
+ * from your controller.
185
+ *
186
+ * @param {expression= } on-refresh Called when the user pulls down enough and lets go
187
+ * of the refresher.
188
+ * @param {expression= } on-pulling Called when the user starts to pull down
189
+ * on the refresher.
190
+ * @param {string= } pulling-icon The icon to display while the user is pulling down.
191
+ * Default: 'ion-arrow-down-c'.
192
+ * @param {string= } pulling-text The text to display while the user is pulling down.
193
+ * @param {string= } refreshing-icon The icon to display after user lets go of the
194
+ * refresher.
195
+ * @param {string= } refreshing-text The text to display after the user lets go of
196
+ * the refresher.
197
+ *
198
+ * @usage
199
+ * ```html
200
+ * <ion-content ng-controller="MyController">
201
+ * <ion-refresher
202
+ * pulling-text="Pull to refresh..."
203
+ * on-refresh="doRefresh()">
204
+ * </ion-refresher>
205
+ * <ion-list>
206
+ * <ion-item ng-repeat="item in items"></ion-item>
207
+ * </ion-list>
208
+ * </ion-content>
209
+ * ```
210
+ * ```js
211
+ * angular.module('testApp', ['ionic'])
212
+ * .controller('MyController', function($scope, $http) {
213
+ * $scope.items = [1,2,3];
214
+ * $scope.doRefresh = function() {
215
+ * $http.get('/new-items').success(function(newItems) {
216
+ * $scope.items = newItems;
217
+ * //Stop the ion-refresher from spinning
218
+ * $scope.$broadcast('scroll.refreshComplete');
219
+ * });
220
+ * };
221
+ * });
222
+ * ```
223
+ */
224
+ . directive ( 'ionRefresher' , [ '$ionicBind' , function ( $ionicBind ) {
179
225
return {
180
226
restrict : 'E' ,
181
227
replace : true ,
182
- require : [ '^?ionContent' , '^?ionList' ] ,
183
- template : '<div class="scroll-refresher"><div class="ionic-refresher-content"><i class="icon ion-arrow-down-c icon-pulling"></i><i class="icon ion-loading-d icon-refreshing"></i></div></div>' ,
184
- scope : true
185
- } ;
186
- } )
228
+ require : '^$ionicScroll' ,
229
+ template :
230
+ '<div class="scroll-refresher">' +
231
+ '<div class="ionic-refresher-content">' +
232
+ '<i class="icon {{pullingIcon}} icon-pulling"></i>' +
233
+ '<span class="icon-pulling" ng-bind-html="pullingText"></span>' +
234
+ '<i class="icon {{refreshingIcon}} icon-refreshing"></i>' +
235
+ '<span class="icon-refreshing" ng-bind-html="refreshingText"></span>' +
236
+ '</div>' +
237
+ '</div>' ,
238
+ compile : function ( $element , $attrs ) {
239
+ if ( angular . isUndefined ( $attrs . pullingIcon ) ) {
240
+ $attrs . $set ( 'pullingIcon' , 'ion-arrow-down-c' ) ;
241
+ }
242
+ if ( angular . isUndefined ( $attrs . refreshingIcon ) ) {
243
+ $attrs . $set ( 'refreshingIcon' , 'ion-loading-d' ) ;
244
+ }
245
+ return function ( $scope , $element , $attrs , scrollCtrl ) {
246
+ $ionicBind ( $scope , $attrs , {
247
+ pullingIcon : '@' ,
248
+ pullingText : '@' ,
249
+ refreshingIcon : '@' ,
250
+ refreshingText : '@' ,
251
+ $onRefresh : '&onRefresh' ,
252
+ $onRefreshOpening : '&onRefreshOpening'
253
+ } ) ;
187
254
188
- . directive ( 'ionScrollRefresher' , function ( ) {
189
- return {
190
- restrict : 'E' ,
191
- replace : true ,
192
- transclude : true ,
193
- template : '<div class="scroll-refresher"><div class="scroll-refresher-content" ng-transclude></div></div>'
255
+ scrollCtrl . setRefresher ( $scope , $element [ 0 ] ) ;
256
+ $scope . $on ( 'scroll.refreshComplete' , function ( ) {
257
+ $element [ 0 ] . classList . remove ( 'active' ) ;
258
+ scrollCtrl . scrollView . finishPullToRefresh ( ) ;
259
+ } ) ;
260
+ } ;
261
+ }
194
262
} ;
195
- } )
263
+ } ] )
196
264
197
265
/**
198
266
* @ngdoc directive
@@ -261,10 +329,7 @@ function($parse, $timeout, $ionicScrollDelegate, $controller, $ionicBind) {
261
329
this . isLoading = false ;
262
330
this . scrollView = null ; //given by link function
263
331
this . getMaxScroll = function ( ) {
264
- var dist = $attrs . distance ||
265
- //deprecated: allow infiniteScrollDistance from ionContent
266
- $scope . infiniteScrollDistance ||
267
- '1%' ;
332
+ var dist = $attrs . distance || '1%' ;
268
333
return dist . indexOf ( '%' ) > - 1 ?
269
334
this . scrollView . getScrollMax ( ) . top * ( 1 - parseInt ( dist , 10 ) / 100 ) :
270
335
this . scrollView . getScrollMax ( ) . top - parseInt ( dist , 10 ) ;
@@ -292,9 +357,7 @@ function($parse, $timeout, $ionicScrollDelegate, $controller, $ionicBind) {
292
357
scrollView . getValues ( ) . top >= infiniteScrollCtrl . getMaxScroll ( ) ) {
293
358
$element [ 0 ] . classList . add ( 'active' ) ;
294
359
infiniteScrollCtrl . isLoading = true ;
295
-
296
- //deprecated: allow $onInfiniteScroll from parent
297
- $scope . $apply ( $attrs . onInfinite || $scope . $onInfiniteScroll ) ;
360
+ $scope . $parent . $apply ( $attrs . onInfinite || '' ) ;
298
361
}
299
362
} ) ) ;
300
363
}
0 commit comments