-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
53 lines (48 loc) · 1.05 KB
/
script.js
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 code = []; // code
var txt = ""; // code in text
const crs = '<span id = "cursor">|</span>'; // cursor
var posCrs; // cursor position in the code
function init() {
console.log("Initiated");
var ed = document.getElementById("editor");
ed.innerHTML = crs;
document.addEventListener("keydown", function(event) {
const key = event.key;
event.preventDefault();
console.log(key, prcInput(key));
txt += prcInput(key);
ed.innerHTML = txt + crs;
// console.log(ed);
});
setCursor();
}
function prcInput(str) {
var rStr;
if (str == "Enter") {
rStr = "<br>";
} else if (str == "Tab") {
rStr = " ";
} else {
rStr = str;
}
return rStr;
}
function reset() {
txt = "";
document.getElementById("editor").innerHTML = crs;
}
function submit() {
}
function setCursor() {
v = true;
s = 500;
setInterval(function() {
if (v) {
v = false;
document.getElementById("cursor").style.opacity = 0;
} else {
v = true;
document.getElementById("cursor").style.opacity = 1;
}
}, s);
}