Skip to content

Commit

Permalink
Merge pull request #691 from mosvov/switch-all-checkbox-default-value
Browse files Browse the repository at this point in the history
Set Switch all checkbox defaults based on the majority of the switches
  • Loading branch information
mikeller authored Oct 16, 2017
2 parents 0b3315d + 09912c9 commit 7bb293e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tabs/osd.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h1 class="tab_title">
<span i18n="osdSetupElementsTitle" />
<span class="switch-all-elements">
<label for="switch-all"><span i18n="osdSetupElementsSwitchAll" />: </label>
<input type="checkbox" checked id="switch-all" name="switch-all" class="togglesmall"></input>
<input type="checkbox" id="switch-all" name="switch-all" class="togglesmall"></input>
</span>
</div>
</div>
Expand Down
12 changes: 10 additions & 2 deletions tabs/osd.js
Original file line number Diff line number Diff line change
Expand Up @@ -1307,11 +1307,12 @@ TABS.osd.initialize = function (callback) {

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

var checked = field.isVisible ? 'checked' : '';
var $field = $('<div class="switchable-field field-'+field.index+'"/>');
var desc = null;
if (field.desc && field.desc.length) {
Expand Down Expand Up @@ -1359,6 +1360,10 @@ TABS.osd.initialize = function (callback) {
}
$displayFields.append($field);
}
//Set Switch all checkbox defaults based on the majority of the switches
var checked = enabledCount >= (OSD.data.display_items.length / 2);
$('input#switch-all').prop('checked', checked).change();

GUI.switchery();
// buffer the preview
OSD.data.preview = [];
Expand Down Expand Up @@ -1533,7 +1538,10 @@ TABS.osd.initialize = function (callback) {
});

//Switch all elements
$('input#switch-all').change(function () {
$('input#switch-all').change(function (event) {
//if we just change value based on the majority of the switches
if (event.isTrigger) return;

var new_state = $(this).is(':checked');

var updateList = [];
Expand Down

0 comments on commit 7bb293e

Please sign in to comment.