(p=>{function t(a){return{restrict:"A",scope:{containerSelector:"@c8yScrollLoadContainer",onAppear:"&c8yScrollLoadOnAppear",onDisappear:"&c8yScrollLoadOnDisappear"},link:function(t,o){var n,r,e=!1,i=_.throttle(function(){r=function(t){var o=1<arguments.length&&void 0!==arguments[1]?arguments[1]:1,n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:1,r=p(window),e={top:r.scrollTop(),left:r.scrollLeft()},r=(e.right=e.left+r.width(),e.bottom=e.top+r.height(),t.outerHeight()),i=t.outerWidth();return!(!i||!r)&&((t=t.offset()).right=t.left+i,t.bottom=t.top+r,!(e.right<t.left||e.left>t.right||e.bottom<t.top||e.top>t.bottom))&&(l=Math.min(1,(t.bottom-e.top)/r),r=Math.min(1,(e.bottom-t.top)/r),c=Math.min(1,(t.right-e.left)/i),e=Math.min(1,(e.right-t.left)/i),o<=c*e)&&n<=l*r;var l,c}(p(o),.5,.5),!e&&r&&c(t.onAppear);e&&!r&&c(t.onDisappear);e=r},500,{leading:!1,trailing:!0});function l(){n&&(n.unbind("scroll",i),p(window).unbind("scroll",i))}function c(t){a(t,100)}t.$watch("containerSelector",function(){l(),(n=p(o).closest(t.containerSelector)).bind("scroll",i),p(window).bind("scroll",i),c(i)}),t.$on("c8yScrollLoad::refresh",i),t.$on("$destroy",l)}}}t.$inject=["$timeout"],angular.module("c8y.ui").directive("c8yScrollLoad",t)})(jQuery);