Skip to content

Commit 9a8af88

Browse files
committed
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 <mearajbhagad@gmail.com>
1 parent 415bd8b commit 9a8af88

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

files/site.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,26 @@ $(function() {
7575
}
7676
run.click(onRun);
7777
})
78+
79+
// Current workaround for the issue https://todo.sr.ht/~eliasnaur/gio/415
80+
// where keydown and keyup listeners don't work
81+
window.addEventListener('keydown', (e)=> {
82+
const frames = document.querySelectorAll('iframe')
83+
frames.forEach((frame)=> {
84+
const input = frame.contentDocument.querySelector('input')
85+
if (input) {
86+
input.dispatchEvent(new KeyboardEvent('keydown', {key:e.key}))
87+
}
88+
})
89+
});
90+
window.addEventListener('keyup', (e)=> {
91+
const frames = document.querySelectorAll('iframe')
92+
frames.forEach((frame)=> {
93+
const input = frame.contentDocument.querySelector('input')
94+
if (input) {
95+
input.dispatchEvent(new KeyboardEvent('keyup', {key:e.key}))
96+
}
97+
})
98+
});
7899
})
79100

0 commit comments

Comments
 (0)