-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
54 lines (46 loc) · 1.45 KB
/
script.js
File metadata and controls
54 lines (46 loc) · 1.45 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
54
const left = document.querySelector(".left"),
right = document.querySelector(".right"),
bar = document.querySelector(".bar"),
editor = document.querySelector(".editor"),
run = document.querySelector(".btn-run"),
iframe = document.querySelector(".iframe"),
darkMode = document.querySelector(".btn-dark"),
lightMode = document.querySelector(".btn-light");
const drag = (e) => {
e.preventDefault();
document.selection
? document.selection.empty()
: window.getSelection().removeAllRanges();
left.style.width = e.pageX - bar.offsetWidth / 3 + "px";
editor.ariaSetSize();
};
bar.addEventListener("mousedown", () => {
document.addEventListener("mousemove", drag);
});
bar.addEventListener("mouseup", () => {
document.removeEventListener("mousemove", drag);
});
//Run btn evenlistener
run.addEventListener("click", () => {
const html = editor.textContent;
iframe.src = "data:text/html;charset=utf-8," + encodeURI(html);
});
//set dark Mode
darkMode.addEventListener("click", () => {
editor.style.backgroundColor = "#363836";
editor.style.color = "#eee";
});
//set light Mode
lightMode.addEventListener("click", () => {
editor.style.backgroundColor = "";
editor.style.color = "";
});
//live code
document.getElementById("live").onclick = function () {
if (this.checked) {
editor.addEventListener("keyup", () => {
const html = editor.textContent;
iframe.src = "data:text/html;charset=utf-8," + encodeURI(html);
});
}
};