mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-22 15:55:33 +03:00
Update sort function (#3167)
This commit is contained in:
parent
454627c05f
commit
1f7e77938c
3 changed files with 27 additions and 31 deletions
|
@ -333,7 +333,7 @@ motors.initialize = async function (callback) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
sortElement('select.mixerList');
|
mixerListElement.sortSelect();
|
||||||
|
|
||||||
function refreshMixerPreview() {
|
function refreshMixerPreview() {
|
||||||
const mixer = FC.MIXER_CONFIG.mixer;
|
const mixer = FC.MIXER_CONFIG.mixer;
|
||||||
|
@ -648,7 +648,7 @@ motors.initialize = async function (callback) {
|
||||||
escProtocolElement.append(`<option value="${j + 1}">${escProtocols[j]}</option>`);
|
escProtocolElement.append(`<option value="${j + 1}">${escProtocols[j]}</option>`);
|
||||||
}
|
}
|
||||||
|
|
||||||
sortElement('select.escprotocol');
|
escProtocolElement.sortSelect("DISABLED");
|
||||||
|
|
||||||
const unsyncedPWMSwitchElement = $("input[id='unsyncedPWMSwitch']");
|
const unsyncedPWMSwitchElement = $("input[id='unsyncedPWMSwitch']");
|
||||||
const divUnsyncedPWMFreq = $('div.unsyncedpwmfreq');
|
const divUnsyncedPWMFreq = $('div.unsyncedpwmfreq');
|
||||||
|
|
|
@ -252,13 +252,7 @@ receiver.initialize = function (callback) {
|
||||||
|
|
||||||
// Convert to select2 and order alphabetic
|
// Convert to select2 and order alphabetic
|
||||||
if (!GUI.isCordova()) {
|
if (!GUI.isCordova()) {
|
||||||
serialRxSelectElement.select2({
|
serialRxSelectElement.sortSelect().select2();
|
||||||
sorter(data) {
|
|
||||||
return data.sort(function(a, b) {
|
|
||||||
return a.text.localeCompare(b.text);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const spiRxTypes = [
|
const spiRxTypes = [
|
||||||
|
@ -314,13 +308,7 @@ receiver.initialize = function (callback) {
|
||||||
|
|
||||||
if (!GUI.isCordova()) {
|
if (!GUI.isCordova()) {
|
||||||
// Convert to select2 and order alphabetic
|
// Convert to select2 and order alphabetic
|
||||||
spiRxElement.select2({
|
spiRxElement.sortSelect().select2();
|
||||||
sorter(data) {
|
|
||||||
return data.sort(function(a, b) {
|
|
||||||
return a.text.localeCompare(b.text);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FC.FEATURE_CONFIG.features.isEnabled('RX_SPI') && FC.RX_CONFIG.rxSpiProtocol == 19 && semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
|
if (FC.FEATURE_CONFIG.features.isEnabled('RX_SPI') && FC.RX_CONFIG.rxSpiProtocol == 19 && semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
|
||||||
|
|
|
@ -87,20 +87,29 @@ export function getTextWidth(text) {
|
||||||
return Math.ceil(context.measureText(text).width);
|
return Math.ceil(context.measureText(text).width);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sortElement(element, keepDown = "DISABLED") {
|
/**
|
||||||
const list = document.querySelector(element);
|
* Returns jquery sorted option list with optional value staying on top of the list.
|
||||||
[...list.children]
|
*
|
||||||
.sort((a, b) => {
|
* @param {string} optional value staying on top of the list.
|
||||||
if (a.innerText === keepDown) {
|
* @return {object} sorted option list.
|
||||||
return 1;
|
*/
|
||||||
} else if (b.innerText === keepDown) {
|
|
||||||
|
$.fn.sortSelect = function(text = "") {
|
||||||
|
const op = this.children("option");
|
||||||
|
|
||||||
|
op.sort((a, b) => {
|
||||||
|
console.log(a.value, a.text);
|
||||||
|
if (a.text === text) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
|
||||||
return a.innerText > b.innerText ? 1 : -1;
|
|
||||||
}
|
}
|
||||||
})
|
if (b.text === text) {
|
||||||
.forEach(node => list.appendChild(node));
|
return 1;
|
||||||
}
|
}
|
||||||
|
return a.text.localeCompare(b.text, window.navigator.language, { ignorePunctuation: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.empty().append(op);
|
||||||
|
};
|
||||||
|
|
||||||
// TODO: these are temp binding while transition to module happens
|
// TODO: these are temp binding while transition to module happens
|
||||||
window.degToRad = degToRad;
|
window.degToRad = degToRad;
|
||||||
|
@ -110,4 +119,3 @@ window.checkChromeRuntimeError = checkChromeRuntimeError;
|
||||||
window.generateVirtualApiVersions = generateVirtualApiVersions;
|
window.generateVirtualApiVersions = generateVirtualApiVersions;
|
||||||
window.getMixerImageSrc = getMixerImageSrc;
|
window.getMixerImageSrc = getMixerImageSrc;
|
||||||
window.getTextWidth = getTextWidth;
|
window.getTextWidth = getTextWidth;
|
||||||
window.sortElement = sortElement;
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue