Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { setupNavigation, setBoneAndSubbones, disableButtons } from './navigation.js';

Check failure on line 1 in js/main.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
import { updateDescription } from './description.js'; // Assuming you already have this

Check failure on line 2 in js/main.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote

document.addEventListener('DOMContentLoaded', () => {

Check failure on line 4 in js/main.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
const prevButton = document.getElementById('prev-button');

Check failure on line 5 in js/main.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
const nextButton = document.getElementById('next-button');

Check failure on line 6 in js/main.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
const subboneDropdown = document.getElementById('subbone-dropdown');

Check failure on line 7 in js/main.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote

setupNavigation(prevButton, nextButton, subboneDropdown, updateDescription);

// Example: when a new bone is selected
document.getElementById('bone-dropdown').addEventListener('change', (event) => {

Check failure on line 12 in js/main.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote

Check failure on line 12 in js/main.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
const selectedBone = event.target.value;
const selectedSubbones = getSubbonesForBone(selectedBone); // You need to implement this

setBoneAndSubbones(selectedBone, selectedSubbones);

// Update the dropdown options
populateSubboneDropdown(subboneDropdown, selectedSubbones);

disableButtons(prevButton, nextButton);
});
});

function populateSubboneDropdown(dropdown, subbones) {
dropdown.innerHTML = '';

Check failure on line 26 in js/main.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
subbones.forEach((subbone, index) => {
const option = document.createElement('option');

Check failure on line 28 in js/main.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
option.value = index;
option.textContent = subbone;
dropdown.appendChild(option);
});
}

// Dummy placeholder for subbones fetching
function getSubbonesForBone(bone) {
const exampleData = {
Humerus: ['Lateral Epicondyle', 'Medial Epicondyle'],
Ulna: ['Olecranon', 'Coronoid Process']
};
return exampleData[bone] || [];
}
49 changes: 49 additions & 0 deletions js/navigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
let currentBone = null;
let currentSubboneIndex = -1;
let subbones = [];

export function setupNavigation(prevButton, nextButton, subboneDropdown, updateDescription) {
prevButton.addEventListener('click', () => {
prevSubbone();
updateUI(subboneDropdown, updateDescription);
});

nextButton.addEventListener('click', () => {
nextSubbone();
updateUI(subboneDropdown, updateDescription);
});

disableButtons(prevButton, nextButton);
}

export function setBoneAndSubbones(bone, boneSubbones) {
currentBone = bone;
subbones = boneSubbones || [];
currentSubboneIndex = subbones.length > 0 ? 0 : -1;
}

function prevSubbone() {
if (currentSubboneIndex > 0) {
currentSubboneIndex--;
}
}

function nextSubbone() {
if (currentSubboneIndex < subbones.length - 1) {
currentSubboneIndex++;
}
}

function updateUI(subboneDropdown, updateDescription) {
if (subbones.length === 0 || currentSubboneIndex === -1) return;

subboneDropdown.selectedIndex = currentSubboneIndex;
const selectedSubbone = subbones[currentSubboneIndex];
updateDescription(selectedSubbone);
}

export function disableButtons(prevButton, nextButton) {
const disabled = subbones.length === 0;
prevButton.disabled = disabled;
nextButton.disabled = disabled;
}
2 changes: 1 addition & 1 deletion templates/boneset.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ <h3>Description</h3>
</div>
</div>
</div>

<script type="module" src="js/main.js"></script>

</body>

</html>