Skip to content

Commit

Permalink
refactor(#4): guard jQuery according to the scary rabbit
Browse files Browse the repository at this point in the history
  • Loading branch information
franmagn committed Oct 23, 2025
1 parent 6f45475 commit 4795405
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/AnnotationControl/annotationPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ export function initAnnotationsPanel(viewer) {
menu.appendChild(panel)
}

if ($(menu).accordion) {
if (window.jQuery && window.jQuery(menu).accordion) {
try {
$(menu).accordion('refresh')
window.jQuery(menu).accordion('refresh')
} catch (e) {}
}

Expand Down Expand Up @@ -118,6 +118,7 @@ export function initAnnotationsPanel(viewer) {
// Helper: safe accessors and utilities for jsTree and annotation descriptions
function _getJSTree() {
try {
if (!window.jQuery) return null
return $('#jstree_scene').jstree && $('#jstree_scene').jstree()
} catch (e) {
return null
Expand All @@ -126,6 +127,7 @@ export function initAnnotationsPanel(viewer) {

function _getJSTreeInstance() {
try {
if (!window.jQuery || !window.jQuery.jstree) return null
return (
($('#jstree_scene').jstree && $('#jstree_scene').jstree(true)) ||
(typeof $.jstree !== 'undefined' &&
Expand Down Expand Up @@ -260,7 +262,7 @@ export function initAnnotationsPanel(viewer) {
) {
const empty = document.createElement('div')
empty.className = 'annotation-empty'
empty.textContent = 'No saved positions yet'
empty.textContent = 'No saved locations yet'
targetContainer.appendChild(empty)
return
}
Expand Down Expand Up @@ -434,10 +436,14 @@ export function initAnnotationsPanel(viewer) {

// remove from sidebar/tree
try {
$('#jstree_scene').jstree('delete_node', node.id)
if (window.jQuery && window.jQuery.fn.jstree) {
window.jQuery('#jstree_scene').jstree('delete_node', node.id)
}
} catch (e) {
try {
$.jstree.reference(node.id).delete_node(node.id)
if (window.jQuery && window.jQuery.jstree && window.jQuery.jstree.reference) {
window.jQuery.jstree.reference(node.id).delete_node(node.id)
}
} catch (_) {}
}
updateAnnotationsList()
Expand Down Expand Up @@ -874,7 +880,8 @@ export function initAnnotationsPanel(viewer) {
if (!uuid) return
// update jsTree node text
try {
const tree = $('#jstree_scene').jstree && $('#jstree_scene').jstree()
if (!window.jQuery) return
const tree = window.jQuery('#jstree_scene').jstree && window.jQuery('#jstree_scene').jstree()
if (tree) {
const annotationsRoot = tree.get_json('annotations')
if (annotationsRoot && annotationsRoot.children) {
Expand Down Expand Up @@ -926,7 +933,11 @@ export function initAnnotationsPanel(viewer) {
'menu_camera_annotations'
)
if (annotationHeader && annotationHeader.nextElementSibling) {
$(annotationHeader.nextElementSibling).slideDown()
if (window.jQuery) {
window.jQuery(annotationHeader.nextElementSibling).slideDown()
} else {
annotationHeader.nextElementSibling.style.display = ''
}
}
// Capture current camera view (position) at the moment the user clicks Add
let camPos = null
Expand Down

0 comments on commit 4795405

Please sign in to comment.