File size: 10,318 Bytes
529b1e4 3217c1d 7afb1ad a9706d2 c810c7a a9706d2 c810c7a a9706d2 c810c7a a9706d2 c810c7a 3217c1d a9706d2 c810c7a 3217c1d 529b1e4 3217c1d 529b1e4 3217c1d 529b1e4 3217c1d 529b1e4 3217c1d 529b1e4 3217c1d 56dbfc4 3217c1d c810c7a 53b6d1a 56dbfc4 385b2fe 56dbfc4 385b2fe 56dbfc4 385b2fe 3217c1d |
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 |
document.addEventListener('DOMContentLoaded', function() {
// Tab functionality
function setupTabs() {
const tabButtons = document.querySelectorAll('.tab-btn');
const tabContents = document.querySelectorAll('.tab-content');
tabButtons.forEach(button => {
button.addEventListener('click', () => {
// Remove active class from all buttons and contents
tabButtons.forEach(btn => btn.classList.remove('active'));
tabContents.forEach(content => {
content.classList.remove('active');
content.classList.add('hidden');
});
// Add active class to clicked button
button.classList.add('active');
// Show the selected tab content
const tabId = button.getAttribute('data-tab') + '-tab';
const tabContent = document.getElementById(tabId);
if (tabContent) {
tabContent.classList.remove('hidden');
tabContent.classList.add('active');
}
});
});
}
// Process diagram functionality
const runProcessBtn = document.getElementById('run-process');
const steps = document.querySelectorAll('.step');
const stepArrows = document.querySelectorAll('.step-arrow');
if (runProcessBtn && steps.length > 0) {
runProcessBtn.addEventListener('click', () => {
// Reset all steps
steps.forEach(step => {
step.classList.remove('active');
const circle = step.querySelector('.step-circle');
if (circle) {
circle.style.backgroundColor = '#e2e8f0';
}
});
stepArrows.forEach(arrow => {
const icon = arrow.querySelector('i');
if (icon) {
icon.style.color = '#9ca3af';
}
});
// Animate steps one by one
let delay = 0;
steps.forEach((step, index) => {
setTimeout(() => {
step.classList.add('active');
// Color the arrow after this step (if not last step)
if (index < steps.length - 1 && stepArrows[index]) {
const icon = stepArrows[index].querySelector('i');
if (icon) {
icon.style.color = '#3b82f6';
}
}
}, delay);
delay += 800; // 0.8s delay between steps
});
// Reset button after animation
setTimeout(() => {
runProcessBtn.classList.add('pulse');
setTimeout(() => {
runProcessBtn.classList.remove('pulse');
}, 1000);
}, delay);
});
}
// Code editor functionality
const exampleButtons = document.querySelectorAll('.example-btn');
const htmlEditor = document.getElementById('html-editor');
const cssEditor = document.getElementById('css-editor');
const jsEditor = document.getElementById('js-editor');
const runCodeBtn = document.getElementById('run-code');
const resetCodeBtn = document.getElementById('reset-code');
const resultFrame = document.getElementById('result-frame');
// Initialize editors if they exist
if (htmlEditor && cssEditor && jsEditor) {
htmlEditor.value = '';
cssEditor.value = '';
jsEditor.value = '';
}
// Example code snippets
const examples = {
button: {
html: `<button id="my-button">Нажми меня</button>`,
css: `#my-button {
padding: 10px 20px;
background-color: #3b82f6;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
#my-button:hover {
background-color: #2563eb;
}`,
js: `document.getElementById('my-button').addEventListener('click', function() {
alert('Кнопка нажата!');
});`
},
color: {
html: `<div id="color-box"></div>
<button id="change-color">Изменить цвет</button>`,
css: `#color-box {
width: 200px;
height: 200px;
background-color: #3b82f6;
margin-bottom: 20px;
}
button {
padding: 10px 20px;
background-color: #10b981;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}`,
js: `const colors = ['#3b82f6', '#ef4444', '#10b981', '#f59e0b', '#8b5cf6'];
let currentColor = 0;
document.getElementById('change-color').addEventListener('click', function() {
currentColor = (currentColor + 1) % colors.length;
document.getElementById('color-box').style.backgroundColor = colors[currentColor];
});`
},
counter: {
html: `<div class="counter-container">
<h2>Счётчик кликов</h2>
<p>Текущее значение: <span id="counter">0</span></p>
<button id="increment">+1</button>
<button id="decrement">-1</button>
<button id="reset">Сбросить</button>
</div>`,
css: `.counter-container {
font-family: Arial, sans-serif;
max-width: 300px;
margin: 0 auto;
text-align: center;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
}
.counter-container h2 {
color: #3b82f6;
margin-top: 0;
}
.counter-container p {
font-size: 18px;
margin: 20px 0;
}
button {
padding: 8px 16px;
margin: 5px;
background-color: #3b82f6;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #2563eb;
}`,
js: `let count = 0;
const counterElement = document.getElementById('counter');
function updateCounter() {
counterElement.textContent = count;
}
document.getElementById('increment').addEventListener('click', function() {
count++;
updateCounter();
});
document.getElementById('decrement').addEventListener('click', function() {
count--;
updateCounter();
});
document.getElementById('reset').addEventListener('click', function() {
count = 0;
updateCounter();
});`
}
};
// Load example code
exampleButtons.forEach(button => {
button.addEventListener('click', () => {
// Remove active class from all buttons
exampleButtons.forEach(btn => btn.classList.remove('active'));
// Add active class to clicked button
button.classList.add('active');
// Load example code
const exampleName = button.getAttribute('data-example');
const example = examples[exampleName];
htmlEditor.value = example.html;
cssEditor.value = example.css;
jsEditor.value = example.js;
// Update preview
updatePreview();
});
});
// Run code button
if (runCodeBtn) {
runCodeBtn.addEventListener('click', updatePreview);
}
// Reset code button
if (resetCodeBtn) {
resetCodeBtn.addEventListener('click', () => {
htmlEditor.value = '';
cssEditor.value = '';
jsEditor.value = '';
resultFrame.srcdoc = '';
});
}
// Update preview function
function updatePreview() {
const html = htmlEditor.value;
const css = cssEditor.value;
const js = jsEditor.value;
const resultDoc = `
<!DOCTYPE html>
<html>
<head>
<style>${css}</style>
</head>
<body>
${html}
<script>${js}</script>
</body>
</html>
`;
resultFrame.srcdoc = resultDoc;
}
// Load first example by default if JS is enabled
if (exampleButtons.length > 0 && !document.body.hasAttribute('data-js-disabled')) {
exampleButtons[0].click();
}
// Handle demo counter button
const demoCounterBtn = document.getElementById('demo-counter-btn');
const demoCounter = document.getElementById('demo-counter');
if (demoCounterBtn && demoCounter) {
demoCounterBtn.addEventListener('click', () => {
demoCounter.textContent++;
});
}
// Make sure tabs work after example changes if JS is enabled
if (!document.body.hasAttribute('data-js-disabled')) {
setupTabs();
}
// Technology toggle functionality
const techToggles = document.querySelectorAll('.tech-toggle');
techToggles.forEach(toggle => {
toggle.addEventListener('click', function(e) {
e.preventDefault();
const tech = this.getAttribute('data-tech');
this.classList.toggle('opacity-50');
if (tech === 'html') {
document.documentElement.style.display = this.classList.contains('opacity-50') ? 'none' : '';
} else if (tech === 'css') {
const styleTags = document.querySelectorAll('style, link[rel="stylesheet"]');
styleTags.forEach(tag => {
tag.disabled = this.classList.contains('opacity-50');
});
} else if (tech === 'js') {
const scripts = Array.from(document.scripts).filter(script =>
!script.classList.contains('tech-toggle') &&
script.id !== 'toggle-js'
);
if (this.classList.contains('opacity-50')) {
// Disable JS
scripts.forEach(script => {
script.type = 'text/disabled';
});
document.body.setAttribute('data-js-disabled', 'true');
} else {
// Enable JS
scripts.forEach(script => {
script.type = 'text/javascript';
});
document.body.removeAttribute('data-js-disabled');
}
}
});
});
}); |