Skip to content

Commit

Permalink
Merge pull request #9 from gaiborjosue/reload-vanilla
Browse files Browse the repository at this point in the history
feat: SliceDrop reloaded
  • Loading branch information
haehn authored Oct 31, 2024
2 parents d4d08ed + 193d1a0 commit f3e1b15
Show file tree
Hide file tree
Showing 21 changed files with 2,313 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@

# nfs
*.nfs*

.vscode/
88 changes: 88 additions & 0 deletions reload/dropHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import viewer from "./viewer.js";

class DropZoneHandler {
constructor() {
this.dropZone = document.getElementById("dropZone");
this.dropText = document.getElementById("dropText");
this.fileInput = document.getElementById("fileInput");
this.drawerContainer = document.querySelector(".drawer-container");
this.landingContainer = document.getElementById("landingContainer");
this.viewerContainer = document.getElementById("viewerContainer");
this.initialize();
}

initialize() {
// Bind event listeners
this.dropZone.addEventListener(
"dragenter",
this.handleDragEnter.bind(this)
);
this.dropZone.addEventListener(
"dragleave",
this.handleDragLeave.bind(this)
);
this.dropZone.addEventListener("dragover", this.handleDragOver.bind(this));
this.dropZone.addEventListener("drop", this.handleDrop.bind(this));
this.fileInput.addEventListener("change", this.handleFileSelect.bind(this));
}

showViewer() {
this.landingContainer.classList.add("hidden");
this.viewerContainer.classList.remove("hidden");
this.drawerContainer.classList.add("visible");
}

handleDragEnter(e) {
e.preventDefault();
e.stopPropagation();
this.dropZone.classList.add("dragging");
this.dropText.textContent = "Drop to load files";
}

handleDragLeave(e) {
e.preventDefault();
e.stopPropagation();
this.dropZone.classList.remove("dragging");
this.dropText.textContent = "Drag & drop your files here";
}

handleDragOver(e) {
e.preventDefault();
e.stopPropagation();
}

async handleDrop(e) {
e.preventDefault();
e.stopPropagation();
this.dropZone.classList.remove("dragging");

const files = Array.from(e.dataTransfer.files);
const results = await Promise.all(
files.map((file) => viewer.loadFile(file))
);

if (results.some(Boolean)) {
this.dropZone.classList.add("hidden");
this.drawerContainer.classList.add("visible");
viewer.updateDrawerStates(); // Force update after all files are loaded
this.showViewer();
}
}

async handleFileSelect(e) {
const files = Array.from(e.target.files);
const results = await Promise.all(
files.map((file) => viewer.loadFile(file))
);

if (results.some(Boolean)) {
this.dropZone.classList.add("hidden");
this.drawerContainer.classList.add("visible");
viewer.updateDrawerStates(); // Force update after all files are loaded
this.showViewer();
}
}
}

// Initialize drop zone handler
new DropZoneHandler();
Binary file added reload/images/14yrold.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reload/images/2yrold_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions reload/images/SliceDropReloaded.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reload/images/avf_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reload/images/brainstem_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reload/images/dicom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reload/images/fibers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reload/images/slicedrop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reload/images/slicedrop_transparent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reload/images/surface.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit f3e1b15

Please sign in to comment.