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

Added autoTriggerUntil function support #29

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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $('.jscroll').jscroll({

* debug (false) When set to true, outputs useful information to the console display if the `console` object exists.
* autoTrigger (true) When set to true, triggers the loading of the next set of content automatically when the user scrolls to the bottom of the containing element. When set to false, the required next link will trigger the loading of the next set of content when clicked.
* autoTriggerUntil (false) Set to an integer great than 0 to turn off `autoTrigger` of paging after the specified number of pages. Requires `autoTrigger` to be `true`.
* autoTriggerUntil (false) Set to an integer great than 0 to turn off `autoTrigger` of paging after the specified number of pages. You can also provide a function that will be called after each page load (return false to stop loading). Requires `autoTrigger` to be `true`.
* loadingHtml (`'<small>Loading...</small>'`) The HTML to show at the bottom of the content while loading the next set.
* padding (0) The distance from the bottom of the scrollable content at which to trigger the loading of the next set of content. This only applies when autoTrigger is set to true.
* nextSelector ('a:last') The selector to use for finding the link which contains the href pointing to the next set of content. If this selector is not found, or if it does not contain a href attribute, jScroll will self-destroy and unbind from the element upon which it was called.
Expand Down
24 changes: 12 additions & 12 deletions jquery.jscroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @author Philip Klauzinski
* @requires jQuery v1.4.3+
*/
(function($) {
(function ($) {

// Define the jscroll namespace and default settings
$.jscroll = {
Expand All @@ -30,7 +30,7 @@
};

// Constructor
var jScroll = function($e, options) {
var jScroll = function ($e, options) {

// Private vars
var _data = $e.data('jscroll'),
Expand All @@ -44,7 +44,7 @@
_nextHref = $.trim(_$next.attr('href') + ' ' + _options.contentSelector);

// Initialization
$e.data('jscroll', $.extend({}, _data, {initialized: true, waiting: false, nextHref: _nextHref}));
$e.data('jscroll', $.extend({}, _data, { initialized: true, waiting: false, nextHref: _nextHref }));
_wrapInnerContent();
_preloadImage();
_setBindings();
Expand Down Expand Up @@ -118,23 +118,23 @@
return true;
}
}

function _setBindings() {
var $next = $e.find(_options.nextSelector).first();
if (_options.autoTrigger && (_options.autoTriggerUntil === false || _options.autoTriggerUntil > 0)) {
if (_options.autoTrigger && ((_options.autoTriggerUntil === false || _options.autoTriggerUntil > 0) || ($.isFunction(_options.autoTriggerUntil) && _options.autoTriggerUntil()))) {
_nextWrap($next);
if (_$body.height() <= _$window.height()) {
_observe();
}
_$scroll.unbind('.jscroll').bind('scroll.jscroll', function() {
_$scroll.unbind('.jscroll').bind('scroll.jscroll', function () {
return _observe();
});
if (_options.autoTriggerUntil > 0) {
if (_options.autoTriggerUntil > 0 && !$.isFunction(_options.autoTriggerUntil)) {
_options.autoTriggerUntil--;
}
} else {
_$scroll.unbind('.jscroll');
$next.bind('click.jscroll', function() {
$next.bind('click.jscroll', function () {
_nextWrap($next);
_load();
return false;
Expand All @@ -152,8 +152,8 @@
.children('.jscroll-added').last()
.html('<div class="jscroll-loading">' + _options.loadingHtml + '</div>');

return $e.animate({scrollTop: $inner.outerHeight()}, 0, function() {
$inner.find('div.jscroll-added').last().load(data.nextHref, function(r, status, xhr) {
return $e.animate({ scrollTop: $inner.outerHeight() }, 0, function () {
$inner.find('div.jscroll-added').last().load(data.nextHref, function (r, status, xhr) {
if (status === 'error') {
return _destroy();
}
Expand Down Expand Up @@ -197,8 +197,8 @@
};

// Define the jscroll plugin method and loop
$.fn.jscroll = function(m) {
return this.each(function() {
$.fn.jscroll = function (m) {
return this.each(function () {
var $this = $(this),
data = $this.data('jscroll');
// Instantiate jScroll on this element if it hasn't been already
Expand Down
2 changes: 1 addition & 1 deletion jquery.jscroll.min.js

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