-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
52 lines (45 loc) · 1.49 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
const left = document.querySelector(".left"),
right = document.querySelector(".right"),
bar = document.querySelector(".bar"),
btn = document.querySelector(".btn-Run"),
dark = document.querySelector(".btn-dark"),
light = document.querySelector(".btn-light"),
iframe = document.querySelector(".iframe"),
editor = document.querySelector(".editor");
// Resizing
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.addEventListener("click", () => {
const html = editor.textContent;
iframe.src = "data:text/html;charset=utf-8," + encodeURI(html);
});
// Set Dark Mode
dark.addEventListener("click", () => {
editor.style.backgroundColor = "rgb(40, 44, 52)";
editor.style.color = '#eee';
});
// Set Light Mode
light.addEventListener("click", () => {
editor.style.backgroundColor = "";
editor.style.color = '';
});
// Live
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);
});
}
}