File size: 3,695 Bytes
3c70117
 
 
 
 
 
f4f0836
f27fa8d
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
// 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/p9.jpg',
    2: 'assets/p10.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();