Add initial context menu service - WIP
This commit is contained in:
parent
2e6c63a5c3
commit
c0322d9ed9
@ -35,6 +35,11 @@ export class ContextMenu {
|
||||
let edgeBuffer = 10;
|
||||
let target = this.el.nativeElement.firstElementChild;
|
||||
|
||||
// Set to the event position by default
|
||||
target.style.left = event.pageX + 'px';
|
||||
target.style.top = event.pageY + 'px';
|
||||
|
||||
// Adjust position if near an edge
|
||||
setTimeout(() => {
|
||||
let rect = target.getBoundingClientRect();
|
||||
|
||||
@ -43,7 +48,7 @@ export class ContextMenu {
|
||||
|
||||
target.style.left = event.pageX - (offsetX ? rect.width : 0) + 'px';
|
||||
target.style.top = event.pageY - (offsetY ? rect.height : 0) + 'px';
|
||||
}, 10);
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
27
src/app/shared/context-menu/context-menu.service.ts
Normal file
27
src/app/shared/context-menu/context-menu.service.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { ContextMenu } from './context-menu.component';
|
||||
|
||||
@Injectable()
|
||||
export class ContextMenuService {
|
||||
private menus: Array<ContextMenu>;
|
||||
|
||||
constructor() {
|
||||
this.menus = [];
|
||||
|
||||
document.addEventListener('click', () => {
|
||||
this.closeAllMenus();
|
||||
});
|
||||
}
|
||||
|
||||
registerMenu(newMenu: ContextMenu) {
|
||||
this.menus.push(newMenu);
|
||||
}
|
||||
|
||||
private closeAllMenus() {
|
||||
this.menus.forEach(menu => {
|
||||
menu.isOpen = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user