diff options
| author | tdro <tdro@noreply.example.com> | 2024-07-18 00:00:00 +0000 |
|---|---|---|
| committer | tdro <tdro@noreply.example.com> | 2024-07-18 00:00:00 +0000 |
| commit | 687c69af8d86b5787467dc5acaa6dc334fc1ba57 (patch) | |
| tree | 876d8d30db476f7a6c41072ea69a54f803f1dbc4 | |
| parent | ad0126e991b5e3060fbe282db624a6f33933a5dc (diff) | |
| download | canory-687c69af8d86b5787467dc5acaa6dc334fc1ba57.tar.gz canory-687c69af8d86b5787467dc5acaa6dc334fc1ba57.tar.bz2 canory-687c69af8d86b5787467dc5acaa6dc334fc1ba57.zip | |
static/js/infinitescroll: HTML collection create shallow copy
Fix remaining count
| -rw-r--r-- | assets/js/index.js | 6 | ||||
| -rw-r--r-- | static/js/infinitescroll.ts | 8 |
2 files changed, 7 insertions, 7 deletions
diff --git a/assets/js/index.js b/assets/js/index.js index 6f91634..962f093 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -839,7 +839,7 @@ const pagination = document.querySelector('[data-type="pagination"]'); if (!pagination) return; const main = document.querySelector("main"); - const count = main.childNodes.length; + const count = main.children.length; const next = pagination.querySelector('[rel="next"]'); const end = pagination.querySelector('[rel="last"]').title === "hidden"; const asynchronous = document.querySelectorAll("[data-type='pagination']").length !== 1; @@ -847,10 +847,10 @@ if (threshold && pagination.remove() === undefined) { fetch(next.href, "GET", function(http) { const page = new DOMParser().parseFromString(http.responseText, "text/html"); - const items = page.querySelector("main").children; + const items = Array.prototype.slice.call(page.querySelector("main").children); const paginate = page.querySelector('[data-type="pagination"]'); - console.log("INFO: Fetch", next.href, items); for(let i1 = 0; i1 < items.length; i1++)main.appendChild(items[i1]); + console.log("INFO: Fetch", next.href, items); main.after(paginate); }, function(http) { console.warn("WARNING: Switching to native pagination", http); diff --git a/static/js/infinitescroll.ts b/static/js/infinitescroll.ts index 15f2824..88d9828 100644 --- a/static/js/infinitescroll.ts +++ b/static/js/infinitescroll.ts @@ -48,7 +48,7 @@ if (!pagination) return; const main = document.querySelector("main"); - const count = main.childNodes.length; + const count = main.children.length; const next = pagination.querySelector('[rel="next"]'); const end = pagination.querySelector('[rel="last"]').title === "hidden"; const asynchronous = document.querySelectorAll("[data-type='pagination']").length !== 1; @@ -59,13 +59,13 @@ fetch(next.href, "GET", function (http) { const page = (new DOMParser()).parseFromString(http.responseText, "text/html"); - const items = page.querySelector("main").children; + const items = Array.prototype.slice.call(page.querySelector("main").children); const paginate = page.querySelector('[data-type="pagination"]'); - console.log("INFO: Fetch", next.href, items); - for (let i = 0; i < items.length; i++) main.appendChild(items[i]); + console.log("INFO: Fetch", next.href, items); + main.after(paginate); }, function (http) { |
