OrganonTweaks: swallow post-drag click so a held press (>100ms) never opens the card; v1.2
This commit is contained in:
35
Asset/js/click-guard.js
Normal file
35
Asset/js/click-guard.js
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* OrganonTweaks -- only open a card on a quick click.
|
||||
*
|
||||
* A real click is a quick press-release; a drag is a press, some movement, and a release
|
||||
* much later. When you drop a card, jQuery UI can leak a trailing "click" on it, and
|
||||
* Kanboard opens the card -- an unwanted side effect of the drag.
|
||||
*
|
||||
* We simply time the press on a card: record the moment of mousedown / touchstart, and on
|
||||
* the click that follows, if more than THRESHOLD ms elapsed the press was a drag (held),
|
||||
* not a click, so we swallow the click in the capture phase before Kanboard's open handler
|
||||
* runs. A normal click is well under the threshold and opens the card as usual.
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
var THRESHOLD = 100; // ms; a press on a card held longer than this is a drag, not a click
|
||||
var pressStart = 0;
|
||||
|
||||
function onDown(e) {
|
||||
pressStart = (e.target && e.target.closest && e.target.closest(".task-board")) ? Date.now() : 0;
|
||||
}
|
||||
|
||||
document.addEventListener("mousedown", onDown, true);
|
||||
document.addEventListener("touchstart", onDown, true);
|
||||
|
||||
document.addEventListener("click", function (e) {
|
||||
if (pressStart &&
|
||||
e.target && e.target.closest && e.target.closest(".task-board") &&
|
||||
(Date.now() - pressStart) > THRESHOLD) {
|
||||
e.stopImmediatePropagation();
|
||||
e.preventDefault();
|
||||
}
|
||||
pressStart = 0;
|
||||
}, true);
|
||||
})();
|
||||
Reference in New Issue
Block a user