Skip to content

Avoid event handler conflict #1

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

Open
wants to merge 1 commit 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
28 changes: 5 additions & 23 deletions build/ng-infinite-scroll.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* ng-infinite-scroll - v1.0.0 - 2013-07-03 */
/* ng-infinite-scroll - v1.0.1 - 2013-10-09 */
var mod;

mod = angular.module('infinite-scroll', []);
Expand All @@ -7,7 +7,8 @@ mod.directive('infiniteScroll', [
'$rootScope', '$window', '$timeout', function($rootScope, $window, $timeout) {
return {
link: function(scope, elem, attrs) {
var checkWhenEnabled, handler, scrollDistance, scrollEnabled, throttle;
var checkWhenEnabled, handler, scrollDistance, scrollEnabled, windowElement;
windowElement = angular.element($window);
scrollDistance = 0;
if (attrs.infiniteScrollDistance != null) {
scope.$watch(attrs.infiniteScrollDistance, function(value) {
Expand All @@ -25,25 +26,6 @@ mod.directive('infiniteScroll', [
}
});
}
throttle = function(fn, delay) {
var timer;
if (delay === 0) {
return fn;
}
timer = false;
return function() {
if (timer) {
return;
}
timer = true;
if (delay !== -1) {
$timeout((function() {
return timer = false;
}), delay);
}
return fn.apply(null, arguments);
};
};
handler = function() {
var element, elementBottom, remaining, shouldScroll, windowBottom;
element = elem[0];
Expand All @@ -61,9 +43,9 @@ mod.directive('infiniteScroll', [
return checkWhenEnabled = true;
}
};
$window.onscroll = throttle(handler, 100);
windowElement.bind('scroll', handler);
scope.$on('$destroy', function() {
return $window.onscroll = null;
return windowElement.unbind('scroll', handler);
});
return $timeout((function() {
if (attrs.infiniteScrollImmediateCheck) {
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.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-infinite-scroll",
"version": "1.0.0",
"version": "1.0.1",
"description": "Infinite scrolling for AngularJS",
"repository": {
"type": "git",
Expand All @@ -22,6 +22,7 @@
"grunt-contrib-concat": "~0.1.2",
"grunt-contrib-uglify": "~0.1.1",
"coffee-script": "~1.4.0",
"grunt-contrib-clean": "~0.4.0"
"grunt-contrib-clean": "~0.4.0",
"grunt": "~0.4.1"
}
}
17 changes: 4 additions & 13 deletions src/infinite-scroll.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ mod = angular.module('infinite-scroll', [])

mod.directive 'infiniteScroll', ['$rootScope', '$window', '$timeout', ($rootScope, $window, $timeout) ->
link: (scope, elem, attrs) ->
windowElement = angular.element($window)

# infinite-scroll-distance specifies how close to the bottom of the page
# the window is allowed to be before we trigger a new scroll. The value
# provided is multiplied by the window height; for example, to load
Expand All @@ -27,17 +29,6 @@ mod.directive 'infiniteScroll', ['$rootScope', '$window', '$timeout', ($rootScop
checkWhenEnabled = false
handler()

# throttle function so scroll event don't hit
# handler every time it's emmitted
throttle = (fn, delay) ->
return fn if delay is 0
timer = false
return ->
return if timer
timer = true
$timeout (-> timer = false), delay unless delay is -1
fn arguments...

# infinite-scroll specifies a function to call when the window
# is scrolled within a certain range from the bottom of the
# document. It is recommended to use infinite-scroll-disabled
Expand All @@ -58,9 +49,9 @@ mod.directive 'infiniteScroll', ['$rootScope', '$window', '$timeout', ($rootScop
else if shouldScroll
checkWhenEnabled = true

$window.onscroll = throttle handler, 100
windowElement.bind 'scroll', handler
scope.$on '$destroy', ->
$window.onscroll = null
windowElement.unbind 'scroll', handler

$timeout (->
if attrs.infiniteScrollImmediateCheck
Expand Down