diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2021-11-23 00:38:06 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2021-11-23 00:38:06 +0100 |
| commit | 090e6aaa177d97b9bca426793af26dc34711d77a (patch) | |
| tree | 2946bb9af2e40bfe637d9313de3c24d9d4ccadc0 | |
| parent | 1773e20839c75a01fd14af3015c0a054c5b83807 (diff) | |
Break out close function from close element onclick
| -rw-r--r-- | example/static/js/media.js | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/example/static/js/media.js b/example/static/js/media.js index e7ae59d..adcfab1 100644 --- a/example/static/js/media.js +++ b/example/static/js/media.js @@ -98,15 +98,19 @@ window.onpopstate = function(event) { } }; +function close_viewer() { + let slash = window.location.pathname.lastIndexOf('/') + let new_path = window.location.pathname.substring(0, slash + 1); + window.location.assign(window.location.protocol + "//" + + window.location.host + new_path); +} + document.addEventListener('DOMContentLoaded', (event) => { show_from_query_string(); document.getElementById('close').onclick = function(event) { - let slash = window.location.pathname.lastIndexOf('/') - let new_path = window.location.pathname.substring(0, slash); - window.location.assign(window.location.protocol + "//" + - window.location.host + new_path); + close_viewer(); return false; }; }); @@ -121,7 +125,7 @@ document.addEventListener('keydown', (event) => { } else if (event.key == 'ArrowRight') { document.getElementById('next').onclick(); } else if (event.key == 'Escape') { - document.getElementById('close').onclick(); + close_viewer(); } else if (event.key == 'D') { document.getElementById('download').onclick(); } |
