From 5babf80537f6067743ccecb91a9e549207e8772b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Sat, 4 Feb 2023 23:12:40 +0100 Subject: [PATCH] lightbox: close on ESC #451 --- static/js/theme.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/static/js/theme.js b/static/js/theme.js index a9a49f47b6..a057bf7250 100644 --- a/static/js/theme.js +++ b/static/js/theme.js @@ -548,6 +548,13 @@ function initMenuScrollbar(){ adjustContentWidth(); } +function imageEscapeHandler( event ){ + if( event.key == "Escape" ){ + var image = event.target; + image.click(); + } +} + function sidebarEscapeHandler( event ){ if( event.key == "Escape" ){ var b = document.querySelector( 'body' ); @@ -752,6 +759,10 @@ function initSwipeHandler(){ document.querySelectorAll( '#sidebar *' ).forEach( function(e){ e.addEventListener("touchend", handleEndX); }, false); } +function initImage(){ + document.querySelectorAll( '.lightbox' ).forEach( function(e){ e.addEventListener("keydown", imageEscapeHandler); }, false); +} + function clearHistory() { var visitedItem = baseUriFull + 'visited-url/' for( var item in sessionStorage ){ @@ -1074,6 +1085,7 @@ ready( function(){ initSwipeHandler(); initHistory(); initSearch(); + initImage(); }); function useMermaid( config ){