Skip to content

Commit d7fa4ca

Browse files
committed
fix section navigation code
1 parent 226898a commit d7fa4ca

File tree

2 files changed

+64
-19
lines changed

2 files changed

+64
-19
lines changed

src/web/index.html

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,31 @@ <h1 class="font-bold text-2xl text-center flex items-baseline justify-center spa
9898

9999

100100

101+
<section id="model-visualization" class="hidden">
102+
<h1>Visualization</h1>
103+
</section>
104+
105+
106+
107+
<section id="model-testing" class="hidden">
108+
<h1>Testing</h1>
109+
</section>
101110

102-
<nav class="section-controller fixed bottom-0 left-0 w-full flex justify-between bg-indigo-600 p-4 border-t border-indigo-700 lg:px-24">
103-
<button id="btn-prev" class="w-auto bg-white text-indigo-600 py-2 px-4 rounded-md hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 invisible">
104-
Back
105-
</button>
106-
<button id="btn-next" class="w-auto bg-white text-indigo-600 py-2 px-4 rounded-md hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 disabled:bg-gray-200 disabled:text-gray-400 disabled:cursor-not-allowed" disabled>
107-
Next
108-
</button>
111+
112+
113+
<nav id="section-controller" class="fixed bottom-0 left-0 w-full flex justify-between bg-indigo-600 p-4 border-t border-indigo-700 lg:px-24">
114+
<div id="btn-back-container" class="flex items-center space-x-3 invisible">
115+
<button id="btn-back" class="w-auto bg-white text-indigo-600 py-2 px-4 rounded-md hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2">
116+
Back
117+
</button>
118+
<span id="btn-back-support-text" class="text-white">Input data</span>
119+
</div>
120+
<div id="btn-next-container" class="flex items-center space-x-3">
121+
<span id="btn-next-support-text" class="text-white">Model selection</span>
122+
<button id="btn-next" class="w-auto bg-white text-indigo-600 py-2 px-4 rounded-md hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 disabled:bg-gray-200 disabled:text-gray-400 disabled:cursor-not-allowed" disabled>
123+
Next
124+
</button>
125+
</div>
109126
</nav>
110127
</main>
111128

src/web/script.js

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ const fileName = document.getElementById('file-name')
55
const btnPreviewData = document.getElementById('btn-preview-data')
66
const previewData = document.getElementById('preview-data-container')
77

8-
const btnPrev = document.getElementById('btn-prev')
8+
const btnBackContainer = document.getElementById('btn-back-container')
9+
const btnBack = document.getElementById('btn-back')
10+
const btnBackSupportText = document.getElementById('btn-back-support-text')
11+
const btnNextContainer = document.getElementById('btn-next-container')
912
const btnNext = document.getElementById('btn-next')
13+
const btnNextSupportText = document.getElementById('btn-next-support-text')
1014

1115
const sections = document.querySelectorAll('section')
1216

@@ -34,29 +38,53 @@ const btnCopy = document.getElementById('btn-copy')
3438
let equation = null
3539

3640
// Global data
37-
let currentSection = 1
41+
let currentSection = 0
42+
const sectionsArray = [
43+
'Input data',
44+
'Model selection',
45+
'Model visualization',
46+
'Model testing'
47+
]
3848
let fileData = null
3949

4050

4151

42-
btnPrev.addEventListener('click', () => {
43-
sections[currentSection - 1].classList.toggle('hidden')
52+
btnBack.addEventListener('click', () => {
53+
sections[currentSection].classList.toggle('hidden')
4454
currentSection--
45-
sections[currentSection - 1].classList.toggle('hidden')
46-
if (currentSection == 1) {
47-
btnPrev.classList.toggle('invisible')
55+
sections[currentSection].classList.toggle('hidden')
56+
57+
if (currentSection == 0) {
58+
btnBackContainer.classList.toggle('invisible')
59+
}
60+
61+
if (currentSection < sectionsArray.length) {
62+
if (btnNextContainer.classList.contains('invisible')) {
63+
btnNextContainer.classList.remove('invisible')
64+
}
4865
}
66+
67+
btnBackSupportText.textContent = sectionsArray[currentSection - 1] || ''
68+
btnNextSupportText.textContent = sectionsArray[currentSection + 1] || ''
4969
})
5070

5171
btnNext.addEventListener('click', () => {
52-
sections[currentSection - 1].classList.toggle('hidden')
72+
sections[currentSection].classList.toggle('hidden')
5373
currentSection++
54-
sections[currentSection - 1].classList.toggle('hidden')
55-
if (currentSection > 1) {
56-
if (btnPrev.classList.contains('invisible')) {
57-
btnPrev.classList.remove('invisible')
74+
sections[currentSection].classList.toggle('hidden')
75+
76+
if (currentSection == sectionsArray.length - 1) {
77+
btnNextContainer.classList.toggle('invisible')
78+
}
79+
80+
if (currentSection > 0) {
81+
if (btnBackContainer.classList.contains('invisible')) {
82+
btnBackContainer.classList.remove('invisible')
5883
}
5984
}
85+
86+
btnBackSupportText.textContent = sectionsArray[currentSection - 1] || ''
87+
btnNextSupportText.textContent = sectionsArray[currentSection + 1] || ''
6088
})
6189

6290

0 commit comments

Comments
 (0)