From 859183fe2ea18ceacb2bc78fee0ed6ff1f556e1c Mon Sep 17 00:00:00 2001 From: Justin Georgi Date: Sat, 3 May 2025 20:04:00 -0700 Subject: [PATCH] Add disable hs buttons when 0 annotations Signed-off-by: Justin Georgi --- includes/GlModelTransformOutput.php | 19 ++++++++++++------- modules/glmv-mvconfig.js | 6 ++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/includes/GlModelTransformOutput.php b/includes/GlModelTransformOutput.php index 572ddb4..68fa8c9 100644 --- a/includes/GlModelTransformOutput.php +++ b/includes/GlModelTransformOutput.php @@ -183,10 +183,10 @@ class GlModelTransformOutput extends MediaTransformOutput { $attrModelView = array_merge(['src' => $srcUrl, 'class' => 'mv-model', 'interpolation-decay' => '100', 'interaction-prompt' => 'none'], $attrModelView); $attrModelView['style'] = 'width: 100%; height: 100%;'; $attrModelView['onload'] = 'modelLoaded(event)'; - $hotspotHtml = (isset($hotspots)) ? implode($hotspots) : ''; + $hotspotHtml = (!empty($hotspots)) ? implode($hotspots) : ''; $elModel = Html::rawElement('model-viewer', $attrModelView, $hotspotHtml); - $elMenu = self::buildViewMenu(); + $elMenu = self::buildViewMenu(!empty($hotspots)); $elFileLink = ''; if (!isset($viewParams['preview']) && $context->getTitle() != $this->file->getTitle()) { @@ -213,9 +213,10 @@ class GlModelTransformOutput extends MediaTransformOutput { /** * Build the button menu used for viewer actions * + * @param bool $annotsDrawn true to enable the annotation buttons * @return string */ - private static function buildViewMenu() { + private static function buildViewMenu($annotsDrawn) { $attrMenu = array( 'class' => 'glmv-menu awaiting-model', 'style' => 'display: none;' @@ -230,13 +231,15 @@ class GlModelTransformOutput extends MediaTransformOutput { $gotoUrl = $mainConfig->get( 'ExtensionAssetsPath' ) . '/GlModelViewer/resources/goto_hs.svg'; $attrMenuButtonPrev = array ( - 'class' => 'glmv-menu-button prev-hs disable-on-hide', + 'class' => 'glmv-menu-button prev-hs disable-on-hide disable-on-none', + 'disabled' => !$annotsDrawn, 'onclick' => 'prevAnnotation(event.target.closest(".glmv-container").querySelector("model-viewer"))', 'onmousedown' => 'event.stopPropagation()', 'ontouchstart' => 'event.stopPropagation()' ); $attrMenuButtonNext = array ( - 'class' => 'glmv-menu-button next-hs disable-on-hide', + 'class' => 'glmv-menu-button next-hs disable-on-hide disable-on-none', + 'disabled' => !$annotsDrawn, 'onclick' => 'nextAnnotation(event.target.closest(".glmv-container").querySelector("model-viewer"))', 'onmousedown' => 'event.stopPropagation()', 'ontouchstart' => 'event.stopPropagation()' @@ -244,7 +247,8 @@ class GlModelTransformOutput extends MediaTransformOutput { $slideUrl = $mainConfig->get( 'ExtensionAssetsPath' ) . '/GlModelViewer/resources/hs_slideshow.svg'; $attrMenuButtonSlides = array ( - 'class' => 'glmv-menu-button disable-on-hide', + 'class' => 'glmv-menu-button disable-on-hide disable-on-none', + 'disabled' => !$annotsDrawn, 'onclick' => 'event.target.toggleAttribute("toggled"); slideshowAnnotations(event.target.closest(".glmv-container").querySelector("model-viewer"))', 'onmousedown' => 'event.stopPropagation()', 'ontouchstart' => 'event.stopPropagation()' @@ -252,7 +256,8 @@ class GlModelTransformOutput extends MediaTransformOutput { $hideUrl = $mainConfig->get( 'ExtensionAssetsPath' ) . '/GlModelViewer/resources/hs_hide.svg'; $attrMenuButtonHide = array ( - 'class' => 'glmv-menu-button', + 'class' => 'glmv-menu-button disable-on-none', + 'disabled' => !$annotsDrawn, 'onclick' => 'event.target.toggleAttribute("toggled"); toggleAnnotations(event.target.closest(".glmv-container").querySelector("model-viewer"))', 'onmousedown' => 'event.stopPropagation()', 'ontouchstart' => 'event.stopPropagation()' diff --git a/modules/glmv-mvconfig.js b/modules/glmv-mvconfig.js index 532308c..9a1e1e6 100644 --- a/modules/glmv-mvconfig.js +++ b/modules/glmv-mvconfig.js @@ -19,6 +19,12 @@ extractMvconfig = function() { if (mvconfig.annotations === undefined) { mvconfig.annotations = {} } + const mView = $('model-viewer')[0] + const hsButtons = [...mView.parentElement.querySelectorAll('.disable-on-none')] + hsButtons.forEach( mb => { + mb.toggleAttribute('disabled',$.isEmptyObject(mvconfig.annotations)) + }) + if (mvconfig.annotationSets === undefined) { mvconfig.annotationSets = {} }