Skip to content

Commit

Permalink
Update led_strip.js
Browse files Browse the repository at this point in the history
  • Loading branch information
druckgott committed Nov 18, 2024
1 parent e079d21 commit 2fdfc87
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions src/js/tabs/led_strip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down

0 comments on commit 2fdfc87

Please sign in to comment.