Add disable hs buttons when 0 annotations

Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
2025-05-03 20:04:00 -07:00
parent 9953dff4a0
commit 859183fe2e
2 changed files with 18 additions and 7 deletions

View File

@@ -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()'

View File

@@ -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 = {}
}