-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
144 lines (130 loc) · 4.15 KB
/
Copy pathindex.html
File metadata and controls
144 lines (130 loc) · 4.15 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>GearCodeingX Live Editor</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.14/codemirror.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.14/theme/material-darker.min.css" />
<style>
body {
margin: 0;
font-family: sans-serif;
display: flex;
flex-direction: column;
height: 100vh;
background: #1e1e1e;
color: white;
}
header {
background: #007acc;
padding: 10px;
text-align: center;
font-weight: bold;
font-size: 20px;
}
.tabs {
display: flex;
background: #252526;
}
.tabs button {
flex: 1;
padding: 10px;
background: #2d2d30;
color: white;
border: none;
cursor: pointer;
transition: background 0.3s;
}
.tabs button.active {
background: #007acc;
}
.editor-container, .result-container {
flex: 1;
display: none;
overflow: hidden;
}
.editor-container.active, .result-container.active {
display: block;
}
#resultFrame {
width: 100%;
height: 100%;
border: none;
background: white;
}
.CodeMirror {
height: 100%;
font-size: 16px;
}
</style>
</head>
<body>
<header>GearCodeingX Live Editor</header>
<div class="tabs">
<button class="tab-btn active" data-tab="html">HTML</button>
<button class="tab-btn" data-tab="css">CSS</button>
<button class="tab-btn" data-tab="js">JavaScript</button>
<button class="tab-btn" data-tab="result">Result</button>
</div>
<div class="editor-container active" id="htmlEditor"></div>
<div class="editor-container" id="cssEditor"></div>
<div class="editor-container" id="jsEditor"></div>
<div class="result-container" id="resultTab">
<iframe id="resultFrame"></iframe>
</div>
<!-- CodeMirror Scripts -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.14/codemirror.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.14/mode/xml/xml.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.14/mode/javascript/javascript.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.14/mode/css/css.min.js"></script>
<script>
const htmlEditor = CodeMirror(document.getElementById('htmlEditor'), {
mode: "xml",
theme: "material-darker",
lineNumbers: true,
value: "<h1>Hello from HTML</h1>"
});
const cssEditor = CodeMirror(document.getElementById('cssEditor'), {
mode: "css",
theme: "material-darker",
lineNumbers: true,
value: "h1 { color: red; text-align: center; }"
});
const jsEditor = CodeMirror(document.getElementById('jsEditor'), {
mode: "javascript",
theme: "material-darker",
lineNumbers: true,
value: "console.log('JS Running')"
});
function updateResult() {
const html = htmlEditor.getValue();
const css = `<style>${cssEditor.getValue()}</style>`;
const js = `<script>${jsEditor.getValue()}<\/script>`;
const finalCode = `${html}${css}${js}`;
const iframe = document.getElementById('resultFrame');
const doc = iframe.contentDocument || iframe.contentWindow.document;
doc.open();
doc.write(finalCode);
doc.close();
}
// Tab switching
const tabs = document.querySelectorAll('.tab-btn');
const editors = {
html: document.getElementById('htmlEditor'),
css: document.getElementById('cssEditor'),
js: document.getElementById('jsEditor'),
result: document.getElementById('resultTab')
};
tabs.forEach(tab => {
tab.addEventListener('click', () => {
tabs.forEach(t => t.classList.remove('active'));
tab.classList.add('active');
Object.values(editors).forEach(e => e.classList.remove('active'));
const selected = tab.dataset.tab;
editors[selected].classList.add('active');
if (selected === 'result') updateResult();
});
});
</script>
</body>
</html>