/*
# -----------------------------------------------------------------------------
# ~/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={type:"infiniteScroll",scrollOffset:100,elementScroll:!1,firstPage:2,lastPage:!1,infoLastPage:!1,loadStatus:!1,onInit:function(){},onBeforeLoad:function(){},onAfterLoad:function(){}};function s(t,n){this.element=t,this.settings=e.extend({},o,n),this.settings.elementID="#"+this.element.id,this.init(this.settings)}e.extend(s.prototype,{init:function(n){var i=this,o=log4javascript.getLogger("j1.scroller.core.init");if(o.info("\ninitializing plugin: started"),o.info("\nstate: started"),n.elementScroll?i.scroller=i.element:i.scroller=t,n.loadStatus){e('
').insertAfter(n.elementID)}if(n.infoLastPage){var s=n.lastPageInfo;e(s).insertAfter(n.elementID)}var r=setInterval(function(){"finished"===j1.getState()&&("infiniteScroll"===n.type&&(o.info("\nprocessing mode: "+n.type),o.info("\nloading items from path: "+n.pagePath),o.info("\nmonitoring element set to: "+this.scroller),i.registerScrollEvent(n)),"showOnScroll"===n.type&&(o.info("\nprocessing mode: "+n.type),o.info("\nloading items from path: "+n.pagePath),o.info("\nmonitoring element set to: "+this.scroller),i.registerScrollEvent(n)),o.info("\ninitializing plugin: finished"),o.info("\nstate: finished"),clearInterval(r))},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,f=l.height(),c=a+f;return a>=o&&ao&&c<=r||f>s&&a<=o&&c>=r}},isBottomReached:function(i){var o,s=e(i.elementID).height();if(this.settings.elementScroll){var r=e(t),l=r.scrollTop(),a=r.height(),f=l+a-i.scrollOffset,c=e(i.elementID),d=c.offset().top+s,g=c.height();return o=d+g,d>=l&&dl&&o<=f||g>a&&d<=l&&o>=f}return t.innerHeight+t.pageYOffset+i.scrollOffset>=n.body.offsetHeight},registerScrollEvent:function(n){var i=this,o=log4javascript.getLogger("j1.scroller.core.registerScrollEvent");"infiniteScroll"===n.type&&(o.info("\nregister scroll event of type: "+n.type),i[n.id]=function(e){var n=i.settings;if(i.isBottomReached(n)){if(n.firstPage>n.lastPage)return o.info("\nlast page detected on: "+n.lastPage),t.removeEventListener("scroll",i[n.id]),o.info("\nscroll event: removed"),n.infoLastPage&&i.infoLastPage(n),!1;i.getNewPost(n)}},t.addEventListener("scroll",i[n.id]),o.info("\nscroll event: registered")),"showOnScroll"===n.type&&(o.info("\nregister scroll event of type: "+n.type),i[n.id]=function(s){i.isInViewport(e("#"+n.id),n.scrollOffset)&&(o.info("\nspecified container is in view: "+n.id),e("."+n.id).show(n.showDelay),o.info("\nremove eventHandler"),t.removeEventListener("scroll",i[n.id]))},t.addEventListener("scroll",i[n.id]))},getNewPost:function(t){var n=this,i=log4javascript.getLogger("j1.scroller.core.getNewPost");if(i.debug("\ntrigger loading "),!1===this.itemsLoaded)return!1;this.itemsLoaded=!1,t.loadStatus&&(i.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=n.getChildItemsByAjaxHTML(t,o.responseText);n.appendNewItems(s),i.info("\nloading new items: successful"),t.loadStatus&&(i.info("\nhide: spinner"),e(".loader-ellips").hide()),n.itemsLoaded=!0}else t.loadStatus&&(i.info("\nhide: spinner"),e(".loader-ellips").hide()),i.error("\nloading new items failed, HTTP response: "+o.status),n.itemsLoaded=!1},i.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=n.createElement("html");return log4javascript.getLogger("j1.scroller.core.getChildItemsByAjaxHTML").debug("\nload new items"),i.innerHTML=t,i.querySelectorAll(e.elementID+" > *")},appendNewItems:function(e){var t=this,n=log4javascript.getLogger("j1.scroller.core.appendNewItems"),i=j1.getCookieNames(),o=j1.readCookie(i.user_translate);n.debug("\nappend new items"),e.forEach(function(e){t.element.appendChild(e)}),o.translationEnabled?(n.info("\ntranslation enabled: "+o.translationEnabled),n.warn("\nskipped processing of dropcaps")):(n.info("\npost processing: createDropCap"),j1.core.createDropCap())},infoLastPage:function(t){log4javascript.getLogger("j1.scroller.core.infoLastPage").info("\nshow: infoLastPage"),e(".page-scroll-last").show()}}),e.fn.scroller=function(t){return this.each(function(){e.data(this,"plugin_scroller")||e.data(this,"plugin_scroller",new s(this,t))})}}(jQuery,window,document);