aboutsummaryrefslogtreecommitdiff
path: root/static/pages/image-viewer/index.js
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2025-11-24 21:13:47 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2025-11-24 21:17:05 +0100
commitf3756dac8a49f3b5599fd50f4c631da4168e9eb0 (patch)
treea84d95e30269d4b368b741ffd1a781b7cfbb1988 /static/pages/image-viewer/index.js
parent97b35ce73fab8a84d4d3e6807618a252efcf4cd9 (diff)
add jump-to month
Diffstat (limited to 'static/pages/image-viewer/index.js')
-rw-r--r--static/pages/image-viewer/index.js17
1 files changed, 10 insertions, 7 deletions
diff --git a/static/pages/image-viewer/index.js b/static/pages/image-viewer/index.js
index 72af671..73b824e 100644
--- a/static/pages/image-viewer/index.js
+++ b/static/pages/image-viewer/index.js
@@ -15,9 +15,6 @@ export default class ImageViewer extends sfw.element.Container {
this.#images = [];
- this.onnewer = () => {}
- this.onolder = () => {}
-
this.body.append(
this.#container = Div.new({
id: 'container',
@@ -32,8 +29,8 @@ export default class ImageViewer extends sfw.element.Container {
);
}
- add(id) {
- const image = Image.new({ id });
+ add(metadata) {
+ const image = Image.new({ metadata });
this.#images.push(image);
this.#container.insertBefore(image, this.#subtitle);
@@ -45,10 +42,16 @@ export default class ImageViewer extends sfw.element.Container {
this.#container.append(this.#subtitle);
}
+ jump_to(month) {
+ const image = this.#images.find(i => i.month == month || i.month.is_same(month));
+ image.scrollIntoView({ behavior: 'instant' })
+ }
+
#preload(image) {
- const loading_zone = (this.#container.scrollTop + this.#container.offsetHeight) * 2;
+ const loading_zone_after = (this.#container.scrollTop + this.#container.offsetHeight) * 2;
+ const loading_zone_before = this.#container.scrollTop - (this.#container.offsetHeight - image.offsetHeight) * 2;
- if (image.offsetTop < loading_zone) {
+ if (loading_zone_before < image.offsetTop && image.offsetTop < loading_zone_after) {
image.load();
}
}