feat(delegateService): create filterFn to find active

This commit is contained in:
Adam Bradley
2014-11-18 08:46:46 -06:00
parent 3615656586
commit 6276506d4f
9 changed files with 140 additions and 79 deletions

View File

@@ -9,36 +9,37 @@ IonicModule
'$timeout',
'$window',
'$location',
'$rootScope',
'$document',
'$ionicScrollDelegate',
function($scope, scrollViewOptions, $timeout, $window, $location, $rootScope, $document, $ionicScrollDelegate) {
function($scope, scrollViewOptions, $timeout, $window, $location, $document, $ionicScrollDelegate) {
var self = this;
// for testing
this.__timeout = $timeout;
self.__timeout = $timeout;
this._scrollViewOptions = scrollViewOptions; //for testing
self._scrollViewOptions = scrollViewOptions; //for testing
var element = this.element = scrollViewOptions.el;
var $element = this.$element = jqLite(element);
var scrollView = this.scrollView = new ionic.views.Scroll(scrollViewOptions);
var element = self.element = scrollViewOptions.el;
var $element = self.$element = jqLite(element);
var scrollView = self.scrollView = new ionic.views.Scroll(scrollViewOptions);
//Attach self to element as a controller so other directives can require this controller
//through `require: '$ionicScroll'
//Also attach to parent so that sibling elements can require this
($element.parent().length ? $element.parent() : $element)
.data('$$ionicScrollController', this);
.data('$$ionicScrollController', self);
var deregisterInstance = $ionicScrollDelegate._registerInstance(
this, scrollViewOptions.delegateHandle
self, scrollViewOptions.delegateHandle, function() {
return !$scope.$$disconnected;
}
);
if (!angular.isDefined(scrollViewOptions.bouncing)) {
ionic.Platform.ready(function() {
scrollView.options.bouncing = true;
if(ionic.Platform.isAndroid()) {
if (ionic.Platform.isAndroid()) {
// No bouncing by default on Android
scrollView.options.bouncing = false;
// Faster scroll decel
@@ -60,7 +61,7 @@ function($scope, scrollViewOptions, $timeout, $window, $location, $rootScope, $d
});
};
$element.on('scroll', scrollFunc );
$element.on('scroll', scrollFunc);
$scope.$on('$destroy', function() {
deregisterInstance();
@@ -83,66 +84,66 @@ function($scope, scrollViewOptions, $timeout, $window, $location, $rootScope, $d
scrollView && scrollView.run && scrollView.run();
});
this.getScrollView = function() {
return this.scrollView;
self.getScrollView = function() {
return self.scrollView;
};
this.getScrollPosition = function() {
return this.scrollView.getValues();
self.getScrollPosition = function() {
return self.scrollView.getValues();
};
this.resize = function() {
self.resize = function() {
return $timeout(resize).then(function() {
$element && $element.triggerHandler('scroll.resize');
});
};
this.scrollTop = function(shouldAnimate) {
self.scrollTop = function(shouldAnimate) {
ionic.DomUtil.blurAll();
this.resize().then(function() {
self.resize().then(function() {
scrollView.scrollTo(0, 0, !!shouldAnimate);
});
};
this.scrollBottom = function(shouldAnimate) {
self.scrollBottom = function(shouldAnimate) {
ionic.DomUtil.blurAll();
this.resize().then(function() {
self.resize().then(function() {
var max = scrollView.getScrollMax();
scrollView.scrollTo(max.left, max.top, !!shouldAnimate);
});
};
this.scrollTo = function(left, top, shouldAnimate) {
self.scrollTo = function(left, top, shouldAnimate) {
ionic.DomUtil.blurAll();
this.resize().then(function() {
self.resize().then(function() {
scrollView.scrollTo(left, top, !!shouldAnimate);
});
};
this.zoomTo = function(zoom, shouldAnimate, originLeft, originTop) {
self.zoomTo = function(zoom, shouldAnimate, originLeft, originTop) {
ionic.DomUtil.blurAll();
this.resize().then(function() {
self.resize().then(function() {
scrollView.zoomTo(zoom, !!shouldAnimate, originLeft, originTop);
});
};
this.zoomBy = function(zoom, shouldAnimate, originLeft, originTop) {
self.zoomBy = function(zoom, shouldAnimate, originLeft, originTop) {
ionic.DomUtil.blurAll();
this.resize().then(function() {
self.resize().then(function() {
scrollView.zoomBy(zoom, !!shouldAnimate, originLeft, originTop);
});
};
this.scrollBy = function(left, top, shouldAnimate) {
self.scrollBy = function(left, top, shouldAnimate) {
ionic.DomUtil.blurAll();
this.resize().then(function() {
self.resize().then(function() {
scrollView.scrollBy(left, top, !!shouldAnimate);
});
};
this.anchorScroll = function(shouldAnimate) {
self.anchorScroll = function(shouldAnimate) {
ionic.DomUtil.blurAll();
this.resize().then(function() {
self.resize().then(function() {
var hash = $location.hash();
var elm = hash && $document[0].getElementById(hash);
if (!(hash && elm)) {
@@ -152,8 +153,8 @@ function($scope, scrollViewOptions, $timeout, $window, $location, $rootScope, $d
var curElm = elm;
var scrollLeft = 0, scrollTop = 0, levelsClimbed = 0;
do {
if(curElm !== null)scrollLeft += curElm.offsetLeft;
if(curElm !== null)scrollTop += curElm.offsetTop;
if (curElm !== null) scrollLeft += curElm.offsetLeft;
if (curElm !== null) scrollTop += curElm.offsetTop;
curElm = curElm.offsetParent;
levelsClimbed++;
} while (curElm.attributes != self.element.attributes && curElm.offsetParent);
@@ -165,8 +166,8 @@ function($scope, scrollViewOptions, $timeout, $window, $location, $rootScope, $d
/**
* @private
*/
this._setRefresher = function(refresherScope, refresherElement) {
var refresher = this.refresher = refresherElement;
self._setRefresher = function(refresherScope, refresherElement) {
var refresher = self.refresher = refresherElement;
var refresherHeight = self.refresher.clientHeight || 60;
scrollView.activatePullToRefresh(refresherHeight, function() {
// activateCallback
@@ -179,16 +180,15 @@ function($scope, scrollViewOptions, $timeout, $window, $location, $rootScope, $d
// startCallback
refresher.classList.add('refreshing');
refresherScope.$onRefresh();
},function(){
}, function() {
// showCallback
refresher.classList.remove('invisible');
},function(){
}, function() {
// hideCallback
refresher.classList.add('invisible');
},function(){
}, function() {
// tailCallback
refresher.classList.add('refreshing-tail');
});
};
}]);