Skip to content

Commit

Permalink
Extended namespaces for event listeners for support of multiple jscro…
Browse files Browse the repository at this point in the history
…lls on same pane
  • Loading branch information
mrIllo authored Dec 20, 2016
1 parent aed806b commit 5c7682c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
32 changes: 18 additions & 14 deletions jquery.jscroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
contentSelector: '',
pagingSelector: '',
callback: false
}
},
instances: 0
};

// Constructor
Expand Down Expand Up @@ -79,8 +80,10 @@

// Remove the jscroll behavior and data from an element
_destroy = function() {
return _$scroll.unbind('.jscroll')
.removeData('jscroll')
var data = $e.data('jscroll');
$e.removeData('jscroll');
return _$scroll.unbind('.jscroll.instance_'+data.id)
//.removeData('jscroll') //CI: think this is obsolete
.find('.jscroll-inner').children().unwrap()
.filter('.jscroll-added').children().unwrap();
},
Expand All @@ -100,7 +103,7 @@

if (!data.waiting && iTotalHeight + _options.padding >= $inner.outerHeight()) {
//data.nextHref = $.trim(data.nextHref + ' ' + _options.contentSelector);
_debug('info', 'jScroll:', $inner.outerHeight() - iTotalHeight, 'from bottom. Loading next request...');
_debug('info', 'jScroll[' + data.id + ']:', $inner.outerHeight() - iTotalHeight, 'from bottom. Loading next request...');
return _load();
}
}
Expand All @@ -110,7 +113,7 @@
_checkNextHref = function(data) {
data = data || $e.data('jscroll');
if (!data || !data.nextHref) {
_debug('warn', 'jScroll: nextSelector not found - destroying');
_debug('warn', 'jScroll[' + data.id + ']: nextSelector not found - destroying');
_destroy();
return false;
} else {
Expand All @@ -120,27 +123,28 @@
},

_setBindings = function() {
var $next = $e.find(_options.nextSelector).first();
var $next = $e.find(_options.nextSelector).first(),
data = $e.data('jscroll');
if (!$next.length) {
return;
}
if (_options.autoTrigger && (_options.autoTriggerUntil === false || _options.autoTriggerUntil > 0)) {
_nextWrap($next);
var scrollingBodyHeight = _$body.height() - $e.offset().top,
scrollingHeight = ($e.height() < scrollingBodyHeight) ? $e.height() : scrollingBodyHeight,
windowHeight = ($e.offset().top - _$window.scrollTop() > 0) ? _$window.height() - ($e.offset().top - $(window).scrollTop()) : _$window.height();
var scrollingBodyHeight = _$body.height() - $e.offset().top,
scrollingHeight = ($e.height() < scrollingBodyHeight) ? $e.height() : scrollingBodyHeight,
windowHeight = ($e.offset().top - _$window.scrollTop() > 0) ? _$window.height() - ($e.offset().top - $(window).scrollTop()) : _$window.height();
if (scrollingHeight <= windowHeight) {
_observe();
}
_$scroll.unbind('.jscroll').bind('scroll.jscroll', function() {
_$scroll.unbind('.jscroll.instance_'+data.id).bind('scroll.jscroll.instance_'+data.id, function() {
return _observe();
});
if (_options.autoTriggerUntil > 0) {
_options.autoTriggerUntil--;
}
} else {
_$scroll.unbind('.jscroll');
$next.bind('click.jscroll', function() {
_$scroll.unbind('.jscroll.instance_'+data.id);
$next.bind('click.jscroll.instance_'+data.id, function() {
_nextWrap($next);
_load();
return false;
Expand All @@ -156,7 +160,7 @@
data.waiting = true;
$inner.append('<div class="jscroll-added" />')
.children('.jscroll-added').last()
.html('<div class="jscroll-loading" id="jscroll-loading">' + _options.loadingHtml + '</div>')
.html('<div class="jscroll-loading">' + _options.loadingHtml + '</div>')
.promise()
.done(function(){
if (_options.loadingFunction) {
Expand Down Expand Up @@ -202,7 +206,7 @@
};

// Initialization
$e.data('jscroll', $.extend({}, _data, {initialized: true, waiting: false, nextHref: _nextHref}));
$e.data('jscroll', $.extend({}, _data, {initialized: true, waiting: false, nextHref: _nextHref, id: ++$.jscroll.instances}));
_wrapInnerContent();
_preloadImage();
_setBindings();
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.

0 comments on commit 5c7682c

Please sign in to comment.