syriastreet.com/assets/js/lib/jquery.jscroll.js

1 line
3.2 KiB
JavaScript
Raw Normal View History

2023-10-06 21:29:45 +00:00
!function(h){"use strict";h.jscroll={defaults:{debug:!1,autoTrigger:!0,autoTriggerUntil:!1,loadingHtml:"<small>Loading...</small>",loadingFunction:!1,padding:0,nextSelector:"a:last",contentSelector:"",pagingSelector:"",callback:!1}};function l(r,t){function e(t){i.pagingSelector?t.closest(i.pagingSelector).hide():t.parent().not(".jscroll-inner,.jscroll-added").addClass("jscroll-next-parent").hide().length||t.wrap('<div class="jscroll-next-parent" />').parent().hide()}function l(){if(r.is(":visible")){f();var t=r.find("div.jscroll-inner").first(),n=r.data("jscroll"),e=parseInt(r.css("borderTopWidth"),10),e=isNaN(e)?0:e,e=parseInt(r.css("paddingTop"),10)+e,l=c?d.scrollTop():r.offset().top,o=t.length?t.offset().top:0,l=Math.ceil(l-o+d.height()+e);if(!n.waiting&&l+i.padding>=t.outerHeight())return j("info","jScroll:",t.outerHeight()-l,"from bottom. Loading next request..."),p()}}function n(){var t,n=r.find(i.nextSelector).first();n.length&&(i.autoTrigger&&(!1===i.autoTriggerUntil||0<i.autoTriggerUntil)?(e(n),t=s.height()-r.offset().top,(r.height()<t?r.height():t)<=(0<r.offset().top-a.scrollTop()?a.height()-(r.offset().top-h(window).scrollTop()):a.height())&&l(),d.unbind(".jscroll").bind("scroll.jscroll",l),0<i.autoTriggerUntil&&i.autoTriggerUntil--):(d.unbind(".jscroll"),n.bind("click.jscroll",function(){return e(n),p(),!1})))}var o=r.data("jscroll"),i=h.extend({},h.jscroll.defaults,"function"==typeof t?{callback:t}:t,o||{}),c="visible"===r.css("overflow-y"),t=r.find(i.nextSelector).first(),a=h(window),s=h("body"),d=c?a:r,t=h.trim(t.attr("href")+" "+i.contentSelector),f=function(){r.find(".jscroll-inner").length||r.contents().wrapAll('<div class="jscroll-inner" />')},g=function(){return d.unbind(".jscroll").removeData("jscroll").find(".jscroll-inner").children().unwrap().filter(".jscroll-added").children().unwrap()},u=function(t){return(t=t||r.data("jscroll"))&&t.nextHref?(n(),!0):(j("warn","jScroll: nextSelector not found - destroying"),g(),!1)},p=function(){var t=r.find("div.jscroll-inner").first(),e=r.data("jscroll");return e.waiting=!0,t.append('<div class="jscroll-added" />').children(".jscroll-added").last().html('<div class="jscroll-loading" id="jscroll-loading">'+i.loadingHtml+"</div>").promise().done(function(){i.loadingFunction&&i.loadingFunction()}),r.animate({scrollTop:t.outerHeight()},0,function(){t.find("div.jscroll-added").last().load(e.nextHref,function(t,n){if("error"===n)return g();n=h(this).find(i.nextSelector).first();e.waiting=!1,e.nextHref=!!n.attr("href")&&h.trim(n.attr("href")+" "+i.contentSelector),h(".jscroll-next-parent",r).remove(),u(),i.callback&&i.callback.call(this),j("dir",e)})})},j=function(t){if(i.debug&&"object"==typeof console&&("object"==typeof t||"function"==typeof console[t]))if("object"==typeof t){var n,e=[];for(n in t)("function"==typeof console[n]?(e=t[n].length?t[n]:[t[n]],console[n]):console.log).apply(console,e)}else console[t].apply(console,Array.prototype.slice.call(arguments,1))};return r.data("jscroll",h.extend({},o,{initialized:!0,waiting:!1,nextHref:t})),f(),(o=h(i.loadingHtml).filter("img").attr("src"))&&((new Image).src=o),n(),h.extend(r.jscroll,{destroy:g}),r}h.fn.jscroll=function(e){return this.each(function(){var t=h(this),n=t.data("jscroll");n&&n.initialized||l(t,e)})}}(jQuery);