Skip to content

Commit

Permalink
improve Click Button behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecat committed Nov 13, 2023
1 parent eac12e0 commit e119063
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions docs/VirtualIODevices.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@
const clickButton = (function() {
const configId = "clickButton";

const tagsToFilter = {
"input": true, "label": true, "textarea": true, "button": true,
"select": true, "a": true, "summary": true,
};
const idsToFilter = {
"padForm": true,
};
const classesToFilter = [
"screenKey",
];

function isEventToIgnore(event) {
let element = event.target;
for (;;) {
if (typeof element.tagName === "string" && element.tagName.toLowerCase() in tagsToFilter) return true;
if (element.id in idsToFilter) return true;
if (element.classList && classesToFilter.some((name) => element.classList.contains(name))) return true;
if (!element.parentNode) return false;
element = element.parentNode;
}
}

let connectedCheck;
let portToConnectSelect;
let signalPressedSelect;
Expand Down Expand Up @@ -37,13 +59,16 @@ const clickButton = (function() {
portToConnectSelect.addEventListener("change", updateOutputPortList);
updateOutputPortList();

document.body.addEventListener("mousedown", function() {
document.body.addEventListener("mousedown", function(event) {
if (isEventToIgnore(event)) return;
isClicked = true;
});
document.body.addEventListener("mouseup", function() {
document.body.addEventListener("mouseup", function(event) {
if (isEventToIgnore(event)) return;
isClicked = false;
});
const touchHandler = function(event) {
if (isEventToIgnore(event)) return;
event.preventDefault();
isTouched = event.targetTouches.length > 0;
};
Expand Down

0 comments on commit e119063

Please sign in to comment.