diff --git a/jquery.jscroll.js b/jquery.jscroll.js
index 829bdb7..9bede3a 100644
--- a/jquery.jscroll.js
+++ b/jquery.jscroll.js
@@ -25,7 +25,8 @@
nextSelector: 'a:last',
contentSelector: '',
pagingSelector: '',
- callback: false
+ callback: false,
+ onLoadComplete: false
}
};
@@ -121,6 +122,7 @@
function _setBindings() {
var $next = $e.find(_options.nextSelector).first();
+ if($next.length == 0) return false; // patched for null nextSelector object - by FabrizioT
if (_options.autoTrigger && (_options.autoTriggerUntil === false || _options.autoTriggerUntil > 0)) {
_nextWrap($next);
if (_$body.height() <= _$window.height()) {
@@ -148,15 +150,22 @@
data = $e.data('jscroll');
data.waiting = true;
+
$inner.append('
')
.children('.jscroll-added').last()
.html('' + _options.loadingHtml + '
');
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();
}
+
+ if (_options.onLoadComplete) {
+ _options.onLoadComplete.call(this,data.nextHref);
+ }
+
var $next = $(this).find(_options.nextSelector).first();
data.waiting = false;
data.nextHref = $next.attr('href') ? $.trim($next.attr('href') + ' ' + _options.contentSelector) : false;
@@ -206,4 +215,4 @@
var jscroll = new jScroll($this, m);
});
};
-})(jQuery);
\ No newline at end of file
+})(jQuery);
diff --git a/jquery.jscroll.min.js b/jquery.jscroll.min.js
index f39469a..6650f71 100644
--- a/jquery.jscroll.min.js
+++ b/jquery.jscroll.min.js
@@ -12,4 +12,4 @@
* @author Philip Klauzinski
* @requires jQuery v1.4.3+
*/
-(function(b){b.jscroll={defaults:{debug:false,autoTrigger:true,autoTriggerUntil:false,loadingHtml:"Loading...",padding:0,nextSelector:"a:last",contentSelector:"",pagingSelector:"",callback:false}};var a=function(e,g){var o=e.data("jscroll"),n=(typeof g==="function")?{callback:g}:g,p=b.extend({},b.jscroll.defaults,n,o||{}),c=(e.css("overflow-y")==="visible"),l=e.find(p.nextSelector).first(),v=b(window),h=b("body"),q=c?v:e,m=b.trim(l.attr("href")+" "+p.contentSelector);e.data("jscroll",b.extend({},o,{initialized:true,waiting:false,nextHref:m}));r();k();t();function k(){var x=b(p.loadingHtml).filter("img").attr("src");if(x){var w=new Image();w.src=x}}function r(){if(!e.find(".jscroll-inner").length){e.contents().wrapAll('')}}function d(w){if(p.pagingSelector){var x=w.closest(p.pagingSelector).hide()}else{var x=w.parent().not(".jscroll-inner,.jscroll-added").addClass("jscroll-next-parent").hide();if(!x.length){w.wrap('').parent().hide()}}}function j(){return q.unbind(".jscroll").removeData("jscroll").find(".jscroll-inner").children().unwrap().filter(".jscroll-added").children().unwrap()}function i(){r();var D=e.find("div.jscroll-inner").first(),B=e.data("jscroll"),C=parseInt(e.css("borderTopWidth")),y=isNaN(C)?0:C,x=parseInt(e.css("paddingTop"))+y,A=c?q.scrollTop():e.offset().top,z=D.length?D.offset().top:0,w=Math.ceil(A-z+q.height()+x);if(!B.waiting&&w+p.padding>=D.outerHeight()){f("info","jScroll:",D.outerHeight()-w,"from bottom. Loading next request...");return u()}}function s(w){w=w||e.data("jscroll");if(!w||!w.nextHref){f("warn","jScroll: nextSelector not found - destroying");j();return false}else{t();return true}}function t(){var w=e.find(p.nextSelector).first();if(p.autoTrigger&&(p.autoTriggerUntil===false||p.autoTriggerUntil>0)){d(w);if(h.height()<=v.height()){i()}q.unbind(".jscroll").bind("scroll.jscroll",function(){return i()});if(p.autoTriggerUntil>0){p.autoTriggerUntil--}}else{q.unbind(".jscroll");w.bind("click.jscroll",function(){d(w);u();return false})}}function u(){var x=e.find("div.jscroll-inner").first(),w=e.data("jscroll");w.waiting=true;x.append('').children(".jscroll-added").last().html(''+p.loadingHtml+"
");return e.animate({scrollTop:x.outerHeight()},0,function(){x.find("div.jscroll-added").last().load(w.nextHref,function(A,z,B){if(z==="error"){return j()}var y=b(this).find(p.nextSelector).first();w.waiting=false;w.nextHref=y.attr("href")?b.trim(y.attr("href")+" "+p.contentSelector):false;b(".jscroll-next-parent",e).remove();s();if(p.callback){p.callback.call(this)}f("dir",w)})})}function f(w){if(p.debug&&typeof console==="object"&&(typeof w==="object"||typeof console[w]==="function")){if(typeof w==="object"){var y=[];for(var x in w){if(typeof console[x]==="function"){y=(w[x].length)?w[x]:[w[x]];console[x].apply(console,y)}else{console.log.apply(console,y)}}}else{console[w].apply(console,Array.prototype.slice.call(arguments,1))}}}b.extend(e.jscroll,{destroy:j});return e};b.fn.jscroll=function(c){return this.each(function(){var f=b(this),e=f.data("jscroll");if(e&&e.initialized){return}var d=new a(f,c)})}})(jQuery);
\ No newline at end of file
+!function(t){t.jscroll={defaults:{debug:!1,autoTrigger:!0,autoTriggerUntil:!1,loadingHtml:"Loading...",padding:0,nextSelector:"a:last",contentSelector:"",pagingSelector:"",callback:!1,onLoadComplete:!1}};var e=function(e,n){function l(){var e=t(p.loadingHtml).filter("img").attr("src");if(e){var n=new Image;n.src=e}}function r(){e.find(".jscroll-inner").length||e.contents().wrapAll('')}function o(t){if(p.pagingSelector)var e=t.closest(p.pagingSelector).hide();else{var e=t.parent().not(".jscroll-inner,.jscroll-added").addClass("jscroll-next-parent").hide();e.length||t.wrap('').parent().hide()}}function i(){return b.unbind(".jscroll").removeData("jscroll").find(".jscroll-inner").children().unwrap().filter(".jscroll-added").children().unwrap()}function a(){r();var t=e.find("div.jscroll-inner").first(),n=e.data("jscroll"),l=parseInt(e.css("borderTopWidth")),o=isNaN(l)?0:l,i=parseInt(e.css("paddingTop"))+o,a=j?b.scrollTop():e.offset().top,c=t.length?t.offset().top:0,s=Math.ceil(a-c+b.height()+i);return!n.waiting&&s+p.padding>=t.outerHeight()?(f("info","jScroll:",t.outerHeight()-s,"from bottom. Loading next request..."),d()):void 0}function c(t){return t=t||e.data("jscroll"),t&&t.nextHref?(s(),!0):(f("warn","jScroll: nextSelector not found - destroying"),i(),!1)}function s(){var t=e.find(p.nextSelector).first();return 0==t.length?!1:void(p.autoTrigger&&(p.autoTriggerUntil===!1||p.autoTriggerUntil>0)?(o(t),m.height()<=v.height()&&a(),b.unbind(".jscroll").bind("scroll.jscroll",function(){return a()}),p.autoTriggerUntil>0&&p.autoTriggerUntil--):(b.unbind(".jscroll"),t.bind("click.jscroll",function(){return o(t),d(),!1})))}function d(){var n=e.find("div.jscroll-inner").first(),l=e.data("jscroll");return l.waiting=!0,n.append('').children(".jscroll-added").last().html(''+p.loadingHtml+"
"),e.animate({scrollTop:n.outerHeight()},0,function(){n.find("div.jscroll-added").last().load(l.nextHref,function(n,r){if("error"===r)return i();p.onLoadComplete&&p.onLoadComplete.call(this,l.nextHref);var o=t(this).find(p.nextSelector).first();l.waiting=!1,l.nextHref=o.attr("href")?t.trim(o.attr("href")+" "+p.contentSelector):!1,t(".jscroll-next-parent",e).remove(),c(),p.callback&&p.callback.call(this),f("dir",l)})})}function f(t){if(p.debug&&"object"==typeof console&&("object"==typeof t||"function"==typeof console[t]))if("object"==typeof t){var e=[];for(var n in t)"function"==typeof console[n]?(e=t[n].length?t[n]:[t[n]],console[n].apply(console,e)):console.log.apply(console,e)}else console[t].apply(console,Array.prototype.slice.call(arguments,1))}var u=e.data("jscroll"),g="function"==typeof n?{callback:n}:n,p=t.extend({},t.jscroll.defaults,g,u||{}),j="visible"===e.css("overflow-y"),h=e.find(p.nextSelector).first(),v=t(window),m=t("body"),b=j?v:e,x=t.trim(h.attr("href")+" "+p.contentSelector);return e.data("jscroll",t.extend({},u,{initialized:!0,waiting:!1,nextHref:x})),r(),l(),s(),t.extend(e.jscroll,{destroy:i}),e};t.fn.jscroll=function(n){return this.each(function(){var l=t(this),r=l.data("jscroll");if(!r||!r.initialized){new e(l,n)}})}}(jQuery);