diff options
author | tdro <tdro@noreply.example.com> | 2024-01-13 20:33:21 -0500 |
---|---|---|
committer | tdro <tdro@noreply.example.com> | 2024-01-13 20:33:21 -0500 |
commit | 30d33a9eedca8ae4b2e6082b915579c309f8b52c (patch) | |
tree | 3ade16a8c0ff1fa5d701d8bb8f0ad10701142b2d /static/js/timeago.ts | |
parent | 0e7a8c8c1984f5394fd825ac9405679648c88e99 (diff) | |
download | canory-30d33a9eedca8ae4b2e6082b915579c309f8b52c.tar.gz canory-30d33a9eedca8ae4b2e6082b915579c309f8b52c.tar.bz2 canory-30d33a9eedca8ae4b2e6082b915579c309f8b52c.zip |
static/js: Prepare custom URL changed event
Set key on pager and always clear interval
Diffstat (limited to 'static/js/timeago.ts')
-rw-r--r-- | static/js/timeago.ts | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/static/js/timeago.ts b/static/js/timeago.ts index 57eb16e..af8f6f5 100644 --- a/static/js/timeago.ts +++ b/static/js/timeago.ts @@ -8,7 +8,7 @@ style: "long", }); - function viewport(element, options = { offset: 100 }) { + function viewport(element, options = { offset: 250 }) { const view = element.getBoundingClientRect(); return view.top >= -options.offset && view.left >= -options.offset @@ -45,14 +45,13 @@ if (element.dataset.type === "default") { tiny = function (string) { return string; }; } if (element.dataset.type === "localDate") { - return element.textContent = new Intl.DateTimeFormat([], { - dateStyle: "medium", - }).format(time).replace(",", ""); + return element.textContent = new Intl.DateTimeFormat([], { dateStyle: "medium", }).format(time).replace(",", ""); } if (element.dataset.type === "localTime") { return element.textContent = new Intl.DateTimeFormat([], { - hour12: false, timeStyle: "short", + hour12: false, + timeStyle: "short", }).format(time) + " " + new Intl.DateTimeFormat([], { timeZoneName: "short" }).format(time).split(" ")[1]; } @@ -78,8 +77,10 @@ const substitution = setInterval(date, 4); - self.addEventListener("scroll", function () { - date("viewport"); + ["scroll", "URLChangedCustomEvent"].forEach(function (event) { + self.addEventListener(event, function () { + date("viewport"); + }); }); self.addEventListener("DOMContentLoaded", function () { |