forked from pklauzinski/jscroll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.jscroll.min.js
15 lines (15 loc) · 3.47 KB
/
jquery.jscroll.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*!
* jScroll - jQuery Plugin for Infinite Scrolling / Auto-Paging - v2.1.1
* http://jscroll.com/
*
* Copyright 2011-2013, Philip Klauzinski
* http://klauzinski.com/
* Dual licensed under the MIT and GPL Version 2 licenses.
* http://jscroll.com/#license
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl-2.0.html
*
* @author Philip Klauzinski
* @requires jQuery v1.4.3+
*/
(function(b){b.jscroll={defaults:{debug:false,autoTrigger:true,loadingHtml:"<small>Loading...</small>",padding:0,nextSelector:"a:last",contentSelector:"",pagingSelector:""}};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(),u=b(window),h=b(document),q=c?b(window):e,m=p.contentSelector?l.attr("href")+" "+p.contentSelector:l.attr("href");e.data("jscroll",b.extend({},o,{initialized:true,waiting:false,nextHref:m}));r();k();if(p.autoTrigger){d(l);q.bind("scroll.jscroll",function(){return i()})}else{l.bind("click.jscroll",function(){d(l);t();return false})}function k(){var w=b(p.loadingHtml).filter("img").attr("src");if(w){var v=new Image();v.src=w}}function r(){if(!e.find(".jscroll-inner").length){e.contents().wrapAll('<div class="jscroll-inner" />')}}function d(v){if(p.pagingSelector){var w=v.closest(p.pagingSelector).hide()}else{var w=v.parent().not(".jscroll-inner,.jscroll-added").addClass("jscroll-next-parent").hide();if(!w.length){v.wrap('<div class="jscroll-next-parent" />').parent().hide()}}}function j(){return q.unbind(".jscroll").removeData("jscroll").find(".jscroll-inner").children().unwrap().filter(".jscroll-added").children().unwrap()}function i(){r();var C=e.find("div.jscroll-inner").first(),A=e.data("jscroll"),B=parseInt(e.css("borderTopWidth")),x=isNaN(B)?0:B,w=parseInt(e.css("paddingTop"))+x,z=c?q.scrollTop():e.offset().top,y=C.length?C.offset().top:0,v=Math.ceil(z-y+q.height()+w);if(s(A)&&!A.waiting&&v+p.padding>=C.outerHeight()){A.nextHref=b.trim(A.nextHref+" "+p.contentSelector);f("info","jScroll:",C.outerHeight()-v,"from bottom. Loading next request...");return t()}}function s(v){v=v||e.data("jscroll");if(!v.nextHref){f("warn","jScroll: nextSelector not found - destroying");e.jscroll.destroy();return false}else{return true}}function t(){var w=e.find("div.jscroll-inner").first(),v=e.data("jscroll");v.waiting=true;w.append('<div class="jscroll-added" />').children(".jscroll-added").last().html('<div class="jscroll-loading">'+p.loadingHtml+"</div>");return s(v)&&e.animate({scrollTop:w.outerHeight()},0,function(){w.find("div.jscroll-added").last().load(v.nextHref,function(z,y,A){var x=b(this).find(p.nextSelector).first();v.waiting=false;v.nextHref=p.contentSelector?x.attr("href")+" "+p.contentSelector:x.attr("href");b(".jscroll-next-parent",e).remove();if(p.autoTrigger){d(x)}else{x.bind("click.jscroll",function(){d(x);i();return false})}if(p.callback){p.callback.call(this)}f("dir",v)})})}function f(v){if(p.debug&&typeof console==="object"&&(typeof v==="object"||typeof console[v]==="function")){if(typeof v==="object"){var x=[];for(var w in v){if(typeof console[w]==="function"){x=(v[w].length)?v[w]:[v[w]];console[w].apply(console,x)}else{console.log.apply(console,x)}}}else{console[v].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);