diff options
| author | tdro <tdro@noreply.example.com> | 2024-08-01 00:00:00 +0000 |
|---|---|---|
| committer | tdro <tdro@noreply.example.com> | 2024-08-01 00:00:00 +0000 |
| commit | a98e81a9910013701670765fc0ca1fe90187ef38 (patch) | |
| tree | 1e2c7285981758fe38e4ab8c02bb7f87810704ab | |
| parent | ddb1104491ca6264d7235650de507618478acfef (diff) | |
| download | canory-a98e81a9910013701670765fc0ca1fe90187ef38.tar.gz canory-a98e81a9910013701670765fc0ca1fe90187ef38.tar.bz2 canory-a98e81a9910013701670765fc0ca1fe90187ef38.zip | |
static/js/infinitescroll: Check last
Add custom event
| -rw-r--r-- | assets/js/index.js | 11 | ||||
| -rw-r--r-- | static/js/forms.ts | 2 | ||||
| -rw-r--r-- | static/js/infinitescroll.ts | 10 |
3 files changed, 14 insertions, 9 deletions
diff --git a/assets/js/index.js b/assets/js/index.js index f89624b..7408b49 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -595,6 +595,7 @@ storage.initEvent("storage", true, true); [ "pageshow", + "FormsCustomEvent", "URLChangedCustomEvent", "DOMContentLoaded" ].forEach(function(event) { @@ -827,9 +828,10 @@ const pagination = document.querySelector('[data-type="pagination"]'); if (!pagination) return; const main = document.querySelector("main"); - const count = main.children.length; const next = pagination.querySelector('[rel="next"]'); - const end = pagination.querySelector('[rel="last"]').title === "hidden"; + const last = pagination.querySelector('[rel="last"]'); + if (!last) return; + const end = last.title === "hidden"; const asynchronous = document.querySelectorAll("[data-type='pagination']").length !== 1; if (end || asynchronous) return pagination.remove(); if (threshold && pagination.remove() === undefined) { @@ -838,7 +840,9 @@ const items = Array.prototype.slice.call(page.querySelector("main").children); const paginate = page.querySelector('[data-type="pagination"]'); for(let i1 = 0; i1 < items.length; i1++)main.appendChild(items[i1]); - console.log("INFO: Fetch", next.href, items); + self.document.dispatchEvent(new CustomEvent("FormsCustomEvent", { + bubbles: true + })); main.after(paginate); }, function(http) { console.warn("WARNING: Switching to native pagination", http); @@ -846,7 +850,6 @@ abort = true; }); } - console.log("INFO:", "r:", remaining, "t:", traversed, "j:", journey, "%:", ratio, "c:", count); }); }); })(); diff --git a/static/js/forms.ts b/static/js/forms.ts index 958cc9f..b7b4b44 100644 --- a/static/js/forms.ts +++ b/static/js/forms.ts @@ -7,7 +7,7 @@ const storage = document.createEvent("Event"); storage.initEvent("storage", true, true); - ["pageshow", "URLChangedCustomEvent", "DOMContentLoaded"].forEach(function (event) { + ["pageshow", "FormsCustomEvent", "URLChangedCustomEvent", "DOMContentLoaded"].forEach(function (event) { self.addEventListener(event, function (event) { const input = Array.prototype.slice.call(document.querySelectorAll("form input")); const select = Array.prototype.slice.call(document.querySelectorAll("form select")); diff --git a/static/js/infinitescroll.ts b/static/js/infinitescroll.ts index 50eb91c..99ece17 100644 --- a/static/js/infinitescroll.ts +++ b/static/js/infinitescroll.ts @@ -44,9 +44,12 @@ if (!pagination) return; const main = document.querySelector("main"); - const count = main.children.length; const next = pagination.querySelector('[rel="next"]'); - const end = pagination.querySelector('[rel="last"]').title === "hidden"; + const last = pagination.querySelector('[rel="last"]'); + + if (!last) return; + + const end = last.title === "hidden"; const asynchronous = document.querySelectorAll("[data-type='pagination']").length !== 1; if (end || asynchronous) return pagination.remove(); @@ -60,7 +63,7 @@ for (let i = 0; i < items.length; i++) main.appendChild(items[i]); - console.log("INFO: Fetch", next.href, items); + self.document.dispatchEvent(new CustomEvent("FormsCustomEvent", { bubbles: true })); main.after(paginate); @@ -70,7 +73,6 @@ abort = true; }); } - console.log("INFO:", "r:", remaining, "t:", traversed, "j:", journey, "%:", ratio, "c:", count); }); }); })(); |
