Skip to content

Commit

Permalink
Add dists
Browse files Browse the repository at this point in the history
  • Loading branch information
onemanclapping committed Oct 25, 2016
1 parent 6f322bf commit 412633e
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions dist/ng-lazy-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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() {
Expand All @@ -141,7 +141,7 @@ angular.module('ngLazyRender').directive('lazyRepeater', [
var placeholderEl = angular.element('<div in-view="$inview && increaseLimit()">' + placeholder + '</div>');
var isolateScope = $scope.$new(true);

isolateScope.increaseLimit = function () {
function increaseLimit() {
var bufferLength = getBufferLength();

limit *= 2;
Expand All @@ -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;
}
Expand Down

0 comments on commit 412633e

Please sign in to comment.