-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.js
More file actions
45 lines (33 loc) · 1.44 KB
/
editor.js
File metadata and controls
45 lines (33 loc) · 1.44 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
const first = document.querySelector(".first");
const third = document.querySelector(".third");
const iframe = document.querySelector("iframe");
const runbtn = document.querySelector("#run-btn");
const darkbtn = document.querySelector("#dark-btn");
const livebtn = document.querySelector("#live-btn");
const defaultbtn = document.querySelector("#default-btn");
runbtn.addEventListener("click", () => {
var html = first.textContent;
iframe.src = "data:text/html;charset=utf-8," + encodeURI(html);
});
darkbtn.addEventListener("click", () => {
var element = document.body;
element.classList.toggle("dark-mode");
});
defaultbtn.addEventListener('click', () => {
document.getElementById('editor').style.display = 'initial';
document.getElementById('liveEditor').style.display = 'none';
document.getElementById('run-span').innerHTML = 'Run';
var html = first.textContent;
iframe.src = "data:text/html;charset=utf-8," + encodeURI(html);
})
livebtn.addEventListener('click', () => {
document.getElementById('editor').style.display = 'none'
document.getElementById('liveEditor').style.display = 'initial'
document.getElementById('run-span').innerHTML = 'Live';
var html = third.textContent;
iframe.src = "data:text/html;charset=utf-8," + encodeURI(html);
third.addEventListener('keyup', () => {
var html = third.textContent;
iframe.src = "data:text/html;charset=utf-8," + encodeURI(html);
})
})