add touch suport for menu (#5)

This commit is contained in:
2024-05-13 23:22:22 +02:00
parent 08cce54604
commit c91a015e79

31
main.js
View File

@@ -651,9 +651,32 @@ class CalendarView extends ItemView
eventEl.addEventListener('mousedown', (e) => {
if (e.button == 2)
{
this.openMenu(e, event);
this.openMenu(event, {x: e.clientX, y: e.clientY});
}
})
});
eventEl.addEventListener('touchstart', (e) => {
if (e.touches.length == 1)
{
this.touchEvent = { "event": event, "location": {x: e.touches[0].clientX, y: e.touches[0].clientY}, "time": new Date().getTime() };
setTimeout(() => {
if (this.touchEvent != null && ((new Date().getTime() - this.touchEvent.time) > 900))
{
this.openMenu(this.touchEvent.event, this.touchEvent.location);
this.touchEvent = null;
}
}, 1000);
}
else
{
this.touchEvent = null;
}
});
eventEl.addEventListener('touchend', (e) => {
this.touchEvent = null;
});
eventEl.addEventListener('touchmove', (e) => {
this.touchEvent = null;
});
switch (event.type)
{
case 'task':
@@ -685,7 +708,7 @@ class CalendarView extends ItemView
return el;
}
openMenu(e, event)
openMenu(event, location)
{
let text = "";
Object.keys(event).forEach(key => {
@@ -698,7 +721,7 @@ class CalendarView extends ItemView
item.setTitle(text);
});
menu.showAtPosition({x: e.x, y: e.y});
menu.showAtPosition(location);
}
}