Skip to content

Commit 1f2627b

Browse files
committed
Remove unused code
Remove unused imports, variables, and functions. `QuizManager.initialize` was a bit of a special case; it wasn't being used, but it was a useful function. Its functionality was being duplicated in `main.js`, but it seemed cleaner to have it handled by the function. So I rewrote it so that the functionality was implemented only in the function.
1 parent 1a2fe67 commit 1f2627b

9 files changed

Lines changed: 17 additions & 171 deletions

File tree

templates/js/annotationOverlay.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const PPT_EMU = { W: 9_144_000, H: 6_858_000 }; // PowerPoint slide size in EMUs
2-
31
function ensureStage(container) {
42
let stage = container.querySelector(".annotation-stage");
53
if (!stage) {
@@ -162,7 +160,4 @@ function attachAutoscale(container) {
162160
});
163161
ro.observe(container);
164162
stage.__resizeObs = ro;
165-
}
166-
167-
// Optional global for non-module usage
168-
window.AnnotationOverlay = { clearAnnotations, drawAnnotations, loadAndDrawAnnotations };
163+
}

templates/js/api.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,6 @@ export async function fetchCombinedData() {
2222
}
2323
}
2424

25-
export async function fetchMockBoneData() {
26-
try {
27-
const response = await fetch(API_CONFIG.ENDPOINTS.MOCK_BONE_DATA);
28-
if (!response.ok) {
29-
throw new Error(`HTTP error! status: ${response.status}`);
30-
}
31-
const data = await response.json();
32-
return data;
33-
} catch (error) {
34-
console.error("Error fetching mock bone data:", error);
35-
return null;
36-
}
37-
}
38-
3925
/**
4026
* Fetch full bone data (description + images) for a single bone from the backend API.
4127
* The backend pulls these files from the data GitHub branch.

templates/js/coloredRegionsOverlay.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -420,13 +420,6 @@ export async function displayColoredRegions(imageElement, boneId, imageIndex = 0
420420
console.warn(`[ColoredRegions] Invalid imageIndex ${imageIndex}, expected 0-${regionData.images.length - 1}`);
421421
return;
422422
}
423-
} else if (regionData.colored_regions) {
424-
console.log("[ColoredRegions] Using old single-image structure");
425-
regionsToDisplay = regionData.colored_regions;
426-
imageData = {
427-
width: regionData.image_dimensions?.width,
428-
height: regionData.image_dimensions?.height
429-
};
430423
}
431424

432425
if (!regionsToDisplay || regionsToDisplay.length === 0) {

templates/js/dropdowns.js

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
11
import { loadDescription } from "./description.js";
2-
import { displayBoneImages, clearImages, showPlaceholder } from "./imageDisplay.js";
3-
import { loadAndDrawAnnotations, clearAnnotations } from "./annotationOverlay.js";
2+
import {displayBoneImages, showPlaceholder} from "./imageDisplay.js";
3+
import {clearAnnotations} from "./annotationOverlay.js";
44
import {fetchBoneData} from "./api.js";
55

66
document.addEventListener("DOMContentLoaded", () => {
77
showPlaceholder();
88
});
99

10-
let _boneById = {}; // filled in setupDropdownListeners
11-
1210
function getImageStage() {
1311
return (document.getElementById("bone-image-container"));
1412
}
1513

16-
// Function maybeLoadAnnotations: Logic removed. Annotation URL construction is now in the listeners.
17-
async function maybeLoadAnnotations(boneId) {
18-
const stage = getImageStage();
19-
if (!stage) return;
20-
21-
// remove any previous overlay
22-
clearAnnotations(stage);
23-
stage.classList.remove("with-annotations");
24-
25-
// Note: The logic for loading the annotation file used to be here, but has been
26-
// refactored into the dropdown listeners (using the 'opts' object) to use the API endpoint.
27-
}
28-
2914
// Backend API base (runs on 8000)
3015
const API_BASE = "http://127.0.0.1:8000";
3116

@@ -82,8 +67,6 @@ export function setupDropdownListeners(combinedData) {
8267

8368
if (!combinedData) return;
8469

85-
_boneById = Object.fromEntries((combinedData.bones || []).map(b => [b.id, b]));
86-
8770
// Boneset change
8871
bonesetSelect.addEventListener("change", (e) => {
8972
const selectedBonesetId = e.target.value;

templates/js/imageDisplay.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -178,21 +178,6 @@ function displaySingleImage(image, container, options = {}) {
178178
}
179179
}
180180

181-
/* Two images (with rotation template) */
182-
const TWO_IMAGE_ROTATION = {
183-
left: { rot_deg: -16.999, flipH: false },
184-
right: { rot_deg: 0, flipH: false },
185-
};
186-
187-
function applyRotation(imgEl, { rot_deg = 0, flipH = false } = {}) {
188-
const parts = [];
189-
if (flipH) parts.push("scaleX(-1)");
190-
if (rot_deg && Math.abs(rot_deg) > 0.001) parts.push(`rotate(${rot_deg}deg)`);
191-
imgEl.style.transform = parts.join(" ") || "none";
192-
imgEl.style.transformOrigin = "50% 50%";
193-
imgEl.style.willChange = "transform";
194-
}
195-
196181
function displayTwoImages(images, container, options = {}) {
197182
const captions = getCaptionsForBone(currentBoneId);
198183

templates/js/main.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { fetchCombinedData, fetchBoneData } from "./api.js";
22
import { populateBonesetDropdown, setupDropdownListeners } from "./dropdowns.js";
3-
import { initializeSidebar } from "./sidebar.js";
3+
import {initializeSidebar} from "./sidebar.js";
44
import { setupNavigation, setBoneAndSubbones, disableButtons } from "./navigation.js";
55
import { loadDescription } from "./description.js";
66
import { displayBoneData, clearViewer } from "./viewer.js";
@@ -24,15 +24,7 @@ document.addEventListener("DOMContentLoaded", async () => {
2424
setupDropdownListeners(combinedData);
2525

2626
try {
27-
quizManager.allBones = combinedData.bones || [];
28-
quizManager.allSubbones = combinedData.subbones || [];
29-
quizManager.createMasterQuestionPool();
30-
if (quizManager.masterQuestionPool.length >= 4) {
31-
quizManager.setupEventListeners();
32-
console.log("Quiz system initialized successfully with", quizManager.masterQuestionPool.length, "items");
33-
} else {
34-
console.warn("Not enough items for quiz:", quizManager.masterQuestionPool.length);
35-
}
27+
await quizManager.initialize(combinedData);
3628
} catch (error) {
3729
console.error("Error initializing quiz:", error);
3830
}

templates/js/quiz.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import {fetchBoneData, fetchCombinedData} from "./api.js";
1+
import {fetchBoneData} from "./api.js";
22
import {displayColoredRegions} from "./coloredRegionsOverlay.js";
33

44
class QuizManager {
55
constructor() {
66
this.questions = [];
77
this.currentQuestionIndex = 0;
88
this.score = 0;
9-
this.isQuizActive = false;
109
this.totalQuestions = 10;
1110
this.allBones = [];
1211
this.allSubbones = [];
@@ -17,25 +16,18 @@ class QuizManager {
1716
/**
1817
* Initialize the quiz system
1918
*/
20-
async initialize() {
21-
try {
22-
const data = await fetchCombinedData();
23-
this.allBones = data.bones || [];
24-
this.allSubbones = data.subbones || [];
25-
26-
this.createMasterQuestionPool();
19+
async initialize(data) {
20+
this.allBones = data.bones || [];
21+
this.allSubbones = data.subbones || [];
2722

28-
if (this.masterQuestionPool.length < 4) {
29-
console.error("Not enough items to create a quiz. Need at least 4 items.");
30-
return false;
31-
}
23+
this.createMasterQuestionPool();
3224

33-
this.setupEventListeners();
34-
return true;
35-
} catch (error) {
36-
console.error("Error initializing quiz:", error);
37-
return false;
25+
if (this.masterQuestionPool.length < 4) {
26+
throw new Error(`Not enough items to create a quiz. Need at least 4 items. (Quiz pool length: ${this.masterQuestionPool.length})`);
3827
}
28+
29+
this.setupEventListeners();
30+
return true;
3931
}
4032

4133
/**
@@ -238,7 +230,6 @@ startQuiz() {
238230
// Reset quiz state
239231
this.currentQuestionIndex = 0;
240232
this.score = 0;
241-
this.isQuizActive = true;
242233
this.answered = false;
243234

244235
// Show quiz container, hide main content
@@ -354,7 +345,7 @@ startQuiz() {
354345

355346
choicesContainer.innerHTML = "";
356347

357-
question.allAnswers.forEach((answer, index) => {
348+
question.allAnswers.forEach(answer => {
358349
const button = document.createElement("button");
359350
button.className = "quiz-choice-btn";
360351
button.textContent = answer;

templates/js/sidebar.js

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -29,47 +29,4 @@ export async function initializeSidebar() {
2929
}
3030
});
3131
}
32-
}
33-
34-
export async function loadHelpButton() {
35-
const helpButtonContainer = document.getElementById("help-button-container");
36-
if (helpButtonContainer) {
37-
try {
38-
const response = await fetch("helpButton.html");
39-
const helpButtonHTML = await response.text();
40-
helpButtonContainer.innerHTML = helpButtonHTML;
41-
42-
const helpButton = document.getElementById("text-button-Help");
43-
const helpModal = document.getElementById("help-modal");
44-
const closeHelpModal = document.getElementById("close-help-modal");
45-
46-
if (helpButton && helpModal && closeHelpModal) {
47-
// Handle click events
48-
helpButton.addEventListener("click", () => {
49-
helpModal.classList.add("is-visible");
50-
});
51-
52-
closeHelpModal.addEventListener("click", () => {
53-
helpModal.classList.remove("is-visible");
54-
});
55-
56-
// Handle keyboard events
57-
helpButton.addEventListener("keydown", (event) => {
58-
if (event.key === "Enter" || event.key === " ") {
59-
event.preventDefault();
60-
helpModal.classList.add("is-visible");
61-
}
62-
});
63-
64-
// Close on escape key
65-
document.addEventListener("keydown", (event) => {
66-
if (event.key === "Escape" && helpModal.classList.contains("is-visible")) {
67-
helpModal.classList.remove("is-visible");
68-
}
69-
});
70-
}
71-
} catch (error) {
72-
console.error("Error loading help button:", error);
73-
}
74-
}
75-
}
32+
}

templates/js/viewer.js

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,3 @@
1-
/**
2-
* Displays bone image with error handling for broken URLs
3-
* @param {Object} boneData - The bone object from mock data
4-
*/
5-
export function displayBoneImage(boneData) {
6-
const boneImage = document.getElementById("bone-image");
7-
if (!boneImage) {
8-
console.error("Bone image element not found");
9-
return;
10-
}
11-
12-
if (boneData.image_url) {
13-
boneImage.src = boneData.image_url;
14-
boneImage.alt = `${boneData.name} bone image`;
15-
boneImage.style.display = "block";
16-
17-
// Handle image load errors gracefully
18-
boneImage.onerror = () => {
19-
console.warn(`Failed to load image for ${boneData.name}: ${boneData.image_url}`);
20-
boneImage.src = "https://via.placeholder.com/600x400/CCCCCC/666666?text=Image+Load+Failed";
21-
boneImage.alt = `${boneData.name} - Image failed to load`;
22-
};
23-
24-
// Clear any previous error handlers when image loads successfully
25-
boneImage.onload = () => {
26-
boneImage.onerror = null;
27-
};
28-
} else {
29-
// Handle missing image_url
30-
boneImage.src = "https://via.placeholder.com/600x400/CCCCCC/666666?text=No+Image+Available";
31-
boneImage.alt = `${boneData.name} - No image available`;
32-
boneImage.style.display = "block";
33-
console.warn(`No image URL provided for bone: ${boneData.name}`);
34-
}
35-
}
36-
371
/**
382
* Displays annotations list for the selected bone
393
* @param {Array} annotations - Array of annotation objects

0 commit comments

Comments
 (0)