Various fixes

This commit is contained in:
MathMan05
2024-11-06 11:58:01 -06:00
parent 0d4ca2d68a
commit 49cdb8fda6
7 changed files with 67 additions and 9 deletions

View File

@@ -84,7 +84,7 @@ class Contextmenu<x, y>{
Contextmenu.currentmenu = div;
return this.div;
}
bindContextmenu(obj: HTMLElement, addinfo: x, other: y){
bindContextmenu(obj: HTMLElement, addinfo: x, other: y,touchDrag:(x:number,y:number)=>unknown=()=>{},touchEnd:(x:number,y:number)=>unknown=()=>{}){
const func = (event: MouseEvent)=>{
event.preventDefault();
event.stopImmediatePropagation();
@@ -92,13 +92,39 @@ class Contextmenu<x, y>{
};
obj.addEventListener("contextmenu", func);
if(iOS){
let hold:NodeJS.Timeout|undefined;
let x!:number;
let y!:number;
obj.addEventListener("touchstart",(event: TouchEvent)=>{
x=event.touches[0].pageX;
y=event.touches[0].pageY;
if(event.touches.length > 1){
event.preventDefault();
event.stopImmediatePropagation();
this.makemenu(event.touches[0].clientX, event.touches[0].clientY, addinfo, other);
}else{
//
event.stopImmediatePropagation();
hold=setTimeout(()=>{
if(lastx**2+lasty**2>10**2) return;
this.makemenu(event.touches[0].clientX, event.touches[0].clientY, addinfo, other);
console.log(obj);
},500)
}
},{passive: false});
let lastx=0;
let lasty=0;
obj.addEventListener("touchend",()=>{
if(hold){
clearTimeout(hold);
}
touchEnd(lastx,lasty);
});
obj.addEventListener("touchmove",(event)=>{
lastx=event.touches[0].pageX-x;
lasty=event.touches[0].pageY-y;
touchDrag(lastx,lasty);
});
}
return func;
}