/** * @ngdoc directive * @name ionRefresher * @module ionic * @restrict E * @parent ionic.directive:ionContent, ionic.directive:ionScroll * @description * Allows you to add pull-to-refresh to a scrollView. * * Place it as the first child of your {@link ionic.directive:ionContent} or * {@link ionic.directive:ionScroll} element. * * When refreshing is complete, $broadcast the 'scroll.refreshComplete' event * from your controller. * * @usage * * ```html * * * * * * * * ``` * ```js * angular.module('testApp', ['ionic']) * .controller('MyController', function($scope, $http) { * $scope.items = [1,2,3]; * $scope.doRefresh = function() { * $http.get('/new-items') * .success(function(newItems) { * $scope.items = newItems; * }) * .finally(function() { * // Stop the ion-refresher from spinning * $scope.$broadcast('scroll.refreshComplete'); * }); * }; * }); * ``` * * @param {expression=} on-refresh Called when the user pulls down enough and lets go * of the refresher. * @param {expression=} on-pulling Called when the user starts to pull down * on the refresher. * @param {expression=} on-pull-progress Repeatedly called as the user is pulling down * the refresher. The callback should have a `progress` argument which will be a number * from `0` and `1`. For example, if the user has pulled the refresher halfway * down, its progress would be `0.5`. * @param {string=} pulling-icon The icon to display while the user is pulling down. * Default: 'ion-android-arrow-down'. * @param {string=} pulling-text The text to display while the user is pulling down. * @param {string=} refreshing-icon The icon to display after user lets go of the * refresher. * @param {string=} refreshing-text The text to display after the user lets go of * the refresher. * @param {boolean=} disable-pulling-rotation Disables the rotation animation of the pulling * icon when it reaches its activated threshold. To be used with a custom `pulling-icon`. * */ IonicModule .directive('ionRefresher', ['$ionicBind', '$parse', function($ionicBind, $parse) { return { restrict: 'E', replace: true, require: '^$ionicScroll', template: '
' + '
' + '
' + '' + '
' + '
' + '
' + '' + '' + '
' + '
' + '
' + '
', link: function($scope, $element, $attrs, scrollCtrl) { if (angular.isUndefined($attrs.pullingIcon)) { $attrs.$set('pullingIcon', 'ion-android-arrow-down'); } $scope.showLoader = angular.isUndefined($attrs.refreshingIcon); $ionicBind($scope, $attrs, { pullingIcon: '@', pullingText: '@', refreshingIcon: '@', refreshingText: '@', loader: '@', disablePullingRotation: '@', $onRefresh: '&onRefresh', $onPulling: '&onPulling' }); if (isDefined($attrs.onPullProgress)) { var onPullProgressFn = $parse($attrs.onPullProgress); $scope.$onPullProgress = function(progress) { onPullProgressFn($scope, { progress: progress }); }; } scrollCtrl._setRefresher($scope, $element[0]); $scope.$on('scroll.refreshComplete', function() { $scope.$evalAsync(function() { scrollCtrl.scrollView.finishPullToRefresh(); }); }); } }; }]);