-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
42 lines (34 loc) · 1.27 KB
/
script.js
File metadata and controls
42 lines (34 loc) · 1.27 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
let htmlinput=document.querySelector(".html-editor textarea")
let cssinput=document.querySelector(".css-editor textarea")
let jsinput=document.querySelector(".js-editor textarea")
let save=document.querySelector("#save")
let outputContainer=document.querySelector(".output-container")
let output=document.querySelector("#output")
let full=document.querySelector("#full")
let copy=document.querySelectorAll(".copy")
save.addEventListener("click",()=>{
output.contentDocument.body.innerHTML=htmlinput.value;
output.contentDocument.head.innerHTML=`<style>${cssinput.value}</style>`
output.contentWindow.eval(jsinput.value)
})
full.addEventListener("click",()=>{
outputContainer.classList.toggle("output-full-active")
if(outputContainer.classList.contains("output-full-active")){
full.style.transform="rotate(180deg)"
}else{
full.style.transform="rotate(0deg)"
}
})
copy.forEach((e)=>{
e.addEventListener("click",()=>{
if(e.classList.contains("copy1")){
navigator.clipboard.writeText(htmlinput.value)
}
else if(e.classList.contains("copy2")){
navigator.clipboard.writeText(cssinput.value)
}
else{
navigator.clipboard.writeText(jsinput.value)
}
})
})