-
Notifications
You must be signed in to change notification settings - Fork 0
/
20_basic_javasctipt_header
90 lines (88 loc) · 2.74 KB
/
20_basic_javasctipt_header
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<script>
var handled = false,
reveals = document.getElementsByClassName("reveal"),
clr = window.getComputedStyle(reveals[0]).color,
bg = window.getComputedStyle(reveals[0]).background,
holder = [];
hint = document.getElementById("hint");
if (hint) {hintText = hint.innerHTML;}
extra = document.getElementById("extra");
if (extra) {extraText = extra.innerHTML;}
if (extra || hint) {extraStep = 1;} else {extraStep = 0;}
for (i = 0; i < reveals.length; ++i) {holder.push(reveals[i].innerHTML);}
if (reveals.length > 1) {
for (i = 0; i < reveals.length; ++i) {
//reveals[i].style.background = clr;
//reveals[i].style.fontWeight = "bold";
clozeChildren = reveals[i].getElementsByTagName("*");
//for (j = 1; j < clozeChildren.length; ++j) {clozeChildren[j].style.background = clr;}
reveals[i].innerHTML = "[|||]";
}
for (i = 0; i < reveals.length; ++i) {
(function(j) {
reveals[j].onclick = function() {
this.innerHTML = holder[j];
//this.style.fontWeight = "normal";
this.style.background = bg;
clozeChildren = this.getElementsByTagName("*");
for (k = 1; k < clozeChildren.length; ++k) {
clozeChildren[k].style.background = bg;
}
this.style.cursor = 'text';
}
})(i);
reveals[i].style.cursor = 'help';
}
if (hint) {
hint.innerHTML = 'HINT';
hint.onclick = function() {
this.innerHTML = hintText;
}
}
if (extra) {
extra.innerHTML = '<hr>[more info]';
extra.onclick = function() {
this.innerHTML = extraText;
}
}
}
document.onkeypress = function(ev) {
if (handled) return false;
}
document.onkeydown = function() {
if (reveals.length > 1) {
for (i = 0; i < reveals.length + extraStep; ++i) {
if ((event.which == 32 || event.which == 37 || event.which == 38 || event.which == 39 || event.which == 40 || event.which == 13) && i < reveals.length) {
if (reveals[i].style.background != bg || reveals[i].innerHTML == "[|||]") {
reveals[i].innerHTML = holder[i];
//reveals[i].style.fontWeight = "normal";
reveals[i].style.background = bg;
clozeChildren = reveals[i].getElementsByTagName("*");
for (j = 1; j < clozeChildren.length; ++j) {
clozeChildren[j].style.background = bg;
}
handled = true;
return false
}
}
if ((event.which == 32 || event.which == 37 || event.which == 38 || event.which == 39 || event.which == 40 || event.which == 13) && i == reveals.length) {
if ((extra && extra.innerHTML != extraText) || (hint && hint.innerHTML != hintText)) {
if (hint) {
hint.innerHTML = hintText;
}
if (extra) {
extra.innerHTML = extraText;
}
handled = true;
return false
}
}
}
}
handled = false;
return true;
}
window.setTimeout(function() {
window.focus()
}, 0);
</script>