Convert to image handler hook based viewer insertion

Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
2024-10-22 19:58:02 -07:00
parent b31d9f3925
commit 5d90da0fda
3 changed files with 20 additions and 4 deletions

View File

@@ -16,12 +16,25 @@ class GlModelViewer extends ImageHandler {
}
public static function onBeforePageDisplay(OutputPage $out) {
preg_match('/(<a href="\S*?\.(glb|gltf"))/',$out->getHTML(),$findGltf);
preg_match('/(<model-viewer src="\S*?\.(glb|gltf"))/',$out->getHTML(),$findGltf);
if ($findGltf[0]) {
$out->addModules('ext.glmv');
}
}
public static function onImageBeforeProduceHTML( DummyLinker &$linker, Title &$title, &$file, array &$frameParams, array &$handlerParams, &$time, &$result, Parser $parser, string &$query, &$widthOption ) {
if ($file->getMimeType() !== 'model/gltf-binary') {
return true;
}
$result = '<model-viewer src=' . $file->getFullUrl() . '></model-viewer>';
#echo '<script>';
#GlModelViewer::console_log($handlerParams);
#GlModelViewer::console_log($frameParams);
#GlModelViewer::console_log($file->getDescriptionText());
#echo '</script>';
return false;
}
public static function console_log($data, $add_script_tags = false) {
$command = 'console.log('. json_encode($data, JSON_HEX_TAG).');';
if ($add_script_tags) {