diff options
author | Feuerfuchs <git@feuerfuchs.dev> | 2019-06-23 17:29:07 +0200 |
---|---|---|
committer | Feuerfuchs <git@feuerfuchs.dev> | 2019-06-23 17:29:07 +0200 |
commit | c448abd99a470e1ec541027077dcdef0745270d8 (patch) | |
tree | 433def56b6f0e81457cbe39fc85f402a9e4e18a8 /js | |
parent | Check type instead of file ext to render text via tpl (diff) | |
download | gopherproxy-c448abd99a470e1ec541027077dcdef0745270d8.tar.gz gopherproxy-c448abd99a470e1ec541027077dcdef0745270d8.tar.bz2 gopherproxy-c448abd99a470e1ec541027077dcdef0745270d8.zip |
Show expandable thumbnails for images
Diffstat (limited to 'js')
-rw-r--r-- | js/main.ts | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/js/main.ts b/js/main.ts new file mode 100644 index 0000000..21e589d --- /dev/null +++ b/js/main.ts | |||
@@ -0,0 +1,42 @@ | |||
1 | let linkQryEls = document.getElementsByClassName('link--QRY'); | ||
2 | let i = linkQryEls.length; | ||
3 | while (i--) { | ||
4 | linkQryEls[i].addEventListener('click', e => { | ||
5 | e.preventDefault(); | ||
6 | |||
7 | const resp = prompt('Please enter required input: ', ''); | ||
8 | if ((resp !== null) && (resp !== "")) { | ||
9 | window.location.href = (e.target as HTMLAnchorElement).href + '?' + resp; | ||
10 | } | ||
11 | |||
12 | return false; | ||
13 | }); | ||
14 | } | ||
15 | |||
16 | let imgPreviewEls = document.getElementsByClassName('img-preview'); | ||
17 | i = imgPreviewEls.length; | ||
18 | while (i--) { | ||
19 | const imgPreviewEl = imgPreviewEls[i] as HTMLAnchorElement; | ||
20 | const child = imgPreviewEl.children[0] as HTMLImageElement; | ||
21 | const thumbnailUrl = child.src; | ||
22 | |||
23 | child.addEventListener('load', e => { | ||
24 | child.classList.remove('faded'); | ||
25 | }); | ||
26 | |||
27 | imgPreviewEls[i].addEventListener('click', e => { | ||
28 | e.preventDefault(); | ||
29 | |||
30 | child.classList.add('faded'); | ||
31 | |||
32 | if (child.classList.contains('expanded')) { | ||
33 | child.classList.remove('expanded'); | ||
34 | child.src = thumbnailUrl; | ||
35 | } else { | ||
36 | child.classList.add('expanded'); | ||
37 | child.src = imgPreviewEl.href; | ||
38 | } | ||
39 | |||
40 | return false; | ||
41 | }); | ||
42 | } | ||