Skip to content

Commit

Permalink
Move preventdafult
Browse files Browse the repository at this point in the history
  • Loading branch information
jivansh77 committed Jan 5, 2025
1 parent 04850db commit 7e82d6f
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions js/piemenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -3518,38 +3518,45 @@ const piemenuBlockContext = (block) => {
// Long-press on blocks
let longPressTimer = null;
const LONG_PRESS_DURATION = 500;
let touchStarted = false;

block.container.on("touchstart", (event) => {
event.preventDefault();
// event.preventDefault();
event.stopPropagation();

if (event.touches.length !== 1) return;

touchStarted = true;

longPressTimer = setTimeout(() => {
docById("contextWheelDiv").style.position = "absolute";
docById("contextWheelDiv").style.display = "";

const x = block.container.x;
const y = block.container.y;
const canvasLeft = block.activity.canvas.offsetLeft + 28 * block.blocks.blockScale;
const canvasTop = block.activity.canvas.offsetTop + 6 * block.blocks.blockScale;

docById("contextWheelDiv").style.left = Math.round((x + block.activity.blocksContainer.x) *
block.activity.getStageScale() + canvasLeft) + "px";
docById("contextWheelDiv").style.top = Math.round((y + block.activity.blocksContainer.y) *
block.activity.getStageScale() + canvasTop) + "px";
if (touchStarted) {
event.preventDefault();

docById("contextWheelDiv").style.position = "absolute";
docById("contextWheelDiv").style.display = "";

const x = block.container.x;
const y = block.container.y;
const canvasLeft = block.activity.canvas.offsetLeft + 28 * block.blocks.blockScale;
const canvasTop = block.activity.canvas.offsetTop + 6 * block.blocks.blockScale;

docById("contextWheelDiv").style.left = Math.round((x + block.activity.blocksContainer.x) *
block.activity.getStageScale() + canvasLeft) - 150 + "px";
docById("contextWheelDiv").style.top = Math.round((y + block.activity.blocksContainer.y) *
block.activity.getStageScale() + canvasTop) - 150 + "px";
}
}, LONG_PRESS_DURATION);
});
}, { passive: false });

const clearTimer = () => {
touchStarted = false;
if (longPressTimer) {
clearTimeout(longPressTimer);
longPressTimer = null;
}
};

block.container.on("touchmove", (event) => {
event.preventDefault();
block.container.on("touchmove", () => {
clearTimer();
});
block.container.on("touchend", clearTimer);
Expand Down

0 comments on commit 7e82d6f

Please sign in to comment.