Skip to content

Commit 7016f9b

Browse files
committed
enhance makeButtonBlink
1 parent f881dc3 commit 7016f9b

File tree

1 file changed

+20
-13
lines changed
  • services/static-webserver/client/source/class/osparc/utils

1 file changed

+20
-13
lines changed

services/static-webserver/client/source/class/osparc/utils/Utils.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -321,23 +321,30 @@ qx.Class.define("osparc.utils.Utils", {
321321
},
322322

323323
makeButtonBlink: function(button, nTimes = 1) {
324-
const onTime = 1000;
325-
const oldBgColor = button.getBackgroundColor();
324+
const baseColor = button.getBackgroundColor();
325+
const blinkColor = "strong-main";
326+
const interval = 500;
326327
let count = 0;
327328

328-
const blinkIt = btn => {
329+
// If a blink is already in progress, cancel it
330+
if (button._blinkingIntervalId) {
331+
clearInterval(button._blinkingIntervalId);
332+
button.setBackgroundColor(baseColor); // reset to base
333+
}
334+
335+
const blinkInterval = setInterval(() => {
336+
button.setBackgroundColor((count % 2 === 0) ? blinkColor : baseColor);
329337
count++;
330-
btn.setBackgroundColor("strong-main");
331-
setTimeout(() => {
332-
btn && btn.setBackgroundColor(oldBgColor);
333-
}, onTime);
334-
};
335338

336-
// make it "blink": show it as strong button during onTime" nTimes
337-
blinkIt(button);
338-
const intervalId = setInterval(() => {
339-
(count < nTimes) ? blinkIt(button) : clearInterval(intervalId);
340-
}, 2*onTime);
339+
if (count >= nTimes * 2) {
340+
clearInterval(blinkInterval);
341+
button.setBackgroundColor(baseColor);
342+
button._blinkingIntervalId = null; // cleanup
343+
}
344+
}, interval);
345+
346+
// Store interval ID on the button
347+
button._blinkingIntervalId = blinkInterval;
341348
},
342349

343350
hardRefresh: function() {

0 commit comments

Comments
 (0)