Skip to content

Commit 7bb293e

Browse files
authored
Merge pull request #691 from mosvov/switch-all-checkbox-default-value
Set Switch all checkbox defaults based on the majority of the switches
2 parents 0b3315d + 09912c9 commit 7bb293e

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

tabs/osd.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h1 class="tab_title">
2222
<span i18n="osdSetupElementsTitle" />
2323
<span class="switch-all-elements">
2424
<label for="switch-all"><span i18n="osdSetupElementsSwitchAll" />: </label>
25-
<input type="checkbox" checked id="switch-all" name="switch-all" class="togglesmall"></input>
25+
<input type="checkbox" id="switch-all" name="switch-all" class="togglesmall"></input>
2626
</span>
2727
</div>
2828
</div>

tabs/osd.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,11 +1307,12 @@ TABS.osd.initialize = function (callback) {
13071307

13081308
// display fields on/off and position
13091309
var $displayFields = $('#element-fields').empty();
1310+
var enabledCount = 0;
13101311
for (let field of OSD.data.display_items) {
13111312
// versioning related, if the field doesn't exist at the current flight controller version, just skip it
13121313
if (!field.name) { continue; }
1314+
if (field.isVisible) { enabledCount++; }
13131315

1314-
var checked = field.isVisible ? 'checked' : '';
13151316
var $field = $('<div class="switchable-field field-'+field.index+'"/>');
13161317
var desc = null;
13171318
if (field.desc && field.desc.length) {
@@ -1359,6 +1360,10 @@ TABS.osd.initialize = function (callback) {
13591360
}
13601361
$displayFields.append($field);
13611362
}
1363+
//Set Switch all checkbox defaults based on the majority of the switches
1364+
var checked = enabledCount >= (OSD.data.display_items.length / 2);
1365+
$('input#switch-all').prop('checked', checked).change();
1366+
13621367
GUI.switchery();
13631368
// buffer the preview
13641369
OSD.data.preview = [];
@@ -1533,7 +1538,10 @@ TABS.osd.initialize = function (callback) {
15331538
});
15341539

15351540
//Switch all elements
1536-
$('input#switch-all').change(function () {
1541+
$('input#switch-all').change(function (event) {
1542+
//if we just change value based on the majority of the switches
1543+
if (event.isTrigger) return;
1544+
15371545
var new_state = $(this).is(':checked');
15381546

15391547
var updateList = [];

0 commit comments

Comments
 (0)