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