aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2024-08-03 00:00:00 +0000
committertdro <tdro@noreply.example.com>2024-08-03 00:00:00 +0000
commite70816dc7cc8d9dda313909b63787bac2ff3bb6f (patch)
tree8eb58cd4308d8d52a0d25c6dd4e7f920dfdd831d
parenta98e81a9910013701670765fc0ca1fe90187ef38 (diff)
downloadcanory-e70816dc7cc8d9dda313909b63787bac2ff3bb6f.tar.gz
canory-e70816dc7cc8d9dda313909b63787bac2ff3bb6f.tar.bz2
canory-e70816dc7cc8d9dda313909b63787bac2ff3bb6f.zip
static/js/fixedsearch: Remove leak
Check filter location
-rw-r--r--assets/js/index.js36
-rw-r--r--static/js/domfilter.ts2
-rw-r--r--static/js/fixedsearch.ts44
3 files changed, 43 insertions, 39 deletions
diff --git a/assets/js/index.js b/assets/js/index.js
index 7408b49..694faa1 100644
--- a/assets/js/index.js
+++ b/assets/js/index.js
@@ -385,22 +385,24 @@
}
}
});
- let scrolls = 0;
- self.addEventListener("scroll", function() {
- if (scrolls > 3) {
- scrolls = 0;
- document.activeElement.blur();
- dropdown.setAttribute("hidden", "");
- container.removeAttribute("data-focus");
- }
- scrolls++;
- });
- self.addEventListener("click", function(event) {
- if (!form.contains(event.target) && !(document.activeElement === query) && !(document.activeElement === submit)) {
- dropdown.setAttribute("hidden", "");
- container.removeAttribute("data-focus");
- }
- });
+ if (event === "DOMContentLoaded") {
+ let scrolls = 0;
+ self.addEventListener("scroll", function() {
+ if (scrolls > 3) {
+ scrolls = 0;
+ document.activeElement.blur();
+ dropdown.setAttribute("hidden", "");
+ container.removeAttribute("data-focus");
+ }
+ scrolls++;
+ });
+ self.addEventListener("click", function(event) {
+ if (!form.contains(event.target) && !(document.activeElement === query) && !(document.activeElement === submit)) {
+ dropdown.setAttribute("hidden", "");
+ container.removeAttribute("data-focus");
+ }
+ });
+ }
function fetch(url, callback) {
const http = new XMLHttpRequest();
http.onreadystatechange = function() {
@@ -756,7 +758,7 @@
persist();
});
self.addEventListener("popstate", function(event) {
- if (localStorage[key] !== state) return;
+ if (localStorage[key] !== state || !document.querySelector('link[rel="location"]')) return;
const link = JSON.parse(document.querySelector('link[rel="location"]').target);
const url = event.target.location;
const hashed = link.pathname === url.pathname;
diff --git a/static/js/domfilter.ts b/static/js/domfilter.ts
index c972bf1..2be690d 100644
--- a/static/js/domfilter.ts
+++ b/static/js/domfilter.ts
@@ -95,7 +95,7 @@
});
self.addEventListener("popstate", function (event) {
- if (localStorage[key] !== state) return;
+ if (localStorage[key] !== state || !document.querySelector('link[rel="location"]')) return;
const link = JSON.parse(document.querySelector('link[rel="location"]').target);
const url = event.target.location;
const hashed = link.pathname === url.pathname;
diff --git a/static/js/fixedsearch.ts b/static/js/fixedsearch.ts
index 04d318b..54916aa 100644
--- a/static/js/fixedsearch.ts
+++ b/static/js/fixedsearch.ts
@@ -121,28 +121,30 @@
}
});
- let scrolls = 0;
-
- self.addEventListener("scroll", function () {
- if (scrolls > 3) {
- scrolls = 0;
- document.activeElement.blur();
- dropdown.setAttribute("hidden", "");
- container.removeAttribute("data-focus");
- }
- scrolls++;
- });
+ if (event === "DOMContentLoaded") {
+ let scrolls = 0;
- self.addEventListener("click", function (event) {
- if (
- !form.contains(event.target) &&
- !(document.activeElement === query) &&
- !(document.activeElement === submit)
- ) {
- dropdown.setAttribute("hidden", "");
- container.removeAttribute("data-focus");
- }
- });
+ self.addEventListener("scroll", function () {
+ if (scrolls > 3) {
+ scrolls = 0;
+ document.activeElement.blur();
+ dropdown.setAttribute("hidden", "");
+ container.removeAttribute("data-focus");
+ }
+ scrolls++;
+ });
+
+ self.addEventListener("click", function (event) {
+ if (
+ !form.contains(event.target) &&
+ !(document.activeElement === query) &&
+ !(document.activeElement === submit)
+ ) {
+ dropdown.setAttribute("hidden", "");
+ container.removeAttribute("data-focus");
+ }
+ });
+ }
function fetch(url, callback) {
const http = new XMLHttpRequest();