Отключение JS не работает
Browse files
script.js
CHANGED
|
@@ -260,19 +260,21 @@ document.getElementById('reset').addEventListener('click', function() {
|
|
| 260 |
|
| 261 |
resultFrame.srcdoc = resultDoc;
|
| 262 |
}
|
| 263 |
-
// Load first example by default
|
| 264 |
-
if (exampleButtons.length > 0) {
|
| 265 |
exampleButtons[0].click();
|
| 266 |
}
|
| 267 |
|
| 268 |
-
// Make sure tabs work after example changes
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
|
|
|
| 272 |
const techToggles = document.querySelectorAll('.tech-toggle');
|
| 273 |
techToggles.forEach(toggle => {
|
| 274 |
-
toggle.addEventListener('click', function() {
|
| 275 |
-
|
|
|
|
| 276 |
this.classList.toggle('opacity-50');
|
| 277 |
|
| 278 |
if (tech === 'html') {
|
|
@@ -283,11 +285,25 @@ document.getElementById('reset').addEventListener('click', function() {
|
|
| 283 |
tag.disabled = this.classList.contains('opacity-50');
|
| 284 |
});
|
| 285 |
} else if (tech === 'js') {
|
| 286 |
-
const
|
| 287 |
-
|
| 288 |
-
script.
|
| 289 |
-
|
| 290 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
});
|
| 292 |
});
|
| 293 |
});
|
|
|
|
| 260 |
|
| 261 |
resultFrame.srcdoc = resultDoc;
|
| 262 |
}
|
| 263 |
+
// Load first example by default if JS is enabled
|
| 264 |
+
if (exampleButtons.length > 0 && !document.body.hasAttribute('data-js-disabled')) {
|
| 265 |
exampleButtons[0].click();
|
| 266 |
}
|
| 267 |
|
| 268 |
+
// Make sure tabs work after example changes if JS is enabled
|
| 269 |
+
if (!document.body.hasAttribute('data-js-disabled')) {
|
| 270 |
+
setupTabs();
|
| 271 |
+
}
|
| 272 |
+
// Technology toggle functionality
|
| 273 |
const techToggles = document.querySelectorAll('.tech-toggle');
|
| 274 |
techToggles.forEach(toggle => {
|
| 275 |
+
toggle.addEventListener('click', function(e) {
|
| 276 |
+
e.preventDefault();
|
| 277 |
+
const tech = this.getAttribute('data-tech');
|
| 278 |
this.classList.toggle('opacity-50');
|
| 279 |
|
| 280 |
if (tech === 'html') {
|
|
|
|
| 285 |
tag.disabled = this.classList.contains('opacity-50');
|
| 286 |
});
|
| 287 |
} else if (tech === 'js') {
|
| 288 |
+
const scripts = Array.from(document.scripts).filter(script =>
|
| 289 |
+
!script.classList.contains('tech-toggle') &&
|
| 290 |
+
script.id !== 'toggle-js'
|
| 291 |
+
);
|
| 292 |
+
|
| 293 |
+
if (this.classList.contains('opacity-50')) {
|
| 294 |
+
// Disable JS
|
| 295 |
+
scripts.forEach(script => {
|
| 296 |
+
script.type = 'text/disabled';
|
| 297 |
+
});
|
| 298 |
+
document.body.setAttribute('data-js-disabled', 'true');
|
| 299 |
+
} else {
|
| 300 |
+
// Enable JS
|
| 301 |
+
scripts.forEach(script => {
|
| 302 |
+
script.type = 'text/javascript';
|
| 303 |
+
});
|
| 304 |
+
document.body.removeAttribute('data-js-disabled');
|
| 305 |
+
}
|
| 306 |
+
}
|
| 307 |
});
|
| 308 |
});
|
| 309 |
});
|
style.css
CHANGED
|
@@ -131,11 +131,19 @@ body {
|
|
| 131 |
.tech-toggle:hover {
|
| 132 |
opacity: 0.8;
|
| 133 |
}
|
| 134 |
-
|
| 135 |
.tech-toggle.opacity-50 {
|
| 136 |
opacity: 0.5;
|
| 137 |
text-decoration: line-through;
|
| 138 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
/* Responsive adjustments */
|
| 140 |
@media (max-width: 768px) {
|
| 141 |
.step {
|
|
|
|
| 131 |
.tech-toggle:hover {
|
| 132 |
opacity: 0.8;
|
| 133 |
}
|
|
|
|
| 134 |
.tech-toggle.opacity-50 {
|
| 135 |
opacity: 0.5;
|
| 136 |
text-decoration: line-through;
|
| 137 |
}
|
| 138 |
+
|
| 139 |
+
body[data-js-disabled="true"] [onclick],
|
| 140 |
+
body[data-js-disabled="true"] [onload],
|
| 141 |
+
body[data-js-disabled="true"] [onchange],
|
| 142 |
+
body[data-js-disabled="true"] [onmouseover],
|
| 143 |
+
body[data-js-disabled="true"] [onmouseout] {
|
| 144 |
+
pointer-events: none;
|
| 145 |
+
opacity: 0.7;
|
| 146 |
+
}
|
| 147 |
/* Responsive adjustments */
|
| 148 |
@media (max-width: 768px) {
|
| 149 |
.step {
|