Skip to content
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
26 changes: 14 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 @@ -25,12 +25,13 @@
nextSelector: 'a:last',
contentSelector: '',
pagingSelector: '',
callback: false
callback: false,
paddingSelector: '.jscroll-inner'
}
};

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

// Private vars
var _data = $e.data('jscroll'),
Expand All @@ -44,7 +45,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 @@ -97,9 +98,10 @@
iContainerTop = parseInt($e.css('paddingTop')) + borderTopWidthInt,
iTopHeight = _isWindow ? _$scroll.scrollTop() : $e.offset().top,
innerTop = $inner.length ? $inner.offset().top : 0,
iTotalHeight = Math.ceil(iTopHeight - innerTop + _$scroll.height() + iContainerTop);
iTotalHeight = Math.ceil(iTopHeight - innerTop + _$scroll.height() + iContainerTop),
$resultsContainer = $(_options.paddingSelector);

if (!data.waiting && iTotalHeight + _options.padding >= $inner.outerHeight()) {
if (!data.waiting && iTotalHeight + _options.padding >= $resultsContainer.outerHeight()) {
//data.nextHref = $.trim(data.nextHref + ' ' + _options.contentSelector);
_debug('info', 'jScroll:', $inner.outerHeight() - iTotalHeight, 'from bottom. Loading next request...');
return _load();
Expand All @@ -126,15 +128,15 @@
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) {
_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 +154,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 +199,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