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) {
preg_match('/(<model-viewer src="\S*?\.(glb|gltf"))/',$out->getHTML(),$findGltf);
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');
}
}
@@ -80,8 +85,6 @@ class GlModelViewer extends ImageHandler {
public static function onImageOpenShowImageInlineBefore( $imagepage, $out ){
$file = $imagepage->getFile();
if ($file->getMimeType() == 'model/gltf-binary') {
$out->addModules('ext.glmv');
$viewer = self::buildViewer($file->getDescriptionText(), $file->getFullUrl(), ['class' => 'view-default']);
$out->addHtml(Html::rawElement('div',['id' => 'file', 'class' => 'fullModelView'],$viewer));
}