-
Notifications
You must be signed in to change notification settings - Fork 0
/
infinite-scroller-directive.js
36 lines (34 loc) · 1.2 KB
/
infinite-scroller-directive.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
angular.module('customDirectives').directive("infiniteScroller",function(){
return {
restrict:"E",
scope: {
ngLoadMore:"&",
minRepeatDelay:"&",
ngCurrentCount: "&",
ngCurrentLimit: "&",
ngTotalItems: "&"
},
template:``,
link: function($scope, $element, $attrs, $ngModelCtrl){
var parent = $element.parent();
var parentRaw = parent[0]
parent.on("scroll", handleScroll);
$scope.$on('$destroy',() => {
parent.off('scroll',handleScroll);
});
if($scope.minRepeatDelay == undefined){
$scope.minRepeatDelay = 1000;
}
var ignore = false
function handleScroll(event){
if(parentRaw.scrollHeight - parentRaw.clientHeight - parentRaw.scrollTop < 1){
if($scope.ngCurrentCount() >= $scope.ngCurrentLimit() && $scope.ngCurrentCount() <= $scope.ngTotalItems()){
$scope.$apply(function(){
$scope.ngLoadMore();
})
}
}
}
}
}
});