From 9a8af88e85855fceb7e5d651a8637a1d991eafc6 Mon Sep 17 00:00:00 2001 From: Mearaj Bhagad Date: Tue, 25 Jul 2023 17:30:15 +0530 Subject: [PATCH] files/site.js: forward key events to embedded examples For some reason most, probably iframes (may be event focus), the gio window inside iframe doesn't receives key events. In this commit, a global key event listener is added and it passes down key events to gio's window embedded inside iframes. Fixes: https://todo.sr.ht/~eliasnaur/gio/415 Signed-off-by: Mearaj Bhagad --- files/site.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/files/site.js b/files/site.js index c66a3f1..e13296d 100644 --- a/files/site.js +++ b/files/site.js @@ -75,5 +75,26 @@ $(function() { } run.click(onRun); }) + + // Current workaround for the issue https://todo.sr.ht/~eliasnaur/gio/415 + // where keydown and keyup listeners don't work + window.addEventListener('keydown', (e)=> { + const frames = document.querySelectorAll('iframe') + frames.forEach((frame)=> { + const input = frame.contentDocument.querySelector('input') + if (input) { + input.dispatchEvent(new KeyboardEvent('keydown', {key:e.key})) + } + }) + }); + window.addEventListener('keyup', (e)=> { + const frames = document.querySelectorAll('iframe') + frames.forEach((frame)=> { + const input = frame.contentDocument.querySelector('input') + if (input) { + input.dispatchEvent(new KeyboardEvent('keyup', {key:e.key})) + } + }) + }); })