From 090e6aaa177d97b9bca426793af26dc34711d77a Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Tue, 23 Nov 2021 00:38:06 +0100 Subject: Break out close function from close element onclick --- example/static/js/media.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'example/static/js/media.js') 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(); } -- cgit v1.2.3-70-g09d2