Convert to image handler hook based viewer insertion
Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
"author": "Justin Georgi",
|
||||
"url": "https://gitea.azgeorgis.net/jgeorgi/mwModelViewer",
|
||||
"description": "This extension allows .glb and .gltf files to be added, displayed, and annotated in MediaWiki",
|
||||
"version": "0.0.3",
|
||||
"version": "0.0.4",
|
||||
"license-name": "MIT",
|
||||
"type": "media",
|
||||
"manifest_version": 2,
|
||||
@@ -13,7 +13,8 @@
|
||||
"Hooks": {
|
||||
"MimeMagicInit": "GlModelViewer::onMimeMagicInit",
|
||||
"MimeMagicImproveFromExtension": "GlModelViewer::onMimeMagicImproveFromExtension",
|
||||
"BeforePageDisplay": "GlModelViewer::onBeforePageDisplay"
|
||||
"BeforePageDisplay": "GlModelViewer::onBeforePageDisplay",
|
||||
"ImageBeforeProduceHTML": "GlModelViewer::onImageBeforeProduceHTML"
|
||||
},
|
||||
"ResourceFileModulePaths": {
|
||||
"localBasePath": "modules",
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -6,6 +6,7 @@ headElem.appendChild(modelLoad)
|
||||
let urlProm, dataProm
|
||||
let isFilePageImage = false
|
||||
|
||||
/*
|
||||
let glbElems = document.querySelectorAll('.mw-body-content [href$=".glb"][title$=".glb"')
|
||||
if (glbElems.length > 0) {
|
||||
[...glbElems].forEach((ge, idx) => {
|
||||
@@ -65,4 +66,5 @@ async function getModelMeta(getTitle) {
|
||||
"page": getTitle
|
||||
});
|
||||
return JSON.parse($(metaApiResp.parse.text['*']).find('pre').text() || '{}')
|
||||
}
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user