From 4795405fe7870ccf5e467b97ab5f041181806bfe Mon Sep 17 00:00:00 2001 From: franmagn Date: Thu, 23 Oct 2025 19:30:55 +0200 Subject: [PATCH] refactor(#4): guard jQuery according to the scary rabbit --- src/AnnotationControl/annotationPanel.js | 25 +++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/AnnotationControl/annotationPanel.js b/src/AnnotationControl/annotationPanel.js index a1d6b8f..eb9f429 100644 --- a/src/AnnotationControl/annotationPanel.js +++ b/src/AnnotationControl/annotationPanel.js @@ -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) {} } @@ -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 @@ -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' && @@ -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 } @@ -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() @@ -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) { @@ -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