Create script.js
Browse files
script.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Assembly Guide JavaScript
|
| 2 |
+
let currentStep = 1;
|
| 3 |
+
const totalSteps = 51;
|
| 4 |
+
|
| 5 |
+
// Map of available images (only step1 and step2 exist, rest are placeholders)
|
| 6 |
+
const availableImages = {
|
| 7 |
+
1: 'steps/step1.jpg',
|
| 8 |
+
2: 'steps/step2.jpg'
|
| 9 |
+
};
|
| 10 |
+
|
| 11 |
+
// DOM Elements
|
| 12 |
+
const stepDisplay = document.getElementById('stepDisplay');
|
| 13 |
+
const stepImage = document.getElementById('stepImage');
|
| 14 |
+
const placeholderText = document.getElementById('placeholderText');
|
| 15 |
+
const placeholderNumber = document.getElementById('placeholderNumber');
|
| 16 |
+
const placeholderStep = document.getElementById('placeholderStep');
|
| 17 |
+
const prevBtn = document.getElementById('prevBtn');
|
| 18 |
+
const nextBtn = document.getElementById('nextBtn');
|
| 19 |
+
const progressFill = document.getElementById('progressFill');
|
| 20 |
+
const indicatorsContainer = document.getElementById('indicators');
|
| 21 |
+
|
| 22 |
+
// Initialize
|
| 23 |
+
function init() {
|
| 24 |
+
createIndicators();
|
| 25 |
+
updateDisplay();
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
// Create step indicators
|
| 29 |
+
function createIndicators() {
|
| 30 |
+
const indicatorsToShow = Math.min(totalSteps, 10);
|
| 31 |
+
|
| 32 |
+
for (let i = 0; i < indicatorsToShow; i++) {
|
| 33 |
+
const button = document.createElement('button');
|
| 34 |
+
button.className = 'indicator';
|
| 35 |
+
button.setAttribute('aria-label', `Go to step ${i + 1}`);
|
| 36 |
+
button.addEventListener('click', () => {
|
| 37 |
+
const targetStep = Math.floor((currentStep - 1) / 10) * 10 + i + 1;
|
| 38 |
+
if (targetStep <= totalSteps) {
|
| 39 |
+
goToStep(targetStep);
|
| 40 |
+
}
|
| 41 |
+
});
|
| 42 |
+
indicatorsContainer.appendChild(button);
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
// Update indicators
|
| 47 |
+
function updateIndicators() {
|
| 48 |
+
const indicators = indicatorsContainer.children;
|
| 49 |
+
const startStep = Math.floor((currentStep - 1) / 10) * 10 + 1;
|
| 50 |
+
|
| 51 |
+
Array.from(indicators).forEach((indicator, i) => {
|
| 52 |
+
const step = startStep + i;
|
| 53 |
+
if (step > totalSteps) {
|
| 54 |
+
indicator.style.display = 'none';
|
| 55 |
+
} else {
|
| 56 |
+
indicator.style.display = 'block';
|
| 57 |
+
indicator.classList.toggle('active', step === currentStep);
|
| 58 |
+
}
|
| 59 |
+
});
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
// Update display
|
| 63 |
+
function updateDisplay() {
|
| 64 |
+
// Update step counter
|
| 65 |
+
stepDisplay.textContent = `Step ${currentStep}/${totalSteps}`;
|
| 66 |
+
|
| 67 |
+
// Update image or placeholder
|
| 68 |
+
if (availableImages[currentStep]) {
|
| 69 |
+
stepImage.src = availableImages[currentStep];
|
| 70 |
+
stepImage.alt = `Assembly step ${currentStep}`;
|
| 71 |
+
stepImage.style.display = 'block';
|
| 72 |
+
placeholderText.style.display = 'none';
|
| 73 |
+
} else {
|
| 74 |
+
stepImage.style.display = 'none';
|
| 75 |
+
placeholderText.style.display = 'block';
|
| 76 |
+
placeholderNumber.textContent = currentStep;
|
| 77 |
+
placeholderStep.textContent = currentStep;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
// Update buttons
|
| 81 |
+
prevBtn.disabled = currentStep === 1;
|
| 82 |
+
nextBtn.disabled = currentStep === totalSteps;
|
| 83 |
+
|
| 84 |
+
// Update progress bar
|
| 85 |
+
const progress = (currentStep / totalSteps) * 100;
|
| 86 |
+
progressFill.style.width = `${progress}%`;
|
| 87 |
+
|
| 88 |
+
// Update indicators
|
| 89 |
+
updateIndicators();
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
// Go to specific step
|
| 93 |
+
function goToStep(step) {
|
| 94 |
+
if (step >= 1 && step <= totalSteps) {
|
| 95 |
+
currentStep = step;
|
| 96 |
+
updateDisplay();
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
// Next step
|
| 101 |
+
function nextStep() {
|
| 102 |
+
if (currentStep < totalSteps) {
|
| 103 |
+
currentStep++;
|
| 104 |
+
updateDisplay();
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
// Previous step
|
| 109 |
+
function prevStep() {
|
| 110 |
+
if (currentStep > 1) {
|
| 111 |
+
currentStep--;
|
| 112 |
+
updateDisplay();
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
// Event listeners
|
| 117 |
+
nextBtn.addEventListener('click', nextStep);
|
| 118 |
+
prevBtn.addEventListener('click', prevStep);
|
| 119 |
+
|
| 120 |
+
// Keyboard navigation
|
| 121 |
+
document.addEventListener('keydown', (e) => {
|
| 122 |
+
if (e.key === 'ArrowRight') {
|
| 123 |
+
nextStep();
|
| 124 |
+
} else if (e.key === 'ArrowLeft') {
|
| 125 |
+
prevStep();
|
| 126 |
+
}
|
| 127 |
+
});
|
| 128 |
+
|
| 129 |
+
// Initialize on load
|
| 130 |
+
init();
|