diff --git a/build/ng-infinite-scroll.js b/build/ng-infinite-scroll.js index c2a1cfe..ff2b5da 100644 --- a/build/ng-infinite-scroll.js +++ b/build/ng-infinite-scroll.js @@ -1,4 +1,4 @@ -/* ng-infinite-scroll - v1.1.2 - 2014-08-08 */ +/* ng-infinite-scroll - v1.1.2 - 2014-09-24 */ var mod; mod = angular.module('infinite-scroll', []); @@ -16,10 +16,11 @@ mod.directive('infiniteScroll', [ infiniteScrollUseDocumentBottom: '=' }, link: function(scope, elem, attrs) { - var changeContainer, checkWhenEnabled, container, handleInfiniteScrollContainer, handleInfiniteScrollDisabled, handleInfiniteScrollDistance, handleInfiniteScrollUseDocumentBottom, handler, height, immediateCheck, offsetTop, pageYOffset, scrollDistance, scrollEnabled, throttle, useDocumentBottom, windowElement; + var changeContainer, checkWhenEnabled, container, handleInfiniteScrollContainer, handleInfiniteScrollDisabled, handleInfiniteScrollDistance, handleInfiniteScrollUseDocumentBottom, handler, height, immediateCheck, ngIs, offsetTop, pageYOffset, scrollDistance, throttle, useDocumentBottom, windowElement; windowElement = angular.element($window); + ngIs = this; scrollDistance = null; - scrollEnabled = null; + ngIs.scrollEnabled = null; checkWhenEnabled = null; container = null; immediateCheck = true; @@ -27,7 +28,7 @@ mod.directive('infiniteScroll', [ height = function(elem) { elem = elem[0] || elem; if (isNaN(elem.offsetHeight)) { - return height(elem.document.documentElement); + return elem.document.documentElement.clientHeight; } else { return elem.offsetHeight; } @@ -66,7 +67,7 @@ mod.directive('infiniteScroll', [ shouldScroll = remaining <= height(container) * scrollDistance + 1; if (shouldScroll) { checkWhenEnabled = true; - if (scrollEnabled) { + if (ngIs.scrollEnabled) { if (scope.$$phase || $rootScope.$$phase) { return scope.infiniteScroll(); } else { @@ -113,13 +114,13 @@ mod.directive('infiniteScroll', [ return container.off('scroll', handler); }); handleInfiniteScrollDistance = function(v) { - return scrollDistance = parseInt(v, 10) || 0; + return scrollDistance = parseFloat(v) || 0; }; scope.$watch('infiniteScrollDistance', handleInfiniteScrollDistance); handleInfiniteScrollDistance(scope.infiniteScrollDistance); handleInfiniteScrollDisabled = function(v) { - scrollEnabled = !v; - if (scrollEnabled && checkWhenEnabled) { + ngIs.scrollEnabled = !v; + if (ngIs.scrollEnabled && checkWhenEnabled) { checkWhenEnabled = false; return handler(); } diff --git a/build/ng-infinite-scroll.min.js b/build/ng-infinite-scroll.min.js index 147a6aa..d9be939 100644 --- a/build/ng-infinite-scroll.min.js +++ b/build/ng-infinite-scroll.min.js @@ -1,2 +1,2 @@ -/* ng-infinite-scroll - v1.1.2 - 2014-08-08 */ -var mod;mod=angular.module("infinite-scroll",[]),mod.value("THROTTLE_MILLISECONDS",null),mod.directive("infiniteScroll",["$rootScope","$window","$timeout","THROTTLE_MILLISECONDS",function(n,e,t,i){return{scope:{infiniteScroll:"&",infiniteScrollContainer:"=",infiniteScrollDistance:"=",infiniteScrollDisabled:"=",infiniteScrollUseDocumentBottom:"="},link:function(l,o,r){var c,u,a,f,m,d,s,S,v,g,w,D,$,p,h,T,C;return C=angular.element(e),$=null,p=null,u=null,a=null,g=!0,T=!1,v=function(n){return n=n[0]||n,isNaN(n.offsetHeight)?v(n.document.documentElement):n.offsetHeight},w=function(n){return n[0].getBoundingClientRect&&!n.css("none")?n[0].getBoundingClientRect().top+D(n):void 0},D=function(n){return n=n[0]||n,isNaN(window.pageYOffset)?n.document.documentElement.scrollTop:n.ownerDocument.defaultView.pageYOffset},S=function(){var e,t,i,r,c;return a===C?(e=v(a)+D(a[0].document.documentElement),i=w(o)+v(o)):(e=v(a),t=0,void 0!==w(a)&&(t=w(a)),i=w(o)-t+v(o)),T&&(i=v((o[0].ownerDocument||o[0].document).documentElement)),r=i-e,c=v(a)*$+1>=r,c?(u=!0,p?l.$$phase||n.$$phase?l.infiniteScroll():l.$apply(l.infiniteScroll):void 0):u=!1},h=function(n,e){var i,l,o;return o=null,l=0,i=function(){var e;return l=(new Date).getTime(),t.cancel(o),o=null,n.call(),e=null},function(){var r,c;return r=(new Date).getTime(),c=e-(r-l),0>=c?(clearTimeout(o),t.cancel(o),o=null,l=r,n.call()):o?void 0:o=t(i,c)}},null!=i&&(S=h(S,i)),l.$on("$destroy",function(){return a.off("scroll",S)}),d=function(n){return $=parseInt(n,10)||0},l.$watch("infiniteScrollDistance",d),d(l.infiniteScrollDistance),m=function(n){return p=!n,p&&u?(u=!1,S()):void 0},l.$watch("infiniteScrollDisabled",m),m(l.infiniteScrollDisabled),s=function(n){return T=n},l.$watch("infiniteScrollUseDocumentBottom",s),s(l.infiniteScrollUseDocumentBottom),c=function(n){return null!=a&&a.off("scroll",S),a="function"==typeof n.last&&n!==C?n.last():n,null!=n?a.on("scroll",S):void 0},c(C),f=function(n){if(null!=n&&0!==n.length){if(n=angular.element(document.querySelector(n)),null!=n)return c(n);throw new Exception("invalid infinite-scroll-container attribute.")}},l.$watch("infiniteScrollContainer",f),f(l.infiniteScrollContainer||[]),null!=r.infiniteScrollParent&&c(angular.element(o.parent())),null!=r.infiniteScrollImmediateCheck&&(g=l.$eval(r.infiniteScrollImmediateCheck)),t(function(){return g?S():void 0},0)}}}]); \ No newline at end of file +/* ng-infinite-scroll - v1.1.2 - 2014-09-24 */ +var mod;mod=angular.module("infinite-scroll",[]),mod.value("THROTTLE_MILLISECONDS",null),mod.directive("infiniteScroll",["$rootScope","$window","$timeout","THROTTLE_MILLISECONDS",function(n,e,t,l){return{scope:{infiniteScroll:"&",infiniteScrollContainer:"=",infiniteScrollDistance:"=",infiniteScrollDisabled:"=",infiniteScrollUseDocumentBottom:"="},link:function(i,o,r){var c,u,a,f,d,m,s,S,v,g,w,D,$,h,p,E,T;return T=angular.element(e),w=this,h=null,w.scrollEnabled=null,u=null,a=null,g=!0,E=!1,v=function(n){return n=n[0]||n,isNaN(n.offsetHeight)?n.document.documentElement.clientHeight:n.offsetHeight},D=function(n){return n[0].getBoundingClientRect&&!n.css("none")?n[0].getBoundingClientRect().top+$(n):void 0},$=function(n){return n=n[0]||n,isNaN(window.pageYOffset)?n.document.documentElement.scrollTop:n.ownerDocument.defaultView.pageYOffset},S=function(){var e,t,l,r,c;return a===T?(e=v(a)+$(a[0].document.documentElement),l=D(o)+v(o)):(e=v(a),t=0,void 0!==D(a)&&(t=D(a)),l=D(o)-t+v(o)),E&&(l=v((o[0].ownerDocument||o[0].document).documentElement)),r=l-e,c=v(a)*h+1>=r,c?(u=!0,w.scrollEnabled?i.$$phase||n.$$phase?i.infiniteScroll():i.$apply(i.infiniteScroll):void 0):u=!1},p=function(n,e){var l,i,o;return o=null,i=0,l=function(){var e;return i=(new Date).getTime(),t.cancel(o),o=null,n.call(),e=null},function(){var r,c;return r=(new Date).getTime(),c=e-(r-i),0>=c?(clearTimeout(o),t.cancel(o),o=null,i=r,n.call()):o?void 0:o=t(l,c)}},null!=l&&(S=p(S,l)),i.$on("$destroy",function(){return a.off("scroll",S)}),m=function(n){return h=parseFloat(n)||0},i.$watch("infiniteScrollDistance",m),m(i.infiniteScrollDistance),d=function(n){return w.scrollEnabled=!n,w.scrollEnabled&&u?(u=!1,S()):void 0},i.$watch("infiniteScrollDisabled",d),d(i.infiniteScrollDisabled),s=function(n){return E=n},i.$watch("infiniteScrollUseDocumentBottom",s),s(i.infiniteScrollUseDocumentBottom),c=function(n){return null!=a&&a.off("scroll",S),a="function"==typeof n.last&&n!==T?n.last():n,null!=n?a.on("scroll",S):void 0},c(T),f=function(n){if(null!=n&&0!==n.length){if(n=angular.element(document.querySelector(n)),null!=n)return c(n);throw new Exception("invalid infinite-scroll-container attribute.")}},i.$watch("infiniteScrollContainer",f),f(i.infiniteScrollContainer||[]),null!=r.infiniteScrollParent&&c(angular.element(o.parent())),null!=r.infiniteScrollImmediateCheck&&(g=i.$eval(r.infiniteScrollImmediateCheck)),t(function(){return g?S():void 0},0)}}}]); \ No newline at end of file diff --git a/src/infinite-scroll.coffee b/src/infinite-scroll.coffee index edfc073..f275d40 100644 --- a/src/infinite-scroll.coffee +++ b/src/infinite-scroll.coffee @@ -13,9 +13,10 @@ mod.directive 'infiniteScroll', ['$rootScope', '$window', '$timeout', 'THROTTLE_ link: (scope, elem, attrs) -> windowElement = angular.element($window) - + + ngIs = this scrollDistance = null - scrollEnabled = null + ngIs.scrollEnabled = null checkWhenEnabled = null container = null immediateCheck = true @@ -63,7 +64,7 @@ mod.directive 'infiniteScroll', ['$rootScope', '$window', '$timeout', 'THROTTLE_ if shouldScroll checkWhenEnabled = true - if scrollEnabled + if ngIs.scrollEnabled if scope.$$phase || $rootScope.$$phase scope.infiniteScroll() else @@ -123,8 +124,8 @@ mod.directive 'infiniteScroll', ['$rootScope', '$window', '$timeout', 'THROTTLE_ # once it switches back to false the infinite scroll function # will be triggered again. handleInfiniteScrollDisabled = (v) -> - scrollEnabled = !v - if scrollEnabled && checkWhenEnabled + ngIs.scrollEnabled = !v + if ngIs.scrollEnabled && checkWhenEnabled checkWhenEnabled = false handler()