blob: 4c2598841b71a109b753a1cd22e624136936adf2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
import * as api from 'api';
import * as sfw from 'sfw';
const { Div, Img } = sfw.element.native;
const css = await sfw.css(import.meta.url, './index.css')
export default class Image extends sfw.element.Container {
#container
#image
#menu
#id
constructor() {
super ({ css })
this.body.append(
this.#container = Div.new({
id: 'container',
children: [
this.#image = Img.new({
onload: () => this.#container.classList.add('loaded'),
}),
Div.new({ id: 'loading' }),
this.#menu = Div.new({
id: 'menu',
children: [
Div.new({
id: 'delete',
innerText: 'Delete',
onclick: () => {
api.images.remove(this.#id);
this.parentNode.removeChild(this);
}
}),
]
})
],
oncontextmenu: (e) => {
this.#menu.classList.toggle('open');
e.preventDefault();
}
})
);
}
set id(id) {
this.#id = id;
this.#container.classList.remove('loaded');
}
load() {
if (!this.#image.src) {
this.#image.src = `/api/image/load/${this.#id}`;
}
}
}
|