mirror of
https://github.com/umap-project/umap.git
synced 2025-04-29 11:52:38 +02:00
wip: set contextmenu x/y according to position in window
This commit is contained in:
parent
4a6b271bbe
commit
96c9bf9413
1 changed files with 14 additions and 2 deletions
|
@ -26,8 +26,7 @@ export default class ContextMenu {
|
||||||
this.container.appendChild(li)
|
this.container.appendChild(li)
|
||||||
}
|
}
|
||||||
document.body.appendChild(this.container)
|
document.body.appendChild(this.container)
|
||||||
this.container.style.top = `${y}px`
|
this.setPosition([x, y], this.container)
|
||||||
this.container.style.left = `${x}px`
|
|
||||||
this.container.querySelector('button').focus()
|
this.container.querySelector('button').focus()
|
||||||
this.container.addEventListener('keydown', (event) => {
|
this.container.addEventListener('keydown', (event) => {
|
||||||
if (event.key === 'Escape') {
|
if (event.key === 'Escape') {
|
||||||
|
@ -37,6 +36,19 @@ export default class ContextMenu {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setPosition([x, y], element) {
|
||||||
|
if (x < window.innerWidth / 2) {
|
||||||
|
this.container.style.left = `${x}px`
|
||||||
|
} else {
|
||||||
|
this.container.style.left = `${x - element.offsetWidth}px`
|
||||||
|
}
|
||||||
|
if (y < window.innerHeight / 2) {
|
||||||
|
this.container.style.top = `${y}px`
|
||||||
|
} else {
|
||||||
|
this.container.style.top = `${y - element.offsetHeight}px`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
try {
|
try {
|
||||||
this.container.remove()
|
this.container.remove()
|
||||||
|
|
Loading…
Reference in a new issue