{"version":3,"sources":["load-pagination-posts.js"],"names":["window","document","nextElement","querySelector","feedElement","loading","loadMoreButton","alternativeButton","addEventListener","xhr","XMLHttpRequest","responseType","onPageLoad","open","href","send","remove","this","response","querySelectorAll","forEach","item","appendChild","importNode","resNextElement","parentNode","append","style","display"],"mappings":"CAEA,SAAWA,EAAQC,GAEf,IAAIC,EAAcD,EAASE,cAAc,kBACzC,GAAKD,EAAL,CAKA,IAAIE,EAAcH,EAASE,cAAc,iBACzC,GAAKC,EAAL,CAIA,IAAIC,GAAU,EACVC,EAAiBL,EAASE,cAAc,qBACxCI,EAAoBN,EAASE,cAAc,sBA+C/CG,EAAeE,iBAAiB,SAjBhC,WAEI,IAAIH,EAAJ,CAIAA,GAAU,EAEV,IAAII,EAAM,IAAIT,EAAOU,eACrBD,EAAIE,aAAe,WAEnBF,EAAID,iBAAiB,OAAQI,GAE7BH,EAAII,KAAK,MAAOX,EAAYY,MAC5BL,EAAIM,KAAK,WA1Cb,SAASH,IAELN,EAAeU,SAEIC,KAAKC,SAASC,iBAAiB,kBACrCC,SAAQ,SAAUC,GAI3BjB,EAAYkB,YAAYrB,EAASsB,WAAWF,GAAM,OAItD,IAAIG,EAAiBP,KAAKC,SAASf,cAAc,kBAC7CqB,GACAtB,EAAYY,KAAOU,EAAeV,KAElCV,EAAYqB,WAAWC,OAAOpB,IACvBC,IAEPA,EAAkBoB,MAAMC,QAAU,UAClCxB,EAAYqB,WAAWC,OAAOnB,IAIlCF,GAAU,GA1ClB,CA+DGL,OAAQC","file":"load-pagination-posts.js","sourcesContent":["/* eslint-env browser */\n\n(function (window, document) {\n // next link element\n var nextElement = document.querySelector('link[rel=next]');\n if (!nextElement) {\n return;\n }\n\n // post feed element\n var feedElement = document.querySelector('.js-post-feed');\n if (!feedElement) {\n return;\n }\n\n var loading = false;\n var loadMoreButton = document.querySelector('.js-load-more-btn');\n var alternativeButton = document.querySelector('.js-end-pagination');\n\n function onPageLoad() {\n // get rid of the button, so we can append it at the bottom again\n loadMoreButton.remove();\n // append contents\n var postElements = this.response.querySelectorAll('.js-post-entry');\n postElements.forEach(function (item) {\n // document.importNode is important, without it the item's owner\n // document will be different which can break resizing of\n // `object-fit: cover` images in Safari\n feedElement.appendChild(document.importNode(item, true));\n });\n\n // set next link\n var resNextElement = this.response.querySelector('link[rel=next]');\n if (resNextElement) {\n nextElement.href = resNextElement.href;\n // put da button back to where it should be!\n feedElement.parentNode.append(loadMoreButton);\n } else if (alternativeButton) {\n // if we declared a button to show after pagination finished, append it now\n alternativeButton.style.display = 'inherit';\n feedElement.parentNode.append(alternativeButton);\n }\n\n // sync status\n loading = false;\n }\n\n function onClick() {\n // return if already loading\n if (loading) {\n return;\n }\n\n loading = true;\n\n var xhr = new window.XMLHttpRequest();\n xhr.responseType = 'document';\n\n xhr.addEventListener('load', onPageLoad);\n\n xhr.open('GET', nextElement.href);\n xhr.send(null);\n }\n\n loadMoreButton.addEventListener('click', onClick);\n})(window, document);\n"]}