TS conversion
This commit is contained in:
parent
75fa9d0844
commit
845c7f6612
44 changed files with 6225 additions and 611 deletions
61
webpage/contextmenu.ts
Normal file
61
webpage/contextmenu.ts
Normal file
|
@ -0,0 +1,61 @@
|
|||
class Contextmenu{
|
||||
static currentmenu;
|
||||
name:string;
|
||||
buttons:[string,Function,string,Function,Function][];
|
||||
div:HTMLDivElement;
|
||||
static setup(){
|
||||
Contextmenu.currentmenu="";
|
||||
document.addEventListener('click', function(event) {
|
||||
if(Contextmenu.currentmenu==""){
|
||||
return;
|
||||
}
|
||||
if (!Contextmenu.currentmenu.contains(event.target)) {
|
||||
Contextmenu.currentmenu.remove();
|
||||
Contextmenu.currentmenu="";
|
||||
}
|
||||
});
|
||||
}
|
||||
constructor(name:string){
|
||||
this.name=name;
|
||||
this.buttons=[]
|
||||
}
|
||||
addbutton(text:string,onclick:Function,img=null,shown=_=>true,enabled=_=>true){
|
||||
this.buttons.push([text,onclick,img,shown,enabled])
|
||||
return {};
|
||||
}
|
||||
makemenu(x:number,y:number,addinfo:any,obj:HTMLElement){
|
||||
const div=document.createElement("table");
|
||||
div.classList.add("contextmenu");
|
||||
for(const thing of this.buttons){
|
||||
if(!thing[3](addinfo)){continue;}
|
||||
const textb=document.createElement("tr");
|
||||
const intext=document.createElement("button")
|
||||
intext.disabled=!thing[4]();
|
||||
textb["button"]=intext;
|
||||
intext.classList.add("contextbutton")
|
||||
intext.textContent=thing[0]
|
||||
textb.appendChild(intext)
|
||||
console.log(thing)
|
||||
intext.onclick=thing[1].bind(addinfo,obj);
|
||||
div.appendChild(textb);
|
||||
}
|
||||
if(Contextmenu.currentmenu!=""){
|
||||
Contextmenu.currentmenu.remove();
|
||||
}
|
||||
div.style.top = y+'px';
|
||||
div.style.left = x+'px';
|
||||
document.body.appendChild(div);
|
||||
console.log(div)
|
||||
Contextmenu.currentmenu=div;
|
||||
return this.div;
|
||||
}
|
||||
bind(obj:HTMLElement,addinfo:any=undefined){
|
||||
obj.addEventListener("contextmenu", (event) => {
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
this.makemenu(event.clientX,event.clientY,addinfo,obj)
|
||||
});
|
||||
}
|
||||
}
|
||||
Contextmenu.setup();
|
||||
export {Contextmenu as Contextmenu}
|
Loading…
Add table
Add a link
Reference in a new issue