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 autoTriggerRateLimit, autoTriggerPauseUntilLoaded functionality… #174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
40 changes: 36 additions & 4 deletions jquery.jscroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
debug: false,
autoTrigger: true,
autoTriggerUntil: false,
autoTriggerRateLimit: 1000,
autoTriggerLastFiredAt: null,
autoTriggerPauseUntilLoaded: true,
loadingHtml: '<small>Loading...</small>',
loadingFunction: false,
padding: 0,
Expand Down Expand Up @@ -144,10 +147,36 @@

// Load the next set of content, if available
_load = function() {
var $inner = $e.find('div.jscroll-inner').first(),
data = $e.data('jscroll');

data.waiting = true;
// Respect rate limits, if set...
if(_options.autoTriggerRateLimit !== false) {

let now = new Date().valueOf();

if( now < _options.autoTriggerLastFiredAt + _options.autoTriggerLastFiredAt ) {
return; // Exit early and avoid preemptive overhead.
} else {
_options.autoTriggerLastFiredAt = now;
}
}

var $inner = $e.find('div.jscroll-inner').first();

// Check that any images in currently enqueued elements have completed loading...
if(_options.autoTriggerPauseUntilLoaded === true ){
let enquedImages = $inner.find('img');
if( enquedImages.length ) {
for (var i = enquedImages.length - 1; i >= 0; i--){
if(!enquedImages[i].complete){
return _debug('autoTriggerAborted', '-- Still Loading Images --');
}
}
}
}

var data = $e.data('jscroll');
data.waiting = true;

$inner.append('<div class="jscroll-added" />')
.children('.jscroll-added').last()
.html('<div class="jscroll-loading" id="jscroll-loading">' + _options.loadingHtml + '</div>')
Expand All @@ -158,6 +187,9 @@
}
});


if($e.find('div.jscroll-inner').first())

return $e.animate({scrollTop: $inner.outerHeight()}, 0, function() {
var nextHref = data.nextHref;
$inner.find('div.jscroll-added').last().load(nextHref, function(r, status) {
Expand Down Expand Up @@ -223,4 +255,4 @@
});
};

})(jQuery);
})(jQuery);