-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadbox.js
More file actions
53 lines (43 loc) · 1.3 KB
/
readbox.js
File metadata and controls
53 lines (43 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var parentBox = document.getElementById("parent");
var entryBox = document.getElementById("entrybox");
var valueBox = document.getElementById("valuebox");
var inputBox = document.getElementById("inputbox");
var activateBox = document.getElementById("activate");
function isChildFrom(node, parent) {
while (node !== null && node.parentNode) {
if (node === window || node === document.documentElement) {
return false;
}
if (node === parent) {
return true;
}
node = node.parentNode;
}
return false;
}
function keypress(evt) {
var target = evt.target;
if (!isChildFrom(target, parentBox)) {
return true;
}
entryBox.textContent += String.fromCharCode(evt.charCode);
valueBox.textContent = inputBox.value + String.fromCharCode(evt.charCode);
return false;
}
function steal() {
}
function activateTheft(evt) {
var box = evt.target;
var newSetting = box.checked;
if (newSetting) {
steal();
}
}
function textChanged(evt) {
if (isChildFrom(evt.target, parentBox)) {
valueBox.textContent = "Change event:" + inputBox.value;
}
}
window.addEventListener("keypress", keypress, true);
window.addEventListener("change", textChanged, true);
activateBox.addEventListener("change", activateTheft, true);