Get position from passed event|object
This commit is contained in:
parent
8637f176c1
commit
ef5a1c223c
|
@ -33,18 +33,14 @@
|
||||||
methods: {
|
methods: {
|
||||||
calculatePosition() {
|
calculatePosition() {
|
||||||
if (!this.activeMenu.menu.groups.length) return {};
|
if (!this.activeMenu.menu.groups.length) return {};
|
||||||
|
this.mouseX = this.activeMenu.menu.x;
|
||||||
|
this.mouseY = this.activeMenu.menu.y;
|
||||||
const height = this.activeMenu.menu.groups.reduce((total, group) => total + group.items.length, 0) * 28;
|
const height = this.activeMenu.menu.groups.reduce((total, group) => total + group.items.length, 0) * 28;
|
||||||
this.top = window.innerHeight - this.mouseY - height < 0 ? this.mouseY - height : this.mouseY;
|
this.top = window.innerHeight - this.mouseY - height < 0 ? this.mouseY - height : this.mouseY;
|
||||||
this.left = window.innerWidth - this.mouseX - 170 < 0 ? this.mouseX - 170 : this.mouseX;
|
this.left = window.innerWidth - this.mouseX - 170 < 0 ? this.mouseX - 170 : this.mouseX;
|
||||||
this.renderLeft = (this.left + 170 * 2) > window.innerWidth;
|
this.renderLeft = (this.left + 170 * 2) > window.innerWidth;
|
||||||
return { top: `${this.top}px`, left: `${this.left}px` };
|
return { top: `${this.top}px`, left: `${this.left}px` };
|
||||||
}
|
}
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
window.addEventListener('contextmenu', e => {
|
|
||||||
this.mouseX = e.clientX;
|
|
||||||
this.mouseY = e.clientY;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -12,10 +12,13 @@ export class BdContextMenu {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a context menu
|
* Show a context menu
|
||||||
|
* @param {MouseEvent|Object} e MouseEvent or Object { x: 0, y: 0 }
|
||||||
* @param {Object[]} grops Groups of items to show in context menu
|
* @param {Object[]} grops Groups of items to show in context menu
|
||||||
*/
|
*/
|
||||||
static show(groups) {
|
static show(e, groups) {
|
||||||
this.activeMenu.menu = { groups };
|
const x = e.x || e.clientX;
|
||||||
|
const y = e.y || e.clientY;
|
||||||
|
this.activeMenu.menu = { x, y, groups };
|
||||||
}
|
}
|
||||||
|
|
||||||
static get activeMenu() {
|
static get activeMenu() {
|
||||||
|
|
Loading…
Reference in New Issue