jquery-on-infinite-scroll
Advanced tools
Comparing version 0.0.1 to 1.0.0
29
index.js
(function() { | ||
var onScroll = function() { | ||
var onScroll = function(e) { | ||
if ($.active != 0) return; | ||
var offset = $(window).height() * 0.7, | ||
viewPortBottom = $(window).scrollTop() + $(window).height(), | ||
reachedBottom = viewPortBottom >= $(document).height() - offset; | ||
if (e.data) { | ||
var offset = e.data.offset; | ||
}; | ||
if (offset === undefined) { | ||
offset = $(window).height() * 0.7; | ||
} | ||
var viewPortBottom = $(window).scrollTop() + $(window).height(), | ||
breakPoint = $(document).height() - offset; | ||
reachedBottom = viewPortBottom >= breakPoint; | ||
if (!reachedBottom) return; | ||
@@ -12,7 +21,13 @@ $(window).trigger('infiniteScroll'); | ||
$.onInfiniteScroll = function(callback) { | ||
$.onInfiniteScroll = function(callback, options) { | ||
$(window).on('infiniteScroll', callback); | ||
$(window).on('scroll', onScroll); | ||
$(window).on('scroll', options, onScroll); | ||
}; | ||
})(jQuery); | ||
$.destroyInfiniteScroll = function() { | ||
$(window).off('infiniteScroll'); | ||
$(window).off('scroll'); | ||
}; | ||
})(); |
{ | ||
"name": "jquery-on-infinite-scroll", | ||
"version": "0.0.1", | ||
"version": "1.0.0", | ||
"description": "Callback when you reach the bottom of the page and ajax requests finish. Useful as an infinite scroll callback.", | ||
@@ -13,3 +13,3 @@ "keywords": [ | ||
"type": "git", | ||
"url": "http://github.com/artsy/scroll-frame.git" | ||
"url": "http://github.com/artsy/jquery-on-infinite-scroll.git" | ||
}, | ||
@@ -16,0 +16,0 @@ "author": { |
@@ -11,2 +11,9 @@ # jQuery.onInfiniteScroll | ||
}); | ||
$.onInfiniteScroll(function() { | ||
// Pass an optional offset from the page bottom at which to trigger the callback. | ||
}, { offset: 100 }); | ||
// Remove the event listeners. | ||
$.destroyInfiniteScroll(); | ||
```` | ||
@@ -13,0 +20,0 @@ |
var benv = require('benv'); | ||
beforeEach(function(done) { | ||
benv.setup(function() { | ||
benv.expose({ $: require('jquery'), jQuery: require('jquery') }); | ||
require('../index'); | ||
done(); | ||
describe('onInfiniteScroll', function() { | ||
beforeEach(function(done) { | ||
benv.setup(function() { | ||
benv.expose({ $: require('jquery'), jQuery: require('jquery') }); | ||
require('../index'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
afterEach(function() { | ||
benv.teardown(); | ||
}); | ||
afterEach(function() { | ||
$.destroyInfiniteScroll(); | ||
benv.teardown(); | ||
}); | ||
describe('onInfiniteScroll', function() { | ||
it('uses the callback when you have scrolled to the bottom', function(done) { | ||
$.onInfiniteScroll(function() { | ||
done() | ||
done(); | ||
}); | ||
$.fn.scrollTop = function() { return 200 }; | ||
$.fn.height = function() { return 100 }; | ||
$.fn.scrollTop = function() { return 40 }; | ||
$.fn.height = function() { | ||
if (this[0] == window) { | ||
return 50; | ||
} | ||
if (this[0] == document) { | ||
return 100; | ||
} | ||
}; | ||
$(window).trigger('scroll'); | ||
}); | ||
it('uses optional offset', function(done) { | ||
$.onInfiniteScroll(function() { | ||
done(); | ||
}, { offset: 50 }); | ||
$.fn.scrollTop = function() { return 0 }; | ||
$.fn.height = function() { | ||
if (this[0] == window) { | ||
return 50; | ||
} | ||
if (this[0] == document) { | ||
return 100; | ||
} | ||
}; | ||
$(window).trigger('scroll'); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
5729
66
1
26