MCPcopy Create free account
hub / github.com/NikLever/ThreeJS-PathEditor / Menu

Class Menu

menu.js:1–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1export class Menu{
2 constructor( app, links ){
3 this.menu = document.querySelector(".context-menu");
4 this.menuState = 0;
5 this.contextMenuActive = "block";
6 this.app = app;
7
8 this.addLinks( links );
9
10 document.addEventListener("contextmenu", (e) => {
11 e.preventDefault();
12 this.show(e);
13 });
14
15 // Event Listener for Close Context Menu when outside of menu clicked
16 document.addEventListener("click", (e) => {
17 this.hide();
18 });
19
20 // Close Context Menu on Esc key press
21 window.onkeyup = (e) => {
22 if (e.keyCode === 27) this.hide();
23 }
24 }
25
26 addLinks( links = [] ){
27 let html = "";
28
29 /*<div class="flex hover:bg-gray-100 py-1 px-2 rounded cursor-pointer">
30 <button class="ml-4" onclick="alert('Delete');">Delete</button>
31 </div>*/
32
33 const prefix = '<div class="flex hover:bg-gray-100 py-1 px-2 rounded cursor-pointer"><button class="ml-4" onclick="';
34
35 links.forEach( link => {
36 html = `${html + prefix}window.app.${link.code};">${link.name}</button></div>`;
37 });
38
39 const elm = document.getElementById("menu-links");
40 elm.innerHTML = html;
41 }
42
43 show(e) {
44 if (this.menuState !== 1) {
45 this.positionMenu(e);
46 this.menuState = 1;
47 this.menu.style.display = "block";
48 }
49 }
50
51 hide(){
52 if (this.menuState !== 0) {
53 this.menuState = 0;
54 this.menu.style.display = "none";
55 }
56 }
57
58 getPosition(e) {
59 let posx = 0;
60 let posy = 0;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected