diff --git a/jquery.jscroll.js b/jquery.jscroll.js index 06fb462..3c8b440 100644 --- a/jquery.jscroll.js +++ b/jquery.jscroll.js @@ -30,6 +30,7 @@ nextSelector: 'a:last', contentSelector: '', pagingSelector: '', + windowSelector: '', callback: false } }; @@ -43,7 +44,7 @@ _options = $.extend({}, $.jscroll.defaults, _userOptions, _data || {}), _isWindow = ($e.css('overflow-y') === 'visible'), _$next = $e.find(_options.nextSelector).first(), - _$window = $(window), + _$window = _options.windowSelector ? $(_options.windowSelector): $(window), _$body = $('body'), _$scroll = _isWindow ? _$window : $e, _nextHref = $.trim(_$next.attr('href') + ' ' + _options.contentSelector), diff --git a/jquery.jscroll.min.js b/jquery.jscroll.min.js index 4f099d1..66d15b6 100644 --- a/jquery.jscroll.min.js +++ b/jquery.jscroll.min.js @@ -14,4 +14,4 @@ * @requires jQuery v1.4.3+ * @preserve */ -!function(a){"use strict";a.jscroll={defaults:{debug:!1,autoTrigger:!0,autoTriggerUntil:!1,loadingHtml:"Loading...",loadingFunction:!1,padding:0,nextSelector:"a:last",contentSelector:"",pagingSelector:"",callback:!1}};var b=function(b,c){var d=b.data("jscroll"),e="function"==typeof c?{callback:c}:c,f=a.extend({},a.jscroll.defaults,e,d||{}),g="visible"===b.css("overflow-y"),h=b.find(f.nextSelector).first(),i=a(window),j=a("body"),k=g?i:b,l=a.trim(h.attr("href")+" "+f.contentSelector),m=function(){var b=a(f.loadingHtml).filter("img").attr("src");if(b){var c=new Image;c.src=b}},n=function(){b.find(".jscroll-inner").length||b.contents().wrapAll('
')},o=function(a){var b;f.pagingSelector?a.closest(f.pagingSelector).hide():(b=a.parent().not(".jscroll-inner,.jscroll-added").addClass("jscroll-next-parent").hide(),b.length||a.wrap('
').parent().hide())},p=function(){return k.unbind(".jscroll").removeData("jscroll").find(".jscroll-inner").children().unwrap().filter(".jscroll-added").children().unwrap()},q=function(){if(b.is(":visible")){n();var a=b.find("div.jscroll-inner").first(),c=b.data("jscroll"),d=parseInt(b.css("borderTopWidth"),10),e=isNaN(d)?0:d,h=parseInt(b.css("paddingTop"),10)+e,i=g?k.scrollTop():b.offset().top,j=a.length?a.offset().top:0,l=Math.ceil(i-j+k.height()+h);if(!c.waiting&&l+f.padding>=a.outerHeight())return u("info","jScroll:",a.outerHeight()-l,"from bottom. Loading next request..."),t()}},r=function(a){return a=a||b.data("jscroll"),a&&a.nextHref?(s(),!0):(u("warn","jScroll: nextSelector not found - destroying"),p(),!1)},s=function(){var c=b.find(f.nextSelector).first();if(c.length)if(f.autoTrigger&&(f.autoTriggerUntil===!1||f.autoTriggerUntil>0)){o(c);var d=j.height()-b.offset().top,e=b.height()0?i.height()-(b.offset().top-a(window).scrollTop()):i.height();g>=e&&q(),k.unbind(".jscroll").bind("scroll.jscroll",function(){return q()}),f.autoTriggerUntil>0&&f.autoTriggerUntil--}else k.unbind(".jscroll"),c.bind("click.jscroll",function(){return o(c),t(),!1})},t=function(){var c=b.find("div.jscroll-inner").first(),d=b.data("jscroll");return d.waiting=!0,c.append('
').children(".jscroll-added").last().html('
'+f.loadingHtml+"
").promise().done(function(){f.loadingFunction&&f.loadingFunction()}),b.animate({scrollTop:c.outerHeight()},0,function(){c.find("div.jscroll-added").last().load(d.nextHref,function(c,e){if("error"===e)return p();var g=a(this).find(f.nextSelector).first();d.waiting=!1,d.nextHref=g.attr("href")?a.trim(g.attr("href")+" "+f.contentSelector):!1,a(".jscroll-next-parent",b).remove(),r(),f.callback&&f.callback.call(this),u("dir",d)})})},u=function(a){if(f.debug&&"object"==typeof console&&("object"==typeof a||"function"==typeof console[a]))if("object"==typeof a){var b=[];for(var c in a)"function"==typeof console[c]?(b=a[c].length?a[c]:[a[c]],console[c].apply(console,b)):console.log.apply(console,b)}else console[a].apply(console,Array.prototype.slice.call(arguments,1))};return b.data("jscroll",a.extend({},d,{initialized:!0,waiting:!1,nextHref:l})),n(),m(),s(),a.extend(b.jscroll,{destroy:p}),b};a.fn.jscroll=function(c){return this.each(function(){var d,e=a(this),f=e.data("jscroll");f&&f.initialized||(d=new b(e,c))})}}(jQuery); \ No newline at end of file +!function(a){"use strict";a.jscroll={defaults:{debug:!1,autoTrigger:!0,autoTriggerUntil:!1,loadingHtml:"Loading...",loadingFunction:!1,padding:0,nextSelector:"a:last",contentSelector:"",pagingSelector:"",windowSelector:"",callback:!1}};var b=function(b,c){var d=b.data("jscroll"),e="function"==typeof c?{callback:c}:c,f=a.extend({},a.jscroll.defaults,e,d||{}),g="visible"===b.css("overflow-y"),h=b.find(f.nextSelector).first(),i=a(f.windowSelector?f.windowSelector:window),j=a("body"),k=g?i:b,l=a.trim(h.attr("href")+" "+f.contentSelector),m=function(){var b=a(f.loadingHtml).filter("img").attr("src");if(b){var c=new Image;c.src=b}},n=function(){b.find(".jscroll-inner").length||b.contents().wrapAll('
')},o=function(a){var b;f.pagingSelector?a.closest(f.pagingSelector).hide():(b=a.parent().not(".jscroll-inner,.jscroll-added").addClass("jscroll-next-parent").hide(),b.length||a.wrap('
').parent().hide())},p=function(){return k.unbind(".jscroll").removeData("jscroll").find(".jscroll-inner").children().unwrap().filter(".jscroll-added").children().unwrap()},q=function(){if(b.is(":visible")){n();var a=b.find("div.jscroll-inner").first(),c=b.data("jscroll"),d=parseInt(b.css("borderTopWidth"),10),e=isNaN(d)?0:d,h=parseInt(b.css("paddingTop"),10)+e,i=g?k.scrollTop():b.offset().top,j=a.length?a.offset().top:0,l=Math.ceil(i-j+k.height()+h);if(!c.waiting&&l+f.padding>=a.outerHeight())return u("info","jScroll:",a.outerHeight()-l,"from bottom. Loading next request..."),t()}},r=function(a){return a=a||b.data("jscroll"),a&&a.nextHref?(s(),!0):(u("warn","jScroll: nextSelector not found - destroying"),p(),!1)},s=function(){var c=b.find(f.nextSelector).first();if(c.length)if(f.autoTrigger&&(f.autoTriggerUntil===!1||f.autoTriggerUntil>0)){o(c);var d=j.height()-b.offset().top,e=b.height()0?i.height()-(b.offset().top-a(window).scrollTop()):i.height();g>=e&&q(),k.unbind(".jscroll").bind("scroll.jscroll",function(){return q()}),f.autoTriggerUntil>0&&f.autoTriggerUntil--}else k.unbind(".jscroll"),c.bind("click.jscroll",function(){return o(c),t(),!1})},t=function(){var c=b.find("div.jscroll-inner").first(),d=b.data("jscroll");return d.waiting=!0,c.append('
').children(".jscroll-added").last().html('
'+f.loadingHtml+"
").promise().done(function(){f.loadingFunction&&f.loadingFunction()}),b.animate({scrollTop:c.outerHeight()},0,function(){c.find("div.jscroll-added").last().load(d.nextHref,function(c,e){if("error"===e)return p();var g=a(this).find(f.nextSelector).first();d.waiting=!1,d.nextHref=g.attr("href")?a.trim(g.attr("href")+" "+f.contentSelector):!1,a(".jscroll-next-parent",b).remove(),r(),f.callback&&f.callback.call(this),u("dir",d)})})},u=function(a){if(f.debug&&"object"==typeof console&&("object"==typeof a||"function"==typeof console[a]))if("object"==typeof a){var b=[];for(var c in a)"function"==typeof console[c]?(b=a[c].length?a[c]:[a[c]],console[c].apply(console,b)):console.log.apply(console,b)}else console[a].apply(console,Array.prototype.slice.call(arguments,1))};return b.data("jscroll",a.extend({},d,{initialized:!0,waiting:!1,nextHref:l})),n(),m(),s(),a.extend(b.jscroll,{destroy:p}),b};a.fn.jscroll=function(c){return this.each(function(){var d,e=a(this),f=e.data("jscroll");f&&f.initialized||(d=new b(e,c))})}}(jQuery); \ No newline at end of file