Add model-viewer script via MW php method

Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
2024-10-25 18:59:04 -07:00
parent 41354e2d70
commit 36c36dd16e
2 changed files with 5 additions and 8 deletions

View File

@@ -39,6 +39,11 @@ class GlModelViewer extends ImageHandler {
public static function onBeforePageDisplay(OutputPage $out) { public static function onBeforePageDisplay(OutputPage $out) {
preg_match('/(<model-viewer src="\S*?\.(glb|gltf"))/',$out->getHTML(),$findGltf); preg_match('/(<model-viewer src="\S*?\.(glb|gltf"))/',$out->getHTML(),$findGltf);
if ($findGltf[0]) { if ($findGltf[0]) {
$mvScriptAttr = array(
'src' => 'https://ajax.googleapis.com/ajax/libs/model-viewer/3.5.0/model-viewer.min.js',
'type' => 'module'
);
$out->addHeadItems(Html::rawElement('script',$mvScriptAttr));
$out->addModules('ext.glmv'); $out->addModules('ext.glmv');
} }
} }
@@ -80,8 +85,6 @@ class GlModelViewer extends ImageHandler {
public static function onImageOpenShowImageInlineBefore( $imagepage, $out ){ public static function onImageOpenShowImageInlineBefore( $imagepage, $out ){
$file = $imagepage->getFile(); $file = $imagepage->getFile();
if ($file->getMimeType() == 'model/gltf-binary') { if ($file->getMimeType() == 'model/gltf-binary') {
$out->addModules('ext.glmv');
$viewer = self::buildViewer($file->getDescriptionText(), $file->getFullUrl(), ['class' => 'view-default']); $viewer = self::buildViewer($file->getDescriptionText(), $file->getFullUrl(), ['class' => 'view-default']);
$out->addHtml(Html::rawElement('div',['id' => 'file', 'class' => 'fullModelView'],$viewer)); $out->addHtml(Html::rawElement('div',['id' => 'file', 'class' => 'fullModelView'],$viewer));
} }

View File

@@ -1,9 +1,3 @@
let modelLoad = document.createElement('script')
modelLoad.setAttribute('type','module')
modelLoad.setAttribute('src','https://ajax.googleapis.com/ajax/libs/model-viewer/3.5.0/model-viewer.min.js')
let headElem = document.getElementsByTagName('head')[0]
headElem.appendChild(modelLoad)
/** /**
* Sets listener and attributes on model-viewer to * Sets listener and attributes on model-viewer to
* allow for click registering of a new hotspot * allow for click registering of a new hotspot