From 2fdfc870f6c9373fefdae1ab8ec3e72494708929 Mon Sep 17 00:00:00 2001 From: druckgott Date: Mon, 18 Nov 2024 18:00:11 +0100 Subject: [PATCH] Update led_strip.js --- src/js/tabs/led_strip.js | 51 ++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/src/js/tabs/led_strip.js b/src/js/tabs/led_strip.js index e4e144ea256..a31852fc209 100644 --- a/src/js/tabs/led_strip.js +++ b/src/js/tabs/led_strip.js @@ -490,35 +490,46 @@ led_strip.initialize = function (callback, scrollPosition) { return $(that).is(':checked'); } + // Disable all other functions except the one being activated + function disableOtherFunctions(activeFunction) { + const functions = ['.function-o', '.function-b', '.function-x']; + + functions.forEach(func => { + if (!activeFunction.is(func)) { + const checkbox = $(`.checkbox ${func}`); + if (checkbox.is(':checked')) { + checkbox.prop('checked', false); + checkbox.trigger('change'); + toggleSwitch(checkbox, func.slice(-1)); // Pass the last character as the identifier + } + } + }); + } + // UI: check-box toggle $('.checkbox').on('change', function(e) { if (e.originalEvent) { // user-triggered event const that = $(this).find('input'); - //disable Blink always or Larson scanner, both functions are not working properly at the same time - if (that.is('.function-o')) { - const blink = $('.checkbox .function-b'); - if (blink.is(':checked')) { - blink.prop('checked', false); - blink.trigger('change'); - toggleSwitch(blink, 'b'); + // Event handlers for each function + $('.checkbox .function-o').on('change', function () { + if ($(this).is(':checked')) { + disableOtherFunctions($(this)); } - } else if (that.is('.function-b')) { - const aurora = $('.checkbox .function-x'); - if ($('.checkbox .function-x').is(':checked')) { - aurora.prop('checked', false); - aurora.trigger('change'); - toggleSwitch(aurora, 'x'); + }); + + $('.checkbox .function-b').on('change', function () { + if ($(this).is(':checked')) { + disableOtherFunctions($(this)); } - } else if (that.is('.function-b')) { - const larson = $('.checkbox .function-o'); - if ($('.checkbox .function-o').is(':checked')) { - larson.prop('checked', false); - larson.trigger('change'); - toggleSwitch(larson, 'o'); + }); + + $('.checkbox .function-x').on('change', function () { + if ($(this).is(':checked')) { + disableOtherFunctions($(this)); } - } + }); //Change Rainbow slider visibility if (that.is('.function-y')) {