-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeEditor.html
233 lines (212 loc) · 8.53 KB
/
CodeEditor.html
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
<!DOCTYPE html> <html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>DSH Live Playground - Upgraded Popout Focus</title> <!-- CodeMirror CSS --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/codemirror.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/theme/material-darker.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/addon/hint/show-hint.min.css"> <style>
* { box-sizing: border-box; }
body { margin: 0; padding: 10px; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #f0f0f0; }
.toolbar { display: flex; overflow-x: auto; gap: 5px; margin-bottom: 10px; background: #222; padding: 5px; border-radius: 6px; }
.toolbar button {
background: #333;
color: white;
border: none;
padding: 8px 12px;
border-radius: 4px;
font-weight: bold;
cursor: pointer;
}
.toolbar button:hover { background: deepskyblue; }
.container { display: flex; gap: 10px; margin-bottom: 10px; height: 60vh; }
.editor-box {
flex: 1;
display: flex;
flex-direction: column;
border: 2px solid black;
border-radius: 8px;
overflow: hidden;
resize: both;
min-width: 200px;
min-height: 300px;
background: white;
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
/* Baaki sab same */
.editor-title {
text-align: center;
font-weight: bold;
font-style: italic;
color: deepskyblue;
margin: 10px 0;
font-size: 1.2rem;
perspective: 500px; /* 3D effect ka base */
transition: color 0.5s, transform 0.5s;
animation: floatTitle 4s ease-in-out infinite;
}
@keyframes crazyFloatTitle {
0% { transform: rotateX(0deg) rotateY(0deg) translateY(0px) scale(1); }
25% { transform: rotateX(15deg) rotateY(15deg) translateY(-5px) scale(1.05); }
50% { transform: rotateX(0deg) rotateY(0deg) translateY(0px) scale(1); }
75% { transform: rotateX(-15deg) rotateY(-15deg) translateY(5px) scale(1.05); }
100% { transform: rotateX(0deg) rotateY(0deg) translateY(0px) scale(1); }
}
.editor-title {
/* Tumhara existing ke sath */
animation: crazyFloatTitle 5s ease-in-out infinite;
}
/* Jab active ho editor tab aur bhi zyada chamkega */
.editor-box.active .editor-title {
color: cyan;
text-shadow: 0 0 10px cyan, 0 0 20px cyan;
transform: scale(1.1) rotateY(5deg) rotateX(5deg);
}
.CodeMirror { flex: 1; height: 100%; font-size: 16px; }
iframe {
width: 100%;
height: 35vh;
border: 2px solid black;
border-radius: 8px;
background: white;
}
/* POP-UP Effect on Focus */
.editor-box.active {
transform: scale(1.08) rotateY(5deg) rotateX(5deg);
box-shadow: 0 0 20px rgba(0,255,255,0.8), 0 0 40px rgba(0,255,255,0.4);
z-index: 10;
border-color: deepskyblue;
}
.editor-box.active .editor-title {
color: cyan;
}
/* Baaki sab same */
.editor-title {
text-align: center;
font-weight: bold;
font-style: italic;
color: deepskyblue;
margin: 10px 0;
font-size: 1.2rem;
perspective: 500px; /* 3D effect ka base */
transition: color 0.5s, transform 0.5s;
animation: floatTitle 4s ease-in-out infinite;
}
@keyframes floatTitle {
0% {
transform: rotateX(0deg) rotateY(0deg) translateY(0px);
}
25% {
transform: rotateX(10deg) rotateY(10deg) translateY(-5px);
}
50% {
transform: rotateX(0deg) rotateY(0deg) translateY(0px);
}
75% {
transform: rotateX(-10deg) rotateY(-10deg) translateY(5px);
}
100% {
transform: rotateX(0deg) rotateY(0deg) translateY(0px);
}
}
/* Jab active ho editor tab aur bhi zyada chamkega */
.editor-box.active .editor-title {
color: cyan;
text-shadow: 0 0 10px cyan, 0 0 20px cyan;
transform: scale(1.1) rotateY(5deg) rotateX(5deg);
}
</style> </head> <body> <!-- Mobile Smart Toolbar --> <div class="toolbar" id="mobileToolbar"></div> <div class="container">
<div class="editor-box">
<div class="editor-title">html</div>
<textarea id="html"></textarea>
</div>
<div class="editor-box">
<div class="editor-title">css</div>
<textarea id="css"></textarea>
</div>
<div class="editor-box">
<div class="editor-title">js</div>
<textarea id="js"></textarea>
</div>
</div> <div style="margin-top: 10px;">
<div class="editor-title">output</div>
<iframe id="output"></iframe>
</div> <!-- CodeMirror JS --> <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/codemirror.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/mode/xml/xml.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/mode/javascript/javascript.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/mode/css/css.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/mode/htmlmixed/htmlmixed.min.js"></script> <!-- Hint & Autocomplete Addons --> <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/addon/hint/show-hint.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/addon/hint/html-hint.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/addon/hint/css-hint.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/addon/hint/javascript-hint.min.js"></script> <!-- Emmet for CodeMirror --> <script src="https://cdn.jsdelivr.net/npm/@emmetio/[email protected]/dist/emmet-codemirror-plugin.min.js"></script> <script>
// Initialize CodeMirror editors
function initEditor(textareaId, mode) {
return CodeMirror.fromTextArea(document.getElementById(textareaId), {
mode: mode,
theme: "material-darker",
lineNumbers: true,
autoCloseTags: true,
autoCloseBrackets: true,
extraKeys: {
"Ctrl-Space": "autocomplete",
"Tab": "emmetExpandAbbreviation"
}
});
}
const htmlEditor = initEditor("html", "htmlmixed");
const cssEditor = initEditor("css", "css");
const jsEditor = initEditor("js", "javascript");
function run() {
const html = htmlEditor.getValue();
const css = `<style>${cssEditor.getValue()}</style>`; const js = `<script>${jsEditor.getValue()}<\/script>`;
document.getElementById("output").srcdoc = html + css + js;
}
function debounce(func, delay) {
let timeout;
return function() {
clearTimeout(timeout);
timeout = setTimeout(func, delay);
};
}
const autoRun = debounce(run, 500);
htmlEditor.on("change", autoRun);
cssEditor.on("change", autoRun);
jsEditor.on("change", autoRun);
run();
// Mobile Toolbar Buttons
const buttons = [
{ label: 'Ctrl', value: '' },
{ label: 'Shift', value: '' },
{ label: 'Tab', value: '\t' },
{ label: '()', value: '()' },
{ label: '{}', value: '{}' },
{ label: '<>', value: '<>' },
{ label: ';', value: ';' },
{ label: ':', value: ':' },
{ label: '"', value: '""' },
{ label: "'", value: "''" },
{ label: '/', value: '/' },
{ label: '=', value: '=' },
{ label: '+', value: '+' }
];
const toolbar = document.getElementById('mobileToolbar');
let activeEditor = htmlEditor;
function insertText(text) {
const doc = activeEditor.getDoc();
const cursor = doc.getCursor();
doc.replaceRange(text, cursor);
activeEditor.focus();
}
buttons.forEach(btn => {
const button = document.createElement('button');
button.textContent = btn.label;
button.onclick = () => {
if (btn.value) insertText(btn.value);
};
toolbar.appendChild(button);
});
// Detect which editor is active and add popout effect
function setActiveEditor(editor) {
document.querySelectorAll('.editor-box').forEach(box => box.classList.remove('active'));
editor.getWrapperElement().parentElement.classList.add('active');
}
[htmlEditor, cssEditor, jsEditor].forEach(editor => {
editor.on('focus', () => {
activeEditor = editor;
setActiveEditor(editor);
});
});
</script> </body>
</html>