Add mouse coordinate view with click to copy #4
@@ -32,7 +32,21 @@
|
|||||||
"AutoloadNamespaces": {
|
"AutoloadNamespaces": {
|
||||||
"MediaWiki\\Extension\\AnatImageViewer\\": "includes/"
|
"MediaWiki\\Extension\\AnatImageViewer\\": "includes/"
|
||||||
},
|
},
|
||||||
|
"Hooks": {
|
||||||
|
"AlternateEditPreview": "MediaWiki\\Extension\\AnatImageViewer\\AnnotationHooks::onAlternateEditPreview"
|
||||||
|
},
|
||||||
"ContentHandlers": {
|
"ContentHandlers": {
|
||||||
"annotation": "MediaWiki\\Extension\\AnatImageViewer\\AnnotationHandler"
|
"annotation": "MediaWiki\\Extension\\AnatImageViewer\\AnnotationHandler"
|
||||||
|
},
|
||||||
|
"ResourceFileModulePaths": {
|
||||||
|
"localBasePath": "modules",
|
||||||
|
"remoteExtPath": "GlModelViewer/modules"
|
||||||
|
},
|
||||||
|
"ResourceModules": {
|
||||||
|
"ext.annot.prev": {
|
||||||
|
"packageFiles": [
|
||||||
|
"annot-prev.js"
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ class AnnotationHandler extends CodeContentHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$output->setText( self::buildSvg($metadata) );
|
$output->setText( '<div id="svg-wrapper" style="position: relative;">' . self::buildSvg($metadata) . '</div>' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -124,8 +124,8 @@ class AnnotationHandler extends CodeContentHandler {
|
|||||||
'xmlns' => 'http://www.w3.org/2000/svg',
|
'xmlns' => 'http://www.w3.org/2000/svg',
|
||||||
'width' => $baseWidth,
|
'width' => $baseWidth,
|
||||||
'height' => $baseHeight,
|
'height' => $baseHeight,
|
||||||
'style' => 'width: 100%; height: auto;'
|
'style' => 'width: 100%; height: auto;',
|
||||||
|
'mwScale' => $fixScale
|
||||||
);
|
);
|
||||||
$elCompass = '';
|
$elCompass = '';
|
||||||
$useCompass = '';
|
$useCompass = '';
|
||||||
|
|||||||
@@ -2,22 +2,25 @@
|
|||||||
namespace MediaWiki\Extension\AnatImageViewer;
|
namespace MediaWiki\Extension\AnatImageViewer;
|
||||||
|
|
||||||
class AnnotationHooks {
|
class AnnotationHooks {
|
||||||
public static function registrationCallback() {
|
|
||||||
define( 'CONTENT_MODEL_ANNOTATION', 'annotation' );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the content handler for annotations
|
* MWHook: Display model when model file page edits are previewed
|
||||||
*
|
*
|
||||||
* @param Title $title
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/AlternateEditPreview
|
||||||
* @param string &$model
|
*
|
||||||
* @return void
|
* @param EditPage $editor access to information about the edit page itself
|
||||||
|
* @param Content $content access to the current content of the editor
|
||||||
|
* @param string &$previewHTML by reference access to the resultant compiled preview html
|
||||||
|
* @param ?ParserOutput &$parserOutput
|
||||||
|
* @return bool|void True to continue default processing or false to abort for custom processing
|
||||||
*/
|
*/
|
||||||
public static function onContentHandlerDefaultModelFor( $title, &$model ) {
|
public static function onAlternateEditPreview( $editor, $content, string &$previewHTML, ?ParserOutput &$parserOutput ) {
|
||||||
|
$title = $editor->getTitle();
|
||||||
if ( $title->getNamespace() === NS_AV_ANNOT ) {
|
if ( $title->getNamespace() === NS_AV_ANNOT ) {
|
||||||
self::console_log('Found fucking thing!',true);
|
$out = $editor->getContext()->getOutput();
|
||||||
$model = CONTENT_MODEL_ANNOTATION;
|
$out->addModules('ext.annot.prev');
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
21
modules/annot-prev.js
Normal file
21
modules/annot-prev.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
console.log('Previewing Annotation page...')
|
||||||
|
elSvgCont = document.querySelector('div#svg-wrapper')
|
||||||
|
elSvg = elSvgCont.childNodes[0]
|
||||||
|
elCoordBox = document.createElement('div')
|
||||||
|
elCoordBox.style.display='none'
|
||||||
|
elCoordBox.style.position='absolute'
|
||||||
|
elCoordBox.style.padding='3px'
|
||||||
|
elCoordBox.style.background='#ffffff99'
|
||||||
|
elCoordBox.style.border='1px solid black'
|
||||||
|
elSvgCont.appendChild(elCoordBox)
|
||||||
|
elScale = elSvg.getAttribute('mwscale')
|
||||||
|
elSvgCont.addEventListener('click', () => {navigator.clipboard.writeText(`[${elCoordBox.textContent}]`)})
|
||||||
|
elSvgCont.addEventListener('mouseenter', () => {elCoordBox.style.display='block'})
|
||||||
|
elSvgCont.addEventListener('mouseleave', () => {elCoordBox.style.display='none'})
|
||||||
|
elSvgCont.addEventListener('mousemove',(e) => {
|
||||||
|
xPoint = ((e.offsetX / elSvgCont.clientWidth) * elSvg.width.baseVal.value / elScale).toFixed(1)
|
||||||
|
yPoint = ((e.offsetY / elSvgCont.clientHeight) * elSvg.height.baseVal.value / elScale).toFixed(1)
|
||||||
|
elCoordBox.textContent = `${xPoint}, ${yPoint}`
|
||||||
|
elCoordBox.style.left = e.offsetX + 6
|
||||||
|
elCoordBox.style.top = e.offsetY + 12
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user