-
Notifications
You must be signed in to change notification settings - Fork 428
Expand file tree
/
Copy patheditor.js
More file actions
322 lines (276 loc) Β· 8.59 KB
/
editor.js
File metadata and controls
322 lines (276 loc) Β· 8.59 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
// Editor functionality
=======
n
const htmlEditor = document.getElementById("htmlCode");
const cssEditor = document.getElementById("cssCode");
const jsEditor = document.getElementById("jsCode");
const output = document.getElementById("output");
// Run code function
function runCode() {
const html = htmlEditor.value;
const css = cssEditor.value;
const js = jsEditor.value;
const outputDoc = output.contentDocument || output.contentWindow.document;
outputDoc.open();
outputDoc.write(`
=======
// βΆοΈ Run button functionality
document.getElementById("runBtn").addEventListener("click", () => {
const html = htmlEditor.value.trim();
const css = cssEditor.value.trim();
const js = jsEditor.value.trim();
// ποΈ Construct the result HTML
const result = `
<!DOCTYPE html>
<html>
<head>
<style>${css}</style>
</head>
<body>
${html}
<script>${js}<\/script>
</body>
</html>
`);
outputDoc.close();
}
// Reset code function
function resetCode() {
if (confirm('Are you sure you want to reset all code?')) {
htmlEditor.value = `<!DOCTYPE html>
<html>
<head>
<title>My Animation</title>
</head>
<body>
<div class="container">
<h1>Welcome to AnimateItNow</h1>
<div class="box"></div>
<button id="animateBtn">Animate</button>
</div>
</body>
</html>`;
cssEditor.value = `body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
background: linear-gradient(135deg, #6c63ff, #36d1dc);
}
.container {
text-align: center;
background: white;
padding: 30px;
border-radius: 12px;
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}
h1 {
color: #6c63ff;
margin-bottom: 20px;
}
.box {
width: 100px;
height: 100px;
background: #6c63ff;
margin: 20px auto;
border-radius: 8px;
transition: all 0.5s ease;
}
.box.animated {
transform: rotate(360deg) scale(1.2);
background: #ff6584;
border-radius: 50%;
}
button {
background: #6c63ff;
color: white;
border: none;
padding: 10px 20px;
border-radius: 6px;
cursor: pointer;
font-size: 16px;
transition: background 0.3s;
}
button:hover {
background: #554fd8;
}`;
jsEditor.value = `document.getElementById('animateBtn').addEventListener('click', function() {
const box = document.querySelector('.box');
box.classList.toggle('animated');
// Add some fun effects
if (box.classList.contains('animated')) {
this.textContent = 'Reset';
// Create particles
createParticles();
} else {
this.textContent = 'Animate';
}
});
function createParticles() {
const container = document.querySelector('.container');
for (let i = 0; i < 20; i++) {
const particle = document.createElement('div');
particle.style.position = 'absolute';
particle.style.width = '10px';
particle.style.height = '10px';
particle.style.background = '#ff6584';
particle.style.borderRadius = '50%';
particle.style.left = Math.random() * 100 + '%';
particle.style.top = Math.random() * 100 + '%';
particle.style.animation = \`float \${Math.random() * 2 + 1}s ease-in-out infinite\`;
container.appendChild(particle);
// Remove particle after animation
setTimeout(() => {
particle.remove();
}, 3000);
=======
// π Reset button functionality
document.getElementById("resetBtn").addEventListener("click", () => {
htmlEditor.value = "";
cssEditor.value = "";
jsEditor.value = "";
output.srcdoc = "<!DOCTYPE html><html><body></body></html>";
});
// π Scroll indicator functionality
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');
// π Auto-hide tooltip after 1.5 seconds
setTimeout(() => {
tooltip.classList.remove('show');
}, 1500);
} catch (err) {
// π Fallback for older browsers
textarea.select();
document.execCommand('copy');
tooltip.classList.add('show');
// π Auto-hide tooltip after 1.5 seconds
setTimeout(() => {
tooltip.classList.remove('show');
}, 1500);
}
}
// Add CSS for particle animation
const style = document.createElement('style');
style.textContent = \`
@keyframes float {
0%, 100% { transform: translateY(0) scale(1); opacity: 1; }
50% { transform: translateY(-20px) scale(1.2); opacity: 0.7; }
}
\`;
document.head.appendChild(style);`;
runCode();
}
}
// Copy code function
async function copyCode(targetId) {
const textarea = document.getElementById(targetId);
try {
await navigator.clipboard.writeText(textarea.value);
// Show feedback
const button = event.currentTarget;
const tooltip = button.querySelector('.copy-tooltip');
tooltip.classList.add('show');
setTimeout(() => {
tooltip.classList.remove('show');
}, 2000);
} catch (err) {
// Fallback for older browsers
textarea.select();
document.execCommand('copy');
// Show feedback
const button = event.currentTarget;
const tooltip = button.querySelector('.copy-tooltip');
tooltip.classList.add('show');
setTimeout(() => {
tooltip.classList.remove('show');
}, 2000);
}
}
// Toggle fullscreen
function toggleFullscreen() {
if (!document.fullscreenElement) {
output.requestFullscreen().catch(err => {
console.error(`Error attempting to enable fullscreen: ${err.message}`);
});
document.getElementById('fullscreenBtn').innerHTML = '<i class="fas fa-compress"></i>';
} else {
document.exitFullscreen();
document.getElementById('fullscreenBtn').innerHTML = '<i class="fas fa-expand"></i>';
}
}
// Auto-save code
function autoSave() {
const code = {
html: htmlEditor.value,
css: cssEditor.value,
js: jsEditor.value
};
localStorage.setItem('animateItNowCode', JSON.stringify(code));
}
function autoLoad() {
const savedCode = localStorage.getItem('animateItNowCode');
if (savedCode) {
const code = JSON.parse(savedCode);
htmlEditor.value = code.html;
cssEditor.value = code.css;
jsEditor.value = code.js;
}
}
// Set up event listeners
document.addEventListener('DOMContentLoaded', function() {
// Load saved code on page load
autoLoad();
runCode();
// Set up auto-save
htmlEditor.addEventListener('input', autoSave);
cssEditor.addEventListener('input', autoSave);
jsEditor.addEventListener('input', autoSave);
// Button event listeners
document.getElementById("runBtn").addEventListener("click", runCode);
document.getElementById("resetBtn").addEventListener("click", resetCode);
document.getElementById("refreshBtn").addEventListener("click", runCode);
document.getElementById("fullscreenBtn").addEventListener("click", toggleFullscreen);
document.querySelectorAll('.copy-btn').forEach(button => {
button.addEventListener('click', function() {
const target = this.getAttribute('data-target');
copyCode(target);
});
});
// Navbar scroll effect
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 + "%";
});
});
// π Debug logging function for development
function debugLog(message) {
// π This is a placeholder for future debugging
// console.log(`[Editor Debug] ${message}`);
}
// π§ͺ Performance monitoring placeholder
function monitorPerformance() {
// π This is a placeholder for future performance monitoring
// console.log("Performance metrics:", performance.memory);
}
// π§Ό Cleanup function for memory management
function cleanup() {
// π§Ή This is a placeholder for future cleanup operations
console.log("π§Ή Editor cleanup completed");
}