mirror of
https://github.com/webodf/WebODF.git
synced 2026-11-30 16:47:58 +01:00
The textInput event provides a more accurate view of the resulting text from a key press on Chrome and Safari. Use this as the fallback if the key press event is ignored (e.g., user is inputing character code using the Mac OS option key or Windows alt key).
57 lines
1.8 KiB
HTML
57 lines
1.8 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>IME test harness</title>
|
|
</head>
|
|
<body>
|
|
<h1>Enter text using an IME into the box below</h1>
|
|
<div id="editArea" contenteditable="true" style="width: 100px; height: 100px; background-color: red"></div>
|
|
<pre id="log"></pre>
|
|
<script type="text/javascript">
|
|
var editArea = document.getElementById("editArea"),
|
|
log = document.getElementById("log"),
|
|
updateRequested = false,
|
|
cycleCount = 0;
|
|
|
|
function updateTick() {
|
|
if (updateRequested) {
|
|
updateRequested = false;
|
|
cycleCount++;
|
|
}
|
|
}
|
|
|
|
function logInfo(text) {
|
|
// log.insertBefore(document.createTextNode(text + " |cycle: " + cycleCount + "\n"), log.firstChild);
|
|
log.appendChild(document.createTextNode("cycle: " + cycleCount + "| " + text + "\n"));
|
|
updateRequested = true;
|
|
}
|
|
|
|
editArea.addEventListener("input", function() {
|
|
logInfo("input: " + editArea.textContent);
|
|
});
|
|
editArea.addEventListener("textInput", function(e) {
|
|
logInfo("textInput: " + e.data);
|
|
});
|
|
editArea.addEventListener("keydown", function(e) {
|
|
logInfo("keydown: " + String.fromCharCode(e.which));
|
|
});
|
|
editArea.addEventListener("keypress", function(e) {
|
|
logInfo("keypress: " + String.fromCharCode(e.which));
|
|
});
|
|
editArea.addEventListener("keyup", function(e) {
|
|
logInfo("keyup: " + String.fromCharCode(e.which));
|
|
});
|
|
editArea.addEventListener("compositionstart", function(e) {
|
|
logInfo("compositionstart: " + e.data);
|
|
});
|
|
editArea.addEventListener("compositionupdate", function(e) {
|
|
logInfo("compositionupdate: " + e.data);
|
|
});
|
|
editArea.addEventListener("compositionend", function(e) {
|
|
logInfo("compositionend: " + e.data);
|
|
});
|
|
|
|
setInterval(updateTick, 0);
|
|
</script>
|
|
</body>
|
|
</html> |