Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a rare bug when the scope of scrollEnabled in the handler was not the same as handleInfiniteScrollDisable. #127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions build/ng-infinite-scroll.js
Original file line number Diff line number Diff line change
@@ -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', []);
Expand All @@ -16,18 +16,19 @@ 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;
useDocumentBottom = false;
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;
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions build/ng-infinite-scroll.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions src/infinite-scroll.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ mod.directive 'infiniteScroll', ['$rootScope', '$window', '$timeout', 'THROTTLE_

link: (scope, elem, attrs) ->
windowElement = angular.element($window)


ngIs = this
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be @ in coffescript.

scrollDistance = null
scrollEnabled = null
ngIs.scrollEnabled = null
checkWhenEnabled = null
container = null
immediateCheck = true
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down