Add mouse coordinate view with click to copy
Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
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