mind-overflow-website-ghost.../assets/built/infinitescroll.js.map

1 line
5.3 KiB
Plaintext

{"version":3,"file":"infinitescroll.js","sources":["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 = $('.gh-postfeed');\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"],"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","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,gBACZQ,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,IAnBT,IAA0BC,EAClBC,EAuBJ,GAvBIA,EAAkB,0BAGtBD,GAJsBA,EAqBMpB,GAjBhBsB,QAAQ,UAAW,IAAIA,QAAQ,QAAS,MAM3CC,MAAMF,KACXtB,EAAcyB,SAASJ,EAAKG,MAAMF,GAAiB,IAEnDD,EAAOA,E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