-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjmscroll.min.js
10 lines (10 loc) · 4.71 KB
/
jmscroll.min.js
1
2
3
4
5
6
7
8
9
10
(function(b){b.jmscroll={defaults:{debug:!1,autoTrigger:!1,autoTriggerUntil:!1,totalPages:10,contentSelector:"",nextSelector:"a:last",footerSelector:".footer",footerPadding:0,footerVisible:!0,loadingContentDelay:1E3,callback:!1,progressType:"bar",loadingHtml:"Loading More",progressBarSpeed:10,spinnerLines:13,spinnerLength:10,spinnerWidth:10,spinnerRadius:20,spinnerCorners:1,spinnerRotate:0,spinnerDirection:1,spinnerColor:"#000",spinnerSpeed:1,spinnerTrail:60,spinnerShadow:!1,spinnerHwaccel:!1,spinnerClassName:"spinner",
spinnerZIndex:2E9,spinnerTop:"50%",spinnerLeft:"50%"}};var p=function(d,e){function h(){var c=b(a.loadingHtml).filter("img").attr("src");c&&((new Image).src=c)}function q(){d.find(".scroll-wrapper").length||d.contents().wrapAll('<div class="scroll-wrapper" />')}function r(a){a.parent().not(".scroll-wrapper,.scroll-added").addClass("scroll-next-wrapper").hide().length||a.wrap('<div class="scroll-next-wrapper" />').parent().hide()}function t(){var c=d.find(a.nextSelector).first();if(a.autoTrigger&&
(!1===a.autoTriggerUntil||0<a.autoTriggerUntil-1)&&0<a.totalPages-1)r(c),p(),0<a.autoTriggerUntil&&(a.autoTriggerUntil--,f("info","Auto Triggered Pages Remaining = "+a.autoTriggerUntil)),0<a.totalPages&&(a.totalPages--,f("info","Total Pages Remaining = "+a.totalPages));else if(_$document.off("scrollstop"),!1===a.footerVisible&&b(a.footerSelector).show(),0<a.totalPages-1)c.on("click",function(){r(c);u();a.totalPages--;f("info","Total Pages Remaining = "+a.totalPages);return!1});else f("info","Total Pages Number Reached. Calling destroy()"),
b(a.nextSelector).remove(),k()}function p(){q();_$document.on("scrollstop",function(){if(!d.data("jmscroll").waiting&&_$window.scrollTop()+_$window.height()>_$document.height()-b(a.footerSelector).outerHeight()-a.footerPadding)return f("info",a.footerPadding+"px From '"+a.footerSelector+"'. Calling load()"),u()})}function u(){var c=d.find("div.scroll-wrapper").first(),l=d.data("jmscroll");l.waiting=!0;var g="",g="html"==a.progressType?'<div class="progress-div progress-html">'+a.loadingHtml+"</div>":
"spinner"==a.progressType?'<div class="progress-div progress-spinner"></div>':'<div class="progress-div progress-bar"><span></span></div>';c.append('<div class="scroll-added" />').children(".scroll-added").last().html(g);"spinner"==a.progressType&&(n.spin(),b(".progress-div").append(n.el));"bar"==a.progressType&&w();return d.animate({scrollTop:c.outerHeight()},a.loadingContentDelay,function(){c.find("div.scroll-added").last().load(l.nextHref,function(c,g,e){"spinner"==a.progressType&&n.stop();if("error"===
g)return f("error","Error Status Returned From load(). Calling destroy()"),!1===a.footerVisible&&b(a.footerSelector).show(),b(".progress-div").hide(),k();c=b(this).find(a.nextSelector).first();l.waiting=!1;l.nextHref=c.attr("href")?b.trim(c.attr("href")+" "+a.contentSelector):!1;b(".scroll-next-wrapper",d).remove();(c=d.data("jmscroll"))&&c.nextHref?t():(f("info","No More Data. Calling destroy()"),!1===a.footerVisible&&b(a.footerSelector).show(),k());a.callback&&a.callback.call(this)})})}function k(){return _$document.removeData("jmscroll").find(".scroll-wrapper").children().unwrap().filter(".scroll-added").children().unwrap()}
function w(){var c=0,d=setInterval(function(){c++;var g=c%100*b(".progress-div").width()/100;b(".progress-div").find("span").animate({width:g},a.progressBarSpeed);c*a.progressBarSpeed>a.loadingContentDelay&&clearInterval(d)},a.progressBarSpeed)}function f(c){if(a.debug&&"object"===typeof console&&("object"===typeof c||"function"===typeof console[c]))if("object"===typeof c){var b=[],d;for(d in c)"function"===typeof console[d]?(b=m[d].length?m[d]:[m[d]],console[d].apply(console,b)):console.log.apply(console,
b)}else console[c].apply(console,Array.prototype.slice.call(arguments,1))}var v=d.data("jmscroll"),a=b.extend({},b.jmscroll.defaults,"function"===typeof e?{callback:e}:e,v||{}),x=b.trim(d.find(a.nextSelector).first().attr("href")+" "+a.contentSelector);_$window=b(window);_$document=b(document);_$body=b("body");d.data("jmscroll",b.extend({},v,{initialized:!0,waiting:!1,nextHref:x}));!0===a.autoTrigger&&!1===a.footerVisible&&b(a.footerSelector).hide();q();"html"==a.progressType&&h();if("spinner"==a.progressType){var n;
n=new Spinner({lines:a.spinnerLines,length:a.spinnerLength,width:a.spinnerWidth,radius:a.spinnerRadius,corners:a.spinnerCorners,rotate:a.spinnerRotate,direction:a.spinnerDirection,color:a.spinnerColor,speed:a.spinnerSpeed,trail:a.spinnerTrail,shadow:a.spinnerShadow,hwaccel:a.spinnerHwaccel,className:a.spinnerClassName,zIndex:a.spinnerZIndex,top:a.spinnerTop,left:a.spinnerLeft})}t();b.extend(d.jmscroll,{destroy:k});return d};b.fn.jmscroll=function(d){return this.each(function(){var e=b(this),h=e.data("jmscroll");
h&&h.initialized||new p(e,d)})}})(jQuery);