{"version":3,"sources":["infinitescroll.js"],"names":["$","currentPage","pathname","window","location","$document","document","$result","buffer","ticking","isLoading","lastScrollY","scrollY","lastWindowHeight","innerHeight","lastDocumentHeight","height","onScroll","requestTick","onResize","requestAnimationFrame","infiniteScroll","path","paginationRegex","replace","match","parseInt","sanitizePathname","maxPages","removeEventListener","passive","nextPage","get","content","posts","createRange","createContextualFragment","querySelectorAll","length","forEach","call","post","appendChild","fail","xhr","status","always","addEventListener"],"mappings":"AAGAA,EAAE,SAAUA,GACR,IAAIC,EAAc,EACdC,EAAWC,OAAOC,SAASF,SAC3BG,EAAYL,EAAEM,UACdC,EAAUP,EAAE,cACZQ,EAAS,IAETC,GAAU,EACVC,GAAY,EAEZC,EAAcR,OAAOS,QACrBC,EAAmBV,OAAOW,YAC1BC,EAAqBV,EAAUW,SAEnC,SAASC,IACLN,EAAcR,OAAOS,QACrBM,IAGJ,SAASC,IACLN,EAAmBV,OAAOW,YAC1BC,EAAqBV,EAAUW,SAC/BE,IAGJ,SAASA,IACAT,GACDW,sBAAsBC,GAE1BZ,GAAU,EAsBd,SAASY,IAKL,GAHAnB,EArBJ,SAA0BoB,GACtB,IAAIC,EAAkB,yBAetB,OAZAD,EAAOA,EAAKE,QAAQ,UAAW,IAAIA,QAAQ,QAAS,MAM3CC,MAAMF,KACXtB,EAAcyB,SAASJ,EAAKG,MAAMF,GAAiB,IAEnDD,EAAOA,EAAKE,QAAQD,EAAiB,KAGlCD,EAKIK,CAAiBzB,IAGxBQ,EAKJ,GAAIC,EAAcE,GAAoBE,EAAqBP,EACvDC,GAAU,MADd,CAWA,GAAIR,GAAe2B,SAGf,OAFAzB,OAAO0B,oBAAoB,SAAUZ,EAAU,CAACa,SAAS,SACzD3B,OAAO0B,oBAAoB,SAAUV,GAIzCT,GAAY,EAMZ,IAAIqB,EAAW7B,EAAW,SAH1BD,GAAe,GAGmC,IAElDD,EAAEgC,IAAID,EAAU,SAAUE,GACtB,IACIC,EADQ5B,SAAS6B,cAAcC,yBAAyBH,GAC1CI,iBAAiB,SAC/BH,EAAMI,QACN,GAAGC,QAAQC,KAAKN,EAAO,SAAUO,GAC7BlC,EAAQ,GAAGmC,YAAYD,OAGhCE,KAAK,SAAUC,GAEK,MAAfA,EAAIC,SACJ1C,OAAO0B,oBAAoB,SAAUZ,EAAU,CAACa,SAAS,IACzD3B,OAAO0B,oBAAoB,SAAUV,MAE1C2B,OAAO,WACN/B,EAAqBV,EAAUW,SAE/BP,EADAC,GAAY,KAKpBP,OAAO4C,iBAAiB,SAAU9B,EAAU,CAACa,SAAS,IACtD3B,OAAO4C,iBAAiB,SAAU5B,GAElCE","file":"infinitescroll.js","sourcesContent":["/* global maxPages */\n\n// Code snippet inspired by https://github.com/douglasrodrigues5/ghost-blog-infinite-scroll\n$(function ($) {\n    var currentPage = 1;\n    var pathname = window.location.pathname;\n    var $document = $(document);\n    var $result = $('.post-feed');\n    var buffer = 300;\n\n    var ticking = false;\n    var isLoading = false;\n\n    var lastScrollY = window.scrollY;\n    var lastWindowHeight = window.innerHeight;\n    var lastDocumentHeight = $document.height();\n\n    function onScroll() {\n        lastScrollY = window.scrollY;\n        requestTick();\n    }\n\n    function onResize() {\n        lastWindowHeight = window.innerHeight;\n        lastDocumentHeight = $document.height();\n        requestTick();\n    }\n\n    function requestTick() {\n        if (!ticking) {\n            requestAnimationFrame(infiniteScroll);\n        }\n        ticking = true;\n    }\n\n    function sanitizePathname(path) {\n        var paginationRegex = /(?:page\\/)(\\d)(?:\\/)$/i;\n\n        // remove hash params from path\n        path = path.replace(/#(.*)$/g, '').replace('////g', '/');\n\n        // remove pagination from the path and replace the current pages\n        // with the actual requested page. E. g. `/page/3/` indicates that\n        // the user actually requested page 3, so we should request page 4\n        // next, unless it's the last page already.\n        if (path.match(paginationRegex)) {\n            currentPage = parseInt(path.match(paginationRegex)[1]);\n\n            path = path.replace(paginationRegex, '');\n        }\n\n        return path;\n    }\n\n    function infiniteScroll() {\n        // sanitize the pathname from possible pagination or hash params\n        pathname = sanitizePathname(pathname);\n\n        // return if already loading\n        if (isLoading) {\n            return;\n        }\n\n        // return if not scroll to the bottom\n        if (lastScrollY + lastWindowHeight <= lastDocumentHeight - buffer) {\n            ticking = false;\n            return;\n        }\n\n        /**\n        * maxPages is defined in default.hbs and is the value\n        * of the amount of pagination pages.\n        * If we reached the last page or are past it,\n        * we return and disable the listeners.\n        */\n        if (currentPage >= maxPages) {\n            window.removeEventListener('scroll', onScroll, {passive: true});\n            window.removeEventListener('resize', onResize);\n            return;\n        }\n\n        isLoading = true;\n\n        // next page\n        currentPage += 1;\n\n        // Load more\n        var nextPage = pathname + 'page/' + currentPage + '/';\n\n        $.get(nextPage, function (content) {\n            var parse = document.createRange().createContextualFragment(content);\n            var posts = parse.querySelectorAll('.post');\n            if (posts.length) {\n                [].forEach.call(posts, function (post) {\n                    $result[0].appendChild(post);\n                });\n            }\n        }).fail(function (xhr) {\n            // 404 indicates we've run out of pages\n            if (xhr.status === 404) {\n                window.removeEventListener('scroll', onScroll, {passive: true});\n                window.removeEventListener('resize', onResize);\n            }\n        }).always(function () {\n            lastDocumentHeight = $document.height();\n            isLoading = false;\n            ticking = false;\n        });\n    }\n\n    window.addEventListener('scroll', onScroll, {passive: true});\n    window.addEventListener('resize', onResize);\n\n    infiniteScroll();\n});\n"]}