1 /* ng-infinite-scroll - v1.0.0 - 2013-02-23 */
4 mod = angular.module('infinite-scroll', []);
6 mod.directive('infiniteScroll', [
7 '$rootScope', '$window', '$timeout', function($rootScope, $window, $timeout) {
9 link: function(scope, elem, attrs) {
10 var checkWhenEnabled, handler, scrollDistance, scrollEnabled;
11 $window = angular.element($window);
13 if (attrs.infiniteScrollDistance != null) {
14 scope.$watch(attrs.infiniteScrollDistance, function(value) {
15 return scrollDistance = parseInt(value, 10);
19 checkWhenEnabled = false;
20 if (attrs.infiniteScrollDisabled != null) {
21 scope.$watch(attrs.infiniteScrollDisabled, function(value) {
22 scrollEnabled = !value;
23 if (scrollEnabled && checkWhenEnabled) {
24 checkWhenEnabled = false;
29 handler = function() {
30 var elementBottom, remaining, shouldScroll, windowBottom;
31 windowBottom = $window.height() + $window.scrollTop();
32 elementBottom = elem.offset().top + elem.height();
33 remaining = elementBottom - windowBottom;
34 shouldScroll = remaining <= $window.height() * scrollDistance;
35 if (shouldScroll && scrollEnabled) {
36 if ($rootScope.$$phase) {
37 return scope.$eval(attrs.infiniteScroll);
39 return scope.$apply(attrs.infiniteScroll);
41 } else if (shouldScroll) {
42 return checkWhenEnabled = true;
45 $window.on('scroll', handler);
46 scope.$on('$destroy', function() {
47 return $window.off('scroll', handler);
49 return $timeout((function() {
50 if (attrs.infiniteScrollImmediateCheck) {
51 if (scope.$eval(attrs.infiniteScrollImmediateCheck)) {