diff --git a/dist/ng-lazy-render.js b/dist/ng-lazy-render.js index 47bf0cd..ea2451a 100644 --- a/dist/ng-lazy-render.js +++ b/dist/ng-lazy-render.js @@ -22,11 +22,9 @@ angular.module('ngLazyRender').directive('lazyModule', [ '$compile', '$parse', '$q', - '$rootScope', '$templateCache', - '$timeout', 'inViewDirective', - function ($animate, $compile, $parse, $q, $rootScope, $templateCache, $timeout, inViewDirective) { + function ($animate, $compile, $parse, $q, $templateCache, inViewDirective) { 'use strict'; return { @@ -44,7 +42,7 @@ angular.module('ngLazyRender').directive('lazyModule', [ } var el = angular.element($templateCache.get($attr.lazyModule)); - var isolateScope = $rootScope.$new(); + var isolateScope = $scope.$new(true); // Callback for inViewDirective to be called when the module becomes visible. // This will destroy the scope of the placeholder with inView and replace it with @@ -106,10 +104,9 @@ angular.module('ngLazyRender').directive('lazyRepeater', [ '$animate', '$compile', '$parse', - '$rootScope', '$templateCache', '$timeout', - function ($animate, $compile, $parse, $rootScope, $templateCache, $timeout) { + function ($animate, $compile, $parse, $templateCache, $timeout) { 'use strict'; return { @@ -130,6 +127,9 @@ angular.module('ngLazyRender').directive('lazyRepeater', [ return function ($scope, el, attrs) { var limit = attrs.lazyRepeater; + var delay = parseInt(attrs.lazyDelay); + var waiting = false; + var placeholderVisible = false; function getBufferLength() { @@ -141,7 +141,7 @@ angular.module('ngLazyRender').directive('lazyRepeater', [ var placeholderEl = angular.element('
' + placeholder + '
'); var isolateScope = $scope.$new(true); - isolateScope.increaseLimit = function () { + function increaseLimit() { var bufferLength = getBufferLength(); limit *= 2; @@ -152,16 +152,29 @@ angular.module('ngLazyRender').directive('lazyRepeater', [ placeholderVisible = false; } - // trigger in-view for other listeners - $timeout(function () { - angular.element(window).triggerHandler('checkInView'); - }, 0); + waiting = false; + } + + isolateScope.increaseLimit = function () { + if (waiting) { + return; + } + waiting = true; + + if (delay) { + $timeout(increaseLimit, delay); + } else { + increaseLimit(); + } }; var elSiblings = el.parent().children(); var elLastSibling = elSiblings.length === 0 ? el : elSiblings.eq(-1); - $animate.enter(placeholderEl, el.parent(), elLastSibling); + $animate.enter(placeholderEl, el.parent(), elLastSibling).then(function () { + // trigger in-view for other listeners + angular.element(window).triggerHandler('checkInView'); + }); $compile(placeholderEl)(isolateScope); placeholderVisible = true; }