Skip to content

Commit

Permalink
files/site.js: forward key events to embedded examples
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mearaj committed Aug 1, 2023
1 parent 415bd8b commit 9a8af88
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions files/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}))
}
})
});
})

0 comments on commit 9a8af88

Please sign in to comment.