-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This PR adds a new engine option (which is on by default) to grab the window focus when hosted in an iframe. This allows keyboard events to work by default. Confirmed on itch.io https://eonarheim.itch.io/iframe-test Closes #1512
- Loading branch information
Showing
9 changed files
with
131 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Frame</title> | ||
</head> | ||
<body> | ||
<script src="../../lib/excalibur.js"></script> | ||
<script src="./main.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<button>Other things that have focus</button> | ||
<iframe src="frame.html" width="600" height="400" frameborder="0"></iframe> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// window.focus(); | ||
// document.body.addEventListener('keydown', (evt) => { | ||
// console.log(evt.code); | ||
// }) | ||
|
||
|
||
var engine = new ex.Engine({ | ||
width: 600, | ||
height: 400 | ||
}); | ||
|
||
engine.input.keyboard.on('press', (evt) => { | ||
console.log(evt.key); | ||
}); | ||
|
||
engine.onPostDraw = (ctx: ex.ExcaliburGraphicsContext) => { | ||
const keys = engine.input.keyboard.getKeys(); | ||
ctx.debug.drawText(keys.join(','), ex.vec(200, 200)); | ||
} | ||
|
||
engine.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
|
||
/** | ||
* Checks if excalibur is in a x-origin iframe | ||
*/ | ||
export function isCrossOriginIframe() { | ||
try { | ||
// Try and listen to events on top window frame if within an iframe. | ||
// | ||
// See https://github.com/excaliburjs/Excalibur/issues/1294 | ||
// | ||
// Attempt to add an event listener, which triggers a DOMException on | ||
// cross-origin iframes | ||
const noop = () => { | ||
return; | ||
}; | ||
window.top.addEventListener('blur', noop); | ||
window.top.removeEventListener('blur', noop); | ||
} catch { | ||
return true; | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters