angular-inview.spec.js
function scrollTo(element, position, useTimeout) {
		if (!angular.isDefined(position)) {
			position = element;
			element = window;
		}
		if (!angular.isArray(position)) {
			position = [0, position];
		}
		// Prepare promise resolution
		var deferred = $q.defer(), timeout;
		var scrollOnceHandler = function () {
			var check = (element === window) ?
				[element.scrollX, element.scrollY] :
				[element.scrollLeft, element.scrollTop];
			if (check[0] != position[0] || check[1] != position[1]) {
				return;
			}
			if (timeout) {
				clearTimeout(timeout);
				timeout = null;
			}
			angular.element(element).off('scroll', scrollOnceHandler);
			deferred.resolve();
			$rootScope.$digest();
		};
		angular.element(element).on('scroll', scrollOnceHandler);
		// Actual scrolling
		if (element === window) {
			element.scrollTo.apply(element, position);
		}
		else {
			element.scrollLeft = position[0];
			element.scrollTop = position[1];
		}
		// Backup resolver
		if (useTimeout) timeout = setTimeout(function () {
			angular.element(element).off('scroll', scrollOnceHandler);
			var check = (element === window) ?
				[element.scrollX, element.scrollY] :
				[element.scrollLeft, element.scrollTop];
			if (check[0] != position[0] || check[1] != position[1]) {
				deferred.reject();
			}
			else {
				deferred.resolve();
			}
			$rootScope.$digest();
		}, 100);
		return deferred.promise;
	}
function scrollTo(element, position, useTimeout) {
		if (!angular.isDefined(position)) {
			position = element;
			element = window;
		}
		if (!angular.isArray(position)) {
			position = [0, position];
		}
		// Prepare promise resolution
		var deferred = $q.defer(), timeout;
		var scrollOnceHandler = function () {
			var check = (element === window) ?
				[element.scrollX, element.scrollY] :
				[element.scrollLeft, element.scrollTop];
			if (check[0] != position[0] || check[1] != position[1]) {
				return;
			}
			if (timeout) {
				clearTimeout(timeout);
				timeout = null;
			}
			angular.element(element).off('scroll', scrollOnceHandler);
			deferred.resolve();
			$rootScope.$digest();
		};
		angular.element(element).on('scroll', scrollOnceHandler);
		// Actual scrolling
		if (element === window) {
			element.scrollTo.apply(element, position);
		}
		else {
			element.scrollLeft = position[0];
			element.scrollTop = position[1];
		}
		// Backup resolver
		if (useTimeout) timeout = setTimeout(function () {
			angular.element(element).off('scroll', scrollOnceHandler);
			var check = (element === window) ?
				[element.scrollX, element.scrollY] :
				[element.scrollLeft, element.scrollTop];
			if (check[0] != position[0] || check[1] != position[1]) {
				deferred.reject();
			}
			else {
				deferred.resolve();
			}
			$rootScope.$digest();
		}, 100);
		return deferred.promise;
	}
function scrollTo ( element , position , useTimeout ) { if ( ! angular . isDefined ( position ) ) { position = element ; element = window ; } if ( ! angular . isArray ( position ) ) { position = [ 0 , position ] ; } // Prepare promise resolution var deferred = $q . defer ( ) , timeout ; var scrollOnceHandler = function ( ) { var check = ( element === window ) ? [ element . scrollX , element . scrollY ] : [ element . scrollLeft , element . scrollTop ] ; if ( check [ 0 ] != position [ 0 ] || check [ 1 ] != position [ 1 ] ) { return ; } if ( timeout ) { clearTimeout ( timeout ) ; timeout = null ; } angular . element ( element ) . off ( 'scroll' , scrollOnceHandler ) ; deferred . resolve ( ) ; $rootScope . $digest ( ) ; } ; angular . element ( element ) . on ( 'scroll' , scrollOnceHandler ) ; // Actual scrolling if ( element === window ) { element . scrollTo . apply ( element , position ) ; } else { element . scrollLeft = position [ 0 ] ; element . scrollTop = position [ 1 ] ; } // Backup resolver if ( useTimeout ) timeout = setTimeout ( function ( ) { angular . element ( element ) . off ( 'scroll' , scrollOnceHandler ) ; var check = ( element === window ) ? [ element . scrollX , element . scrollY ] : [ element . scrollLeft , element . scrollTop ] ; if ( check [ 0 ] != position [ 0 ] || check [ 1 ] != position [ 1 ] ) { deferred . reject ( ) ; } else { deferred . resolve ( ) ; } $rootScope . $digest ( ) ; } , 100 ) ; return deferred . promise ; }
Scrolls the element to the given x, y position and waits a bit before resolving the returned promise.
Scrolls the element to the given x y position and waits a bit before resolving the returned promise .