File size: 5,114 Bytes
3c70117 759da20 d652d70 3c70117 |
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 |
// Assembly Guide JavaScript
let currentStep = 1;
const totalSteps = 51;
// Map of available images (only step1 and step2 exist, rest are placeholders)
const availableImages = {
1: 'assets/step1.jpg',
2: 'assets/step2.jpg',
3: 'assets/step3bis.jpg',
4: 'assets/step4.jpg',
5: 'assets/step5.jpg',
6: 'assets/step6.jpg',
7: 'assets/step7.jpg',
8: 'assets/step8.jpg',
9: 'assets/step9.jpg',
10: 'assets/step10.jpg',
11: 'assets/step11.jpg',
12: 'assets/step12.jpg',
13: 'assets/step13.jpg',
14: 'assets/step14.jpg',
15: 'assets/step15.jpg',
16: 'assets/step16.jpg',
17: 'assets/step17.jpg',
18: 'assets/step18.jpg',
19: 'assets/step19.jpg',
20: 'assets/step20.jpg',
21: 'assets/step21.jpg',
22: 'assets/step22.jpg',
23: 'assets/step23.jpg',
24: 'assets/step24.jpg',
25: 'assets/step25.jpg',
26: 'assets/step26.jpg',
27: 'assets/step27.jpg',
28: 'assets/step28.jpg',
29: 'assets/step29.jpg',
30: 'assets/step30.jpg',
31: 'assets/step31.jpg',
32: 'assets/step32.jpg',
33: 'assets/step33.jpg',
34: 'assets/step34.jpg',
35: 'assets/step35.jpg',
36: 'assets/step36.jpg',
37: 'assets/step37.jpg',
38: 'assets/step38.jpg',
39: 'assets/step39.jpg',
40: 'assets/step40.jpg',
41: 'assets/step41.jpg',
42: 'assets/step42.jpg',
43: 'assets/step43.jpg',
44: 'assets/step44.jpg',
45: 'assets/step45.jpg',
46: 'assets/step46.jpg',
47: 'assets/step47.jpg',
48: 'assets/step48.jpg',
49: 'assets/step49.jpg',
50: 'assets/step50.jpg',
51: 'assets/step51.jpg',
};
// DOM Elements
const stepDisplay = document.getElementById('stepDisplay');
const stepImage = document.getElementById('stepImage');
const placeholderText = document.getElementById('placeholderText');
const placeholderNumber = document.getElementById('placeholderNumber');
const placeholderStep = document.getElementById('placeholderStep');
const prevBtn = document.getElementById('prevBtn');
const nextBtn = document.getElementById('nextBtn');
const progressFill = document.getElementById('progressFill');
const indicatorsContainer = document.getElementById('indicators');
// Initialize
function init() {
createIndicators();
updateDisplay();
}
// Create step indicators
function createIndicators() {
const indicatorsToShow = Math.min(totalSteps, 10);
for (let i = 0; i < indicatorsToShow; i++) {
const button = document.createElement('button');
button.className = 'indicator';
button.setAttribute('aria-label', `Go to step ${i + 1}`);
button.addEventListener('click', () => {
const targetStep = Math.floor((currentStep - 1) / 10) * 10 + i + 1;
if (targetStep <= totalSteps) {
goToStep(targetStep);
}
});
indicatorsContainer.appendChild(button);
}
}
// Update indicators
function updateIndicators() {
const indicators = indicatorsContainer.children;
const startStep = Math.floor((currentStep - 1) / 10) * 10 + 1;
Array.from(indicators).forEach((indicator, i) => {
const step = startStep + i;
if (step > totalSteps) {
indicator.style.display = 'none';
} else {
indicator.style.display = 'block';
indicator.classList.toggle('active', step === currentStep);
}
});
}
// Update display
function updateDisplay() {
// Update step counter
stepDisplay.textContent = `Step ${currentStep}/${totalSteps}`;
// Update image or placeholder
if (availableImages[currentStep]) {
stepImage.src = availableImages[currentStep];
stepImage.alt = `Assembly step ${currentStep}`;
stepImage.style.display = 'block';
placeholderText.style.display = 'none';
} else {
stepImage.style.display = 'none';
placeholderText.style.display = 'block';
placeholderNumber.textContent = currentStep;
placeholderStep.textContent = currentStep;
}
// Update buttons
prevBtn.disabled = currentStep === 1;
nextBtn.disabled = currentStep === totalSteps;
// Update progress bar
const progress = (currentStep / totalSteps) * 100;
progressFill.style.width = `${progress}%`;
// Update indicators
updateIndicators();
}
// Go to specific step
function goToStep(step) {
if (step >= 1 && step <= totalSteps) {
currentStep = step;
updateDisplay();
}
}
// Next step
function nextStep() {
if (currentStep < totalSteps) {
currentStep++;
updateDisplay();
}
}
// Previous step
function prevStep() {
if (currentStep > 1) {
currentStep--;
updateDisplay();
}
}
// Event listeners
nextBtn.addEventListener('click', nextStep);
prevBtn.addEventListener('click', prevStep);
// Keyboard navigation
document.addEventListener('keydown', (e) => {
if (e.key === 'ArrowRight') {
nextStep();
} else if (e.key === 'ArrowLeft') {
prevStep();
}
});
// Initialize on load
init();
|