Spaces:
Running
Running
Create scripts.js
Browse files- scripts.js +140 -0
scripts.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { config } from './config.js';
|
| 2 |
+
|
| 3 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 4 |
+
// Elements
|
| 5 |
+
const symbols = document.querySelectorAll('.symbol');
|
| 6 |
+
const textPanels = document.querySelectorAll('.text-panel');
|
| 7 |
+
const prevBtn = document.getElementById('prev-btn');
|
| 8 |
+
const nextBtn = document.getElementById('next-btn');
|
| 9 |
+
const progressDots = document.querySelectorAll('.progress-dot');
|
| 10 |
+
const video = document.getElementById('background-video');
|
| 11 |
+
|
| 12 |
+
// Set initial state
|
| 13 |
+
let currentStage = 0;
|
| 14 |
+
const totalStages = symbols.length;
|
| 15 |
+
|
| 16 |
+
// Update CSS variables from config
|
| 17 |
+
document.documentElement.style.setProperty('--intimate-color', config.colors.intimate);
|
| 18 |
+
document.documentElement.style.setProperty('--universal-color', config.colors.universal);
|
| 19 |
+
document.documentElement.style.setProperty('--divine-color', config.colors.divine);
|
| 20 |
+
document.documentElement.style.setProperty('--transition-time', `${config.transitionTime}s`);
|
| 21 |
+
|
| 22 |
+
// Background video settings
|
| 23 |
+
video.style.opacity = config.background.opacity;
|
| 24 |
+
|
| 25 |
+
// Initialize the first stage
|
| 26 |
+
updateStage();
|
| 27 |
+
|
| 28 |
+
// Event listeners
|
| 29 |
+
prevBtn.addEventListener('click', navigateToPrevious);
|
| 30 |
+
nextBtn.addEventListener('click', navigateToNext);
|
| 31 |
+
|
| 32 |
+
progressDots.forEach(dot => {
|
| 33 |
+
dot.addEventListener('click', (e) => {
|
| 34 |
+
const index = parseInt(e.target.dataset.index);
|
| 35 |
+
goToStage(index);
|
| 36 |
+
});
|
| 37 |
+
});
|
| 38 |
+
|
| 39 |
+
// Keyboard navigation
|
| 40 |
+
document.addEventListener('keydown', (e) => {
|
| 41 |
+
if (e.key === 'ArrowLeft') navigateToPrevious();
|
| 42 |
+
if (e.key === 'ArrowRight') navigateToNext();
|
| 43 |
+
});
|
| 44 |
+
|
| 45 |
+
// Automatic progression if enabled
|
| 46 |
+
let autoProgressInterval;
|
| 47 |
+
|
| 48 |
+
if (config.autoProgress.enabled) {
|
| 49 |
+
startAutoProgress();
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
function startAutoProgress() {
|
| 53 |
+
autoProgressInterval = setInterval(() => {
|
| 54 |
+
if (currentStage < totalStages - 1) {
|
| 55 |
+
navigateToNext();
|
| 56 |
+
} else {
|
| 57 |
+
goToStage(0);
|
| 58 |
+
}
|
| 59 |
+
}, config.autoProgress.interval);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
// Navigation functions
|
| 63 |
+
function navigateToNext() {
|
| 64 |
+
if (currentStage < totalStages - 1) {
|
| 65 |
+
currentStage++;
|
| 66 |
+
updateStage();
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
function navigateToPrevious() {
|
| 71 |
+
if (currentStage > 0) {
|
| 72 |
+
currentStage--;
|
| 73 |
+
updateStage();
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
function goToStage(index) {
|
| 78 |
+
if (index >= 0 && index < totalStages) {
|
| 79 |
+
currentStage = index;
|
| 80 |
+
updateStage();
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
function updateStage() {
|
| 85 |
+
// Update symbols
|
| 86 |
+
symbols.forEach((symbol, index) => {
|
| 87 |
+
if (index === currentStage) {
|
| 88 |
+
symbol.classList.add('active');
|
| 89 |
+
} else {
|
| 90 |
+
symbol.classList.remove('active');
|
| 91 |
+
}
|
| 92 |
+
});
|
| 93 |
+
|
| 94 |
+
// Update text panels
|
| 95 |
+
textPanels.forEach((panel, index) => {
|
| 96 |
+
if (index === currentStage) {
|
| 97 |
+
panel.classList.add('active');
|
| 98 |
+
} else {
|
| 99 |
+
panel.classList.remove('active');
|
| 100 |
+
}
|
| 101 |
+
});
|
| 102 |
+
|
| 103 |
+
// Update progress dots
|
| 104 |
+
progressDots.forEach((dot, index) => {
|
| 105 |
+
if (index === currentStage) {
|
| 106 |
+
dot.classList.add('active');
|
| 107 |
+
} else {
|
| 108 |
+
dot.classList.remove('active');
|
| 109 |
+
}
|
| 110 |
+
});
|
| 111 |
+
|
| 112 |
+
// Update buttons
|
| 113 |
+
prevBtn.disabled = currentStage === 0;
|
| 114 |
+
nextBtn.disabled = currentStage === totalStages - 1;
|
| 115 |
+
|
| 116 |
+
// Set background color based on current stage
|
| 117 |
+
let currentColor;
|
| 118 |
+
switch(currentStage) {
|
| 119 |
+
case 0:
|
| 120 |
+
currentColor = config.colors.intimate;
|
| 121 |
+
break;
|
| 122 |
+
case 1:
|
| 123 |
+
currentColor = config.colors.universal;
|
| 124 |
+
break;
|
| 125 |
+
case 2:
|
| 126 |
+
currentColor = config.colors.divine;
|
| 127 |
+
break;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
// Apply subtle color overlay to background
|
| 131 |
+
document.getElementById('background').style.boxShadow = `inset 0 0 100px ${currentColor}33`;
|
| 132 |
+
|
| 133 |
+
// Reset auto-progression timer if enabled
|
| 134 |
+
if (config.autoProgress.enabled) {
|
| 135 |
+
clearInterval(autoProgressInterval);
|
| 136 |
+
startAutoProgress();
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
});
|
| 140 |
+
|