refactor(scroll): make refresher be detected after timeout

This commit is contained in:
Andy Joslin
2014-02-07 12:07:41 -05:00
parent 0facb120c7
commit c41e5371e7
2 changed files with 22 additions and 10 deletions

View File

@@ -10,8 +10,9 @@ angular.module('ionic.ui.scroll')
scrollViewOptions.bouncing :
!ionic.Platform.isAndroid();
var self = this;
var element = this.element = scrollViewOptions.el;
var refresher = this.refresher = element.querySelector('.scroll-refresher');
var scrollView = this.scrollView = new ionic.views.Scroll(scrollViewOptions);
this.$element = angular.element(element);
@@ -23,16 +24,18 @@ angular.module('ionic.ui.scroll')
$timeout(function() {
scrollView.run();
self.refresher = element.querySelector('.scroll-refresher');
// Activate pull-to-refresh
if(refresher) {
var refresherHeight = refresher.clientHeight || 0;
if(self.refresher) {
var refresherHeight = self.refresher.clientHeight || 0;
scrollView.activatePullToRefresh(refresherHeight, function() {
refresher.classList.add('active');
self.refresher.classList.add('active');
}, function() {
refresher.classList.remove('refreshing');
refresher.classList.remove('active');
self.refresher.classList.remove('refreshing');
self.refresher.classList.remove('active');
}, function() {
refresher.classList.add('refreshing');
self.refresher.classList.add('refreshing');
$scope.onRefresh && $scope.onRefresh();
$scope.$parent.$broadcast('scroll.onRefresh');
});