From c448abd99a470e1ec541027077dcdef0745270d8 Mon Sep 17 00:00:00 2001 From: Feuerfuchs Date: Sun, 23 Jun 2019 17:29:07 +0200 Subject: Show expandable thumbnails for images --- js/main.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 js/main.ts (limited to 'js') 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 @@ +let linkQryEls = document.getElementsByClassName('link--QRY'); +let i = linkQryEls.length; +while (i--) { + linkQryEls[i].addEventListener('click', e => { + e.preventDefault(); + + const resp = prompt('Please enter required input: ', ''); + if ((resp !== null) && (resp !== "")) { + window.location.href = (e.target as HTMLAnchorElement).href + '?' + resp; + } + + return false; + }); +} + +let imgPreviewEls = document.getElementsByClassName('img-preview'); +i = imgPreviewEls.length; +while (i--) { + const imgPreviewEl = imgPreviewEls[i] as HTMLAnchorElement; + const child = imgPreviewEl.children[0] as HTMLImageElement; + const thumbnailUrl = child.src; + + child.addEventListener('load', e => { + child.classList.remove('faded'); + }); + + imgPreviewEls[i].addEventListener('click', e => { + e.preventDefault(); + + child.classList.add('faded'); + + if (child.classList.contains('expanded')) { + child.classList.remove('expanded'); + child.src = thumbnailUrl; + } else { + child.classList.add('expanded'); + child.src = imgPreviewEl.href; + } + + return false; + }); +} -- cgit v1.2.3-70-g09d2