-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
57 lines (47 loc) · 1.57 KB
/
Copy pathmain.js
File metadata and controls
57 lines (47 loc) · 1.57 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
55
56
57
const left = document.querySelector(".left");
const right = document.querySelector(".right");
const bar = document.querySelector(".bar");
const editor = document.querySelector(".editor");
const run = document.querySelector(".btn-run");
const display = document.querySelector(".display");
const darkMode = document.querySelector(".btn-dark");
const 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.resize();
};
bar.addEventListener("mousedown", () => {
document.addEventListener("mousemove", drag);
});
bar.addEventListener("mouseup", () => {
document.removeEventListener("mousemove", drag);
});
// run btn event listener
run.addEventListener("click", () => {
const html = editor.textContent;
display.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.querySelector("div").addEventListener("input", (e) => {
// Do something with the "change"-like event
if (document.getElementById("live").checked) {
editor.addEventListener("keyup", () => {
const html = editor.textContent;
display.src = "data:text/html;charset=utf-8," + encodeURI(html);
});
}
});