From f3756dac8a49f3b5599fd50f4c631da4168e9eb0 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Mon, 24 Nov 2025 21:13:47 +0100 Subject: add jump-to month --- static/pages/image-viewer/index.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'static/pages') 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(); } } -- cgit v1.2.3-70-g09d2