Sure! Below is a complete HTML, CSS, and JavaScript implementation for a sleek dark-themed visual scripting website. This setup includes separate tabs for HTML and CSS visual scripting, a classic JavaScript editor using CodeMirror, and an iframe to preview the results of your scripts.
Features:
- Dark Theme: Sleek and modern dark design for a comfortable coding experience.
- Tabbed Interface: Separate tabs for HTML and CSS visual scripting.
- CodeMirror Integration: Enhanced JavaScript coding experience with syntax highlighting and other features.
- Live Preview: An iframe that updates in real-time to show the rendered HTML, CSS, and JavaScript.
Complete Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Visual Scripting Editor</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/dracula.min.css">
<!-- Icons (Optional: Font Awesome for buttons/icons) -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
/* Reset and Basic Styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: #1e1e1e;
color: #cccccc;
font-family: Arial, sans-serif;
height: 100vh;
display: flex;
flex-direction: column;
}
/* Header */
header {
background-color: #2d2d2d;
padding: 10px 20px;
display: flex;
align-items: center;
justify-content: space-between;
}
header h1 {
font-size: 1.5em;
color: #ffffff;
}
/* Main Layout */
.container {
flex: 1;
display: flex;
overflow: hidden;
}
/* Sidebar for Tabs */
.sidebar {
width: 200px;
background-color: #2d2d2d;
display: flex;
flex-direction: column;
border-right: 1px solid #444;
}
.sidebar button {
padding: 15px;
background: none;
border: none;
color: #cccccc;
text-align: left;
width: 100%;
cursor: pointer;
font-size: 1em;
outline: none;
transition: background 0.3s;
}
.sidebar button:hover, .sidebar button.active {
background-color: #3e3e3e;
}
/* Editor Area */
.editor-area {
flex: 1;
display: flex;
flex-direction: column;
}
.tab-content {
flex: 1;
display: none;
padding: 20px;
overflow: auto;
}
.tab-content.active {
display: block;
}
/* JavaScript Editor */
#js-editor {
height: 200px;
border-top: 1px solid #444;
}
/* Preview iframe */
.preview {
height: 300px;
border-top: 1px solid #444;
}
/* Buttons for Visual Scripting */
.visual-buttons {
margin-bottom: 10px;
}
.visual-buttons button {
padding: 10px;
margin-right: 10px;
background-color: #3e3e3e;
border: none;
color: #ffffff;
cursor: pointer;
border-radius: 4px;
transition: background 0.3s;
}
.visual-buttons button:hover {
background-color: #575757;
}
</style>
</head>
<body>
<header>
<h1>Visual Scripting Editor</h1>
</header>
<div class="container">
<!-- Sidebar with Tabs -->
<div class="sidebar">
<button class="tab-button active" data-tab="html-tab"><i class="fas fa-code"></i> HTML</button>
<button class="tab-button" data-tab="css-tab"><i class="fas fa-paint-brush"></i> CSS</button>
<button class="tab-button" data-tab="js-tab"><i class="fas fa-code"></i> JavaScript</button>
</div>
<!-- Editor Area -->
<div class="editor-area">
<!-- HTML Tab -->
<div id="html-tab" class="tab-content active">
<div class="visual-buttons">
<button onclick="insertHTML('div')"><div></button>
<button onclick="insertHTML('p')"><p></button>
<button onclick="insertHTML('h1')"><h1></button>
<button onclick="insertHTML('span')"><span></button>
</div>
<textarea id="html-content" placeholder="Add your HTML visually here..."></textarea>
</div>
<!-- CSS Tab -->
<div id="css-tab" class="tab-content">
<div class="visual-buttons">
<button onclick="insertCSS('color')">Color</button>
<button onclick="insertCSS('background-color')">Background Color</button>
<button onclick="insertCSS('font-size')">Font Size</button>
<button onclick="insertCSS('margin')">Margin</button>
</div>
<textarea id="css-content" placeholder="Add your CSS visually here..."></textarea>
</div>
<!-- JavaScript Tab -->
<div id="js-tab" class="tab-content">
<textarea id="js-editor"></textarea>
</div>
<!-- Preview -->
<iframe id="preview" class="preview"></iframe>
</div>
</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/javascript/javascript.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/addon/edit/closetag.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/addon/edit/closebrackets.min.js"></script>
<!-- Font Awesome JS (Optional) -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/js/all.min.js"></script>
<script>
// Tab Switching
const tabButtons = document.querySelectorAll('.tab-button');
const tabContents = document.querySelectorAll('.tab-content');
tabButtons.forEach(button => {
button.addEventListener('click', () => {
// Remove active class from all buttons
tabButtons.forEach(btn => btn.classList.remove('active'));
// Hide all tab contents
tabContents.forEach(tab => tab.classList.remove('active'));
// Add active class to clicked button
button.classList.add('active');
// Show corresponding tab content
const tab = document.getElementById(button.dataset.tab);
tab.classList.add('active');
});
});
// Initialize CodeMirror for JavaScript
const jsEditor = CodeMirror.fromTextArea(document.getElementById('js-editor'), {
mode: "javascript",
theme: "dracula",
lineNumbers: true,
autoCloseBrackets: true,
autoCloseTags: true,
});
// Function to update preview
function updatePreview() {
const htmlContent = document.getElementById('html-content').value;
const cssContent = document.getElementById('css-content').value;
const jsContent = jsEditor.getValue();
const iframe = document.getElementById('preview');
const documentContent = `
<html>
<head>
<style>
${cssContent}
</style>
</head>
<body>
${htmlContent}
<script>
${jsContent}
</script>
</body>
</html>
`;
iframe.srcdoc = documentContent;
}
// Event listeners to update preview on changes
document.getElementById('html-content').addEventListener('input', updatePreview);
document.getElementById('css-content').addEventListener('input', updatePreview);
jsEditor.on('change', updatePreview);
// Initial Preview
updatePreview();
// Visual Scripting Functions
function insertHTML(tag) {
const htmlArea = document.getElementById('html-content');
const cursorPos = htmlArea.selectionStart;
const before = htmlArea.value.substring(0, cursorPos);
const after = htmlArea.value.substring(cursorPos, htmlArea.value.length);
const newTag = `<${tag}></${tag}>\n`;
htmlArea.value = before + newTag + after;
htmlArea.focus();
htmlArea.selectionStart = htmlArea.selectionEnd = cursorPos + newTag.length;
updatePreview();
}
function insertCSS(property) {
const cssArea = document.getElementById('css-content');
const cursorPos = cssArea.selectionStart;
let value = '';
switch(property) {
case 'color':
value = `color: #ffffff;\n`;
break;
case 'background-color':
value = `background-color: #000000;\n`;
break;
case 'font-size':
value = `font-size: 16px;\n`;
break;
case 'margin':
value = `margin: 10px;\n`;
break;
default:
value = '';
}
const before = cssArea.value.substring(0, cursorPos);
const after = cssArea.value.substring(cursorPos, cssArea.value.length);
cssArea.value = before + value + after;
cssArea.focus();
cssArea.selectionStart = cssArea.selectionEnd = cursorPos + value.length;
updatePreview();
}
</script>
</body>
</html>
Explanation of the Code:
-
HTML Structure:
- Header: Contains the title of the editor.
- Sidebar: Contains buttons to switch between HTML, CSS, and JavaScript tabs.
- Editor Area: Displays the content area for the selected tab along with a preview iframe.
- Visual Buttons: Provide quick buttons to insert common HTML tags and CSS properties.
-
Styling (CSS):
- A dark theme is implemented using various shades of dark gray and vibrant colors for contrast.
- Flexbox is used to create a responsive layout that adjusts to different screen sizes.
- Active tabs and hover effects enhance the user experience.
-
JavaScript Functionality:
- Tab Switching: Clicking on a tab button shows the corresponding content and hides others.
- CodeMirror Integration: Enhances the JavaScript editor with syntax highlighting, line numbers, and auto-closing brackets/tags.
- Live Preview: Combines HTML, CSS, and JavaScript inputs and renders them in the iframe for real-time preview.
- Visual Scripting Functions: Allow users to insert predefined HTML tags and CSS properties with ease, reducing the need to write code manually.
-
External Libraries:
- CodeMirror: A versatile text editor implemented in JavaScript for the JavaScript coding area.
- Font Awesome: Provides icons for better visual representation of tabs and buttons.
Usage:
-
HTML Tab:
- Use the visual buttons to insert common HTML tags like
<div>, <p>, <h1>, and <span>.
- Alternatively, manually write or edit HTML code in the textarea provided.
-
CSS Tab:
- Use the visual buttons to insert common CSS properties like
color, background-color, font-size, and margin.
- Alternatively, manually write or edit CSS code in the textarea provided.
-
JavaScript Tab:
- Write your JavaScript code in the CodeMirror editor. It supports syntax highlighting and other advanced features.
-
Preview:
- The iframe at the bottom automatically updates to reflect the combined HTML, CSS, and JavaScript code, allowing you to see the changes in real-time.
This setup provides a foundation for a visual scripting environment tailored for HTML, CSS, and JavaScript. You can further enhance it by adding more visual scripting tools, advanced code generation, user authentication, project management features, and more based on your requirements.