forked from AnujShrivastava01/AnimateItNow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.js
More file actions
69 lines (63 loc) · 2.01 KB
/
editor.js
File metadata and controls
69 lines (63 loc) · 2.01 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
58
59
60
61
62
63
64
65
66
67
68
69
const htmlEditor = document.getElementById("htmlCode");
const cssEditor = document.getElementById("cssCode");
const jsEditor = document.getElementById("jsCode");
const output = document.getElementById("output");
document.getElementById("runBtn").addEventListener("click", () => {
const html = htmlEditor.value.trim();
const css = cssEditor.value.trim();
const js = jsEditor.value.trim();
const result = `
<!DOCTYPE html>
<html lang="en">
<head>
<style>${css}</style>
</head>
<body>
${html}
<script>
try {
${js}
} catch (e) {
document.body.innerHTML += '<pre style="color:red;">' + e + '</pre>';
}
<\/script>
</body>
</html>
`;
output.srcdoc = result;
});
document.getElementById("resetBtn").addEventListener("click", () => {
htmlEditor.value = "";
cssEditor.value = "";
jsEditor.value = "";
output.srcdoc = "<!DOCTYPE html><html><body></body></html>";
});
window.addEventListener("scroll", () => {
const scrollTop = window.scrollY;
const docHeight = document.documentElement.scrollHeight - window.innerHeight;
const scrollPercent = (scrollTop / docHeight) * 100;
document.querySelector(".scroll-indicator").style.width = scrollPercent + "%";
});
// Copy to clipboard functionality
document.querySelectorAll('.copy-btn').forEach(btn => {
btn.addEventListener('click', async (e) => {
const targetId = e.target.getAttribute('data-target');
const textarea = document.getElementById(targetId);
const tooltip = e.target.parentElement.querySelector('.copy-tooltip');
try {
await navigator.clipboard.writeText(textarea.value);
tooltip.classList.add('show');
setTimeout(() => {
tooltip.classList.remove('show');
}, 1500);
} catch (err) {
// Fallback for older browsers
textarea.select();
document.execCommand('copy');
tooltip.classList.add('show');
setTimeout(() => {
tooltip.classList.remove('show');
}, 1500);
}
});
});