diff --git a/assets/built/infinitescroll.js b/assets/built/infinitescroll.js index d11af784..5f511ca2 100644 --- a/assets/built/infinitescroll.js +++ b/assets/built/infinitescroll.js @@ -1,2 +1,2 @@ -$(function(t){var o=1,r=window.location.pathname,a=t(document),s=t(".post-feed"),c=300,l=!1,w=!1,d=window.scrollY,v=window.innerHeight,u=a.height();function f(){d=window.scrollY,e()}function g(){v=window.innerHeight,u=a.height(),e()}function e(){l||requestAnimationFrame(n),l=!0}function n(){var e,n;if(n=/(?:page\/)(\d)(?:\/)$/i,(e=(e=r).replace(/#(.*)$/g,"").replace("////g","/")).match(n)&&(o=parseInt(e.match(n)[1]),e=e.replace(n,"")),r=e,!w)if(d+v<=u-c)l=!1;else{if(o>=maxPages)return window.removeEventListener("scroll",f,{passive:!0}),void window.removeEventListener("resize",g);w=!0;var i=r+"page/"+(o+=1)+"/";t.get(i,function(e){var n=document.createRange().createContextualFragment(e).querySelectorAll(".post");n.length&&[].forEach.call(n,function(e){s[0].appendChild(e)})}).fail(function(e){404===e.status&&(window.removeEventListener("scroll",f,{passive:!0}),window.removeEventListener("resize",g))}).always(function(){u=a.height(),l=w=!1})}}window.addEventListener("scroll",f,{passive:!0}),window.addEventListener("resize",g),n()}); +$(function(t){var o=1,r=window.location.pathname,a=t(document),s=t(".gh-postfeed"),c=300,l=!1,w=!1,d=window.scrollY,v=window.innerHeight,u=a.height();function f(){d=window.scrollY,e()}function g(){v=window.innerHeight,u=a.height(),e()}function e(){l||requestAnimationFrame(n),l=!0}function n(){var e,n;if(n=/(?:page\/)(\d)(?:\/)$/i,(e=(e=r).replace(/#(.*)$/g,"").replace("////g","/")).match(n)&&(o=parseInt(e.match(n)[1]),e=e.replace(n,"")),r=e,!w)if(d+v<=u-c)l=!1;else{if(o>=maxPages)return window.removeEventListener("scroll",f,{passive:!0}),void window.removeEventListener("resize",g);w=!0;var i=r+"page/"+(o+=1)+"/";t.get(i,function(e){var n=document.createRange().createContextualFragment(e).querySelectorAll(".post");n.length&&[].forEach.call(n,function(e){s[0].appendChild(e)})}).fail(function(e){404===e.status&&(window.removeEventListener("scroll",f,{passive:!0}),window.removeEventListener("resize",g))}).always(function(){u=a.height(),l=w=!1})}}window.addEventListener("scroll",f,{passive:!0}),window.addEventListener("resize",g),n()}); //# sourceMappingURL=infinitescroll.js.map \ No newline at end of file diff --git a/assets/built/infinitescroll.js.map b/assets/built/infinitescroll.js.map index 1ae7170f..c7e53a0a 100644 --- a/assets/built/infinitescroll.js.map +++ b/assets/built/infinitescroll.js.map @@ -1 +1 @@ -{"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 = $('.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"],"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,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,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,EAAKE,QAAQD,EAAiB,KAQzCrB,EALOoB,GAQHZ,EAKJ,GAAIC,EAAcE,GAAoBE,EAAqBP,EACvDC,GAAU,MADd,CAWA,GAAIR,GAAe0B,SAGf,OAFAxB,OAAOyB,oBAAoB,SAAUX,EAAU,CAACY,SAAS,SACzD1B,OAAOyB,oBAAoB,SAAUT,GAIzCT,GAAY,EAMZ,IAAIoB,EAAW5B,EAAW,SAH1BD,GAAe,GAGmC,IAElDD,EAAE+B,IAAID,EAAU,SAAUE,GACtB,IACIC,EADQ3B,SAAS4B,cAAcC,yBAAyBH,GAC1CI,iBAAiB,SAC/BH,EAAMI,QACN,GAAGC,QAAQC,KAAKN,EAAO,SAAUO,GAC7BjC,EAAQ,GAAGkC,YAAYD,OAGhCE,KAAK,SAAUC,GAEK,MAAfA,EAAIC,SACJzC,OAAOyB,oBAAoB,SAAUX,EAAU,CAACY,SAAS,IACzD1B,OAAOyB,oBAAoB,SAAUT,MAE1C0B,OAAO,WACN9B,EAAqBV,EAAUW,SAE/BP,EADAC,GAAY,KAKpBP,OAAO2C,iBAAiB,SAAU7B,EAAU,CAACY,SAAS,IACtD1B,OAAO2C,iBAAiB,SAAU3B,GAElCE"} \ No newline at end of file +{"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","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,EAAKE,QAAQD,EAAiB,KAQzCrB,EALOoB,GAQHZ,EAKJ,GAAIC,EAAcE,GAAoBE,EAAqBP,EACvDC,GAAU,MADd,CAWA,GAAIR,GAAe0B,SAGf,OAFAxB,OAAOyB,oBAAoB,SAAUX,EAAU,CAACY,SAAS,SACzD1B,OAAOyB,oBAAoB,SAAUT,GAIzCT,GAAY,EAMZ,IAAIoB,EAAW5B,EAAW,SAH1BD,GAAe,GAGmC,IAElDD,EAAE+B,IAAID,EAAU,SAAUE,GACtB,IACIC,EADQ3B,SAAS4B,cAAcC,yBAAyBH,GAC1CI,iBAAiB,SAC/BH,EAAMI,QACN,GAAGC,QAAQC,KAAKN,EAAO,SAAUO,GAC7BjC,EAAQ,GAAGkC,YAAYD,OAGhCE,KAAK,SAAUC,GAEK,MAAfA,EAAIC,SACJzC,OAAOyB,oBAAoB,SAAUX,EAAU,CAACY,SAAS,IACzD1B,OAAOyB,oBAAoB,SAAUT,MAE1C0B,OAAO,WACN9B,EAAqBV,EAAUW,SAE/BP,EADAC,GAAY,KAKpBP,OAAO2C,iBAAiB,SAAU7B,EAAU,CAACY,SAAS,IACtD1B,OAAO2C,iBAAiB,SAAU3B,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 = $('.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"]} \ No newline at end of file diff --git a/assets/js/infinitescroll.js b/assets/js/infinitescroll.js index fa72c85f..0ae567b0 100644 --- a/assets/js/infinitescroll.js +++ b/assets/js/infinitescroll.js @@ -5,7 +5,7 @@ $(function ($) { var currentPage = 1; var pathname = window.location.pathname; var $document = $(document); - var $result = $('.post-feed'); + var $result = $('.gh-postfeed'); var buffer = 300; var ticking = false;