Skip to content

Commit 498f8ef

Browse files
committed
Moved touch event handling to block.js
1 parent 04850db commit 498f8ef

File tree

2 files changed

+31
-41
lines changed

2 files changed

+31
-41
lines changed

js/block.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const STRINGLEN = 9;
9191
* Length of a long touch in milliseconds.
9292
* @type {number}
9393
*/
94-
const LONGPRESSTIME = 1500;
94+
const LONGPRESSTIME = 500;
9595
const INLINECOLLAPSIBLES = ["newnote", "interval", "osctime", "definemode"];
9696

9797
/**
@@ -3077,6 +3077,36 @@ class Block {
30773077

30783078
moved = false;
30793079
});
3080+
3081+
this.container.on("touchstart", (event) => {
3082+
event.preventDefault();
3083+
event.stopPropagation();
3084+
that.blocks.mouseDownTime = new Date().getTime();
3085+
that.blocks.longPressTimeout = setTimeout(() => {
3086+
that.blocks.activeBlock = that.blocks.blockList.indexOf(that);
3087+
piemenuBlockContext(that);
3088+
}, LONGPRESSTIME);
3089+
}, { passive: false });
3090+
3091+
this.container.on("touchstart", (event) => {
3092+
if (event.touches.length > 1) {
3093+
if (that.blocks.longPressTimeout) {
3094+
clearTimeout(that.blocks.longPressTimeout);
3095+
}
3096+
}
3097+
});
3098+
3099+
this.container.on("touchmove", () => {
3100+
if (that.blocks.longPressTimeout) {
3101+
clearTimeout(that.blocks.longPressTimeout);
3102+
}
3103+
});
3104+
3105+
this.container.on("touchend touchcancel", () => {
3106+
if (that.blocks.longPressTimeout) {
3107+
clearTimeout(that.blocks.longPressTimeout);
3108+
}
3109+
});
30803110
}
30813111

30823112
/**

js/piemenus.js

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3514,46 +3514,6 @@ const piemenuBlockContext = (block) => {
35143514
setTimeout(() => {
35153515
that.blocks.stageClick = false;
35163516
}, 500);
3517-
3518-
// Long-press on blocks
3519-
let longPressTimer = null;
3520-
const LONG_PRESS_DURATION = 500;
3521-
3522-
block.container.on("touchstart", (event) => {
3523-
event.preventDefault();
3524-
event.stopPropagation();
3525-
3526-
if (event.touches.length !== 1) return;
3527-
3528-
longPressTimer = setTimeout(() => {
3529-
docById("contextWheelDiv").style.position = "absolute";
3530-
docById("contextWheelDiv").style.display = "";
3531-
3532-
const x = block.container.x;
3533-
const y = block.container.y;
3534-
const canvasLeft = block.activity.canvas.offsetLeft + 28 * block.blocks.blockScale;
3535-
const canvasTop = block.activity.canvas.offsetTop + 6 * block.blocks.blockScale;
3536-
3537-
docById("contextWheelDiv").style.left = Math.round((x + block.activity.blocksContainer.x) *
3538-
block.activity.getStageScale() + canvasLeft) + "px";
3539-
docById("contextWheelDiv").style.top = Math.round((y + block.activity.blocksContainer.y) *
3540-
block.activity.getStageScale() + canvasTop) + "px";
3541-
}, LONG_PRESS_DURATION);
3542-
});
3543-
3544-
const clearTimer = () => {
3545-
if (longPressTimer) {
3546-
clearTimeout(longPressTimer);
3547-
longPressTimer = null;
3548-
}
3549-
};
3550-
3551-
block.container.on("touchmove", (event) => {
3552-
event.preventDefault();
3553-
clearTimer();
3554-
});
3555-
block.container.on("touchend", clearTimer);
3556-
block.container.on("touchcancel", clearTimer);
35573517
};
35583518

35593519
/**

0 commit comments

Comments
 (0)