/* # ----------------------------------------------------------------------------- # ~/assets/themes/j1/modules//js/scroller.min.js # J1 core module for scroller # # Product/Info: # https://jekyll.one # # Copyright (C) 2021 Juergen Adams # # J1 Template is licensed under the MIT License. # For details, see https://jekyll.one # ----------------------------------------------------------------------------- */ (function(e,c,a,g){var d="scroller",f={type:"infiniteScroll",scrollOffset:100,elementScroll:false,firstPage:2,lastPage:false,infoLastPage:false,loadStatus:false,onInit:function(){},onBeforeLoad:function(){},onAfterLoad:function(){}};function b(i,h){this.element=i;this.settings=e.extend({},f,h);this.settings.elementID="#"+this.element.id;this.init(this.settings)}e.extend(b.prototype,{init:function(i){var m=this;var h=log4javascript.getLogger("");h.info("\ninitializing plugin: started");h.info("\nstate: started");if(i.elementScroll){m.scroller=m.element}else{m.scroller=c}if(i.loadStatus){var l='';e(l).insertAfter(i.elementID)}if(i.infoLastPage){var j=i.lastPageInfo;e(j).insertAfter(i.elementID)}var k=setInterval(function(){if(j1.getState()==="finished"){if(i.type==="infiniteScroll"){h.info("\nprocessing mode: "+i.type);h.info("\nloading items from path: "+i.pagePath+"#void");h.info("\nmonitoring element set to: "+this.scroller);m.registerScrollEvent(i)}if(i.type==="showOnScroll"){h.info("\nprocessing mode: "+i.type);h.info("\nloading items from path: "+i.pagePath+"#void");h.info("\nmonitoring element set to: "+this.scroller);m.registerScrollEvent(i)}h.info("\ninitializing plugin: finished");h.info("\nstate: finished");clearInterval(k)}})},isInViewport:function(n,m){if(n.length==0){return}var j=jQuery(c);var q=j.scrollTop();var i=j.height();var k=q+i;var l=jQuery(n);var o=l.offset().top+m;var p=l.height();var h=o+p;return(o>=q&&oq&&h<=k)||(p>i&&o<=q&&h>=k)},isBottomReached:function(s){var n=this;var h,p;var m=e(s.elementID).height();if(n.settings.elementScroll){var j=e(c);var r=j.scrollTop();var i=j.height();var l=r+i-s.scrollOffset;var k=e(s.elementID);var o=k.offset().top+m;var q=k.height();h=o+q;return(o>=r&&or&&h<=l)||(q>i&&o<=r&&h>=l)}else{return(c.innerHeight+c.pageYOffset+s.scrollOffset>=a.body.offsetHeight)}},registerScrollEvent:function(i){var j=this;var h=log4javascript.getLogger("");if(i.type==="infiniteScroll"){h.info("\nregister scroll event of type: "+i.type);j[i.id]=function(l){var k=j.settings;if(j.isBottomReached(k)){if(k.firstPage>k.lastPage){h.info("\nlast page detected on: "+k.lastPage);c.removeEventListener("scroll",j[k.id]);h.info("\nscroll event: removed");if(k.infoLastPage){j.infoLastPage(k)}return false}j.getNewPost(k)}};c.addEventListener("scroll",j[i.id]);h.info("\nscroll event: registered")}if(i.type==="showOnScroll"){h.info("\nregister scroll event of type: "+i.type);j[i.id]=function(k){if(j.isInViewport(e("#"+i.id),i.scrollOffset)){h.info("\nspecified container is in view: "+i.id);e("."+i.id).show(i.showDelay);h.info("\nremove eventHandler");c.removeEventListener("scroll",j[i.id])}};c.addEventListener("scroll",j[i.id])}},getNewPost:function(i){var k=this;var h=log4javascript.getLogger("");h.info("\ntrigger loading ");if(this.itemsLoaded===false){return false}this.itemsLoaded=false;if(i.loadStatus){h.info("\nshow: spinner");e(".loader-ellips").show()}var j=new XMLHttpRequest();j.onreadystatechange=function(){if(j.readyState==XMLHttpRequest.DONE){if(j.status==200){i.firstPage++;var l=k.getChildItemsByAjaxHTML(i,j.responseText);k.appendNewItems(l);h.info("\nloading new items: successful");if(i.loadStatus){h.info("\nhide: spinner");e(".loader-ellips").hide()}k.itemsLoaded=true}else{if(i.loadStatus){h.info("\nhide: spinner");e(".loader-ellips").hide()}h.error("\nloading new items failed, HTTP response: "+j.status);k.itemsLoaded=false}}};h.info("\nloading new items from path: "+i.pagePath+i.firstPage);j.open("GET",location.origin+i.pagePath+i.firstPage+"/index.html",true);j.send()},getChildItemsByAjaxHTML:function(j,i){var l=a.createElement("html");var h=log4javascript.getLogger("");h.info("\nload new items");l.innerHTML=i;var k=l.querySelectorAll(j.elementID+" > *");return k},appendNewItems:function(h){var l=this;var i=log4javascript.getLogger("");var k=j1.getCookieNames();var j=j1.readCookie(k.user_translate);i.info("\nappend new items");h.forEach(function(m){l.element.appendChild(m)});if(j.translationEnabled){i.info("\ntranslation enabled: "+j.translationEnabled);i.warn("\nskipped processing of dropcaps")}else{i.info("\npost processing: createDropCap");j1.core.createDropCap()}},infoLastPage:function(i){var j=this;var h=log4javascript.getLogger("");h.info("\nshow: infoLastPage");e(".page-scroll-last").show()}});e.fn[d]=function(h){return this.each(function(){if(!e.data(this,"plugin_"+d)){e.data(this,"plugin_"+d,new b(this,h))}})}})(jQuery,window,document);