Spaces:
Running
Running
File size: 4,795 Bytes
787624d 6aaca9c 787624d 6aaca9c |
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 |
<!DOCTYPE html>
<html>
<head>
<title>Web Code IDE</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.63.0/codemirror.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.63.0/theme/monokai.min.css">
<style>
/* styles.css */
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
height: 100vh;
}
.container {
display: flex;
height: 100vh;
}
.editor-container {
width: 60%;
background: #1e1e1e;
display: flex;
flex-direction: column;
}
.preview-container {
width: 40%;
border-left: 2px solid #333;
}
.tabs {
display: flex;
background: #252526;
}
.tab {
padding: 10px 20px;
color: #fff;
cursor: pointer;
border-right: 1px solid #333;
}
.tab.active {
background: #1e1e1e;
}
.code-editor {
height: 33.33%;
overflow: hidden;
}
.CodeMirror {
height: 100% !important;
}
#preview {
width: 100%;
height: 100%;
border: none;
}
</style>
</head>
<body>
<div class="container">
<div class="editor-container">
<div class="tabs">
<div class="tab active" onclick="showEditor('html')">HTML</div>
<div class="tab" onclick="showEditor('css')">CSS</div>
<div class="tab" onclick="showEditor('js')">JavaScript</div>
</div>
<div id="html-editor" class="code-editor"></div>
<div id="css-editor" class="code-editor" style="display: none"></div>
<div id="js-editor" class="code-editor" style="display: none"></div>
</div>
<div class="preview-container">
<iframe id="preview"></iframe>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.63.0/codemirror.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.63.0/mode/htmlmixed/htmlmixed.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.63.0/mode/css/css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.63.0/mode/javascript/javascript.min.js"></script>
<script>
// script.js
let htmlEditor = CodeMirror(document.getElementById('html-editor'), {
mode: 'htmlmixed',
theme: 'monokai',
lineNumbers: true,
value: '<!DOCTYPE html>\n<html>\n<head>\n\t<title>Demo</title>\n</head>\n<body>\n\t<h1>Hello World</h1>\n</body>\n</html>'
});
let cssEditor = CodeMirror(document.getElementById('css-editor'), {
mode: 'css',
theme: 'monokai',
lineNumbers: true,
value: 'h1 { color: blue; }'
});
let jsEditor = CodeMirror(document.getElementById('js-editor'), {
mode: 'javascript',
theme: 'monokai',
lineNumbers: true,
value: 'console.log("Hello from JS!");'
});
function showEditor(language) {
document.querySelectorAll('.code-editor').forEach(editor => {
editor.style.display = 'none';
});
document.querySelectorAll('.tab').forEach(tab => {
tab.classList.remove('active');
});
document.getElementById(`${language}-editor`).style.display = 'block';
event.target.classList.add('active');
}
function updatePreview() {
const html = htmlEditor.getValue();
const css = cssEditor.getValue();
const js = jsEditor.getValue();
const preview = document.getElementById('preview').contentWindow.document;
preview.open();
preview.write(`
<!DOCTYPE html>
<html>
<head>
<style>${css}</style>
</head>
<body>
${html}
<script>${js}<\/script>
</body>
</html>
`);
preview.close();
}
// Update preview on code changes
[htmlEditor, cssEditor, jsEditor].forEach(editor => {
editor.on('change', () => {
updatePreview();
});
});
// Initial preview
updatePreview();
</script>
</body>
</html>
|