Simplified code by removing boxKeys array
parent
48e02ba13f
commit
5f6fd9247d
|
|
@ -28,19 +28,20 @@
|
||||||
let boxTouched = false;
|
let boxTouched = false;
|
||||||
let touchedBox = null;
|
let touchedBox = null;
|
||||||
|
|
||||||
boxKeys.forEach((boxKey) => {
|
for (let boxKey in boxes) {
|
||||||
if (touchInText(e, boxes[boxKey], boxKey)) {
|
if (touchInText(e, boxes[boxKey])) {
|
||||||
touchedBox = boxKey;
|
touchedBox = boxKey;
|
||||||
boxTouched = true;
|
boxTouched = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
if (boxTouched) {
|
if (boxTouched) {
|
||||||
// Toggle the selected state of the touched box
|
// Toggle the selected state of the touched box
|
||||||
boxes[touchedBox].selected = !boxes[touchedBox].selected;
|
boxes[touchedBox].selected = !boxes[touchedBox].selected;
|
||||||
|
|
||||||
// Update isDragging based on whether any box is selected
|
// Update isDragging based on whether any box is selected
|
||||||
isDragging = boxKeys.some(key => boxes[key].selected);
|
isDragging = Object.values(boxes).some(box => box.selected);
|
||||||
|
|
||||||
if (isDragging) {
|
if (isDragging) {
|
||||||
widgets.hide();
|
widgets.hide();
|
||||||
|
|
@ -60,10 +61,10 @@
|
||||||
if (doubleTapTimer) {
|
if (doubleTapTimer) {
|
||||||
clearTimeout(doubleTapTimer);
|
clearTimeout(doubleTapTimer);
|
||||||
doubleTapTimer = null;
|
doubleTapTimer = null;
|
||||||
Object.keys(boxes).forEach((boxKey) => {
|
for (let boxKey in boxes) {
|
||||||
boxesConfig[boxKey].boxPos.x = (boxes[boxKey].pos.x / w).toFixed(3);
|
boxesConfig[boxKey].boxPos.x = (boxes[boxKey].pos.x / w).toFixed(3);
|
||||||
boxesConfig[boxKey].boxPos.y = (boxes[boxKey].pos.y / h).toFixed(3);
|
boxesConfig[boxKey].boxPos.y = (boxes[boxKey].pos.y / h).toFixed(3);
|
||||||
});
|
}
|
||||||
storage.write(fileName, JSON.stringify(boxesConfig));
|
storage.write(fileName, JSON.stringify(boxesConfig));
|
||||||
displaySaveIcon();
|
displaySaveIcon();
|
||||||
return;
|
return;
|
||||||
|
|
@ -82,7 +83,7 @@
|
||||||
// Stop propagation of the drag event to prevent other handlers
|
// Stop propagation of the drag event to prevent other handlers
|
||||||
E.stopEventPropagation();
|
E.stopEventPropagation();
|
||||||
|
|
||||||
boxKeys.forEach(key => {
|
for (let key in boxes) {
|
||||||
if (boxes[key].selected) {
|
if (boxes[key].selected) {
|
||||||
let boxItem = boxes[key];
|
let boxItem = boxes[key];
|
||||||
calcBoxSize(boxItem);
|
calcBoxSize(boxItem);
|
||||||
|
|
@ -97,7 +98,7 @@
|
||||||
boxItem.pos.y = newY;
|
boxItem.pos.y = newY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
draw();
|
draw();
|
||||||
};
|
};
|
||||||
|
|
@ -311,7 +312,7 @@
|
||||||
updateBoxData();
|
updateBoxData();
|
||||||
}
|
}
|
||||||
|
|
||||||
boxKeys.forEach((boxKey) => {
|
for (let boxKey in boxes) {
|
||||||
let boxItem = boxes[boxKey];
|
let boxItem = boxes[boxKey];
|
||||||
|
|
||||||
// Set font and alignment for each box individually
|
// Set font and alignment for each box individually
|
||||||
|
|
@ -333,7 +334,7 @@
|
||||||
boxItem.pos.x + boxItem.xOffset,
|
boxItem.pos.x + boxItem.xOffset,
|
||||||
boxItem.pos.y + boxItem.yOffset
|
boxItem.pos.y + boxItem.yOffset
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
|
|
||||||
if (!isDragging) {
|
if (!isDragging) {
|
||||||
if (drawTimeout) clearTimeout(drawTimeout);
|
if (drawTimeout) clearTimeout(drawTimeout);
|
||||||
|
|
@ -375,7 +376,7 @@
|
||||||
return boxItem.cachedSize;
|
return boxItem.cachedSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
let touchInText = function(e, boxItem, boxKey) {
|
let touchInText = function(e, boxItem) {
|
||||||
calcBoxSize(boxItem);
|
calcBoxSize(boxItem);
|
||||||
const pos = calcBoxPos(boxItem);
|
const pos = calcBoxPos(boxItem);
|
||||||
return e.x >= pos.x1 &&
|
return e.x >= pos.x1 &&
|
||||||
|
|
@ -386,9 +387,9 @@
|
||||||
|
|
||||||
let deselectAllBoxes = function() {
|
let deselectAllBoxes = function() {
|
||||||
isDragging = false;
|
isDragging = false;
|
||||||
boxKeys.forEach((boxKey) => {
|
for (let boxKey in boxes) {
|
||||||
boxes[boxKey].selected = false;
|
boxes[boxKey].selected = false;
|
||||||
});
|
}
|
||||||
restoreSetColor();
|
restoreSetColor();
|
||||||
widgets.show();
|
widgets.show();
|
||||||
widgets.swipeOn();
|
widgets.swipeOn();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue