Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/iNavFlight/inav-configurator.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Lines <darren@darrenlines.uk>2022-10-17 21:45:19 +0300
committerDarren Lines <darren@darrenlines.uk>2022-10-17 21:45:19 +0300
commit30317ede7997e7ca76d75b71835f934b916d97b3 (patch)
treebb60de00b8645cec36297b6108042845b57102e0
parent43b69d434a23c384371468aa325d0cf0e0c8d189 (diff)
Couple of improvements
- better handling of negative numbers - improved regex pattern - limits to min and max values
-rw-r--r--js/settings.js17
-rw-r--r--main.js14
2 files changed, 24 insertions, 7 deletions
diff --git a/js/settings.js b/js/settings.js
index ae797f76..768d29bf 100644
--- a/js/settings.js
+++ b/js/settings.js
@@ -522,7 +522,7 @@ var Settings = (function () {
}
element.attr('step', step.toFixed(decimalPlaces));
- if ((multiplier !== 'FAHREN' || multiplier !== 'TZHOURS') && multiplier !== 1) {
+ if (multiplier !== 'FAHREN' && multiplier !== 'TZHOURS' && multiplier !== 1) {
element.attr('min', (parseFloat(element.attr('min')) / multiplier).toFixed(decimalPlaces));
element.attr('max', (parseFloat(element.attr('max')) / multiplier).toFixed(decimalPlaces));
}
@@ -535,13 +535,12 @@ var Settings = (function () {
element.attr('max', toFahrenheit(element.attr('max')).toFixed(decimalPlaces));
newValue = toFahrenheit(oldValue).toFixed(decimalPlaces);
} else if (multiplier === 'TZHOURS') {
- element.removeAttr('min');
- element.removeAttr('max');
element.attr('type', 'text');
- element.attr('pattern', '[0-9]{2}:[0-9]{2}');
+ element.removeAttr('step');
+ element.attr('pattern', '([0-9]{2}|[-,0-9]{3}):([0-9]{2})');
let hours = Math.floor(oldValue/60);
let mins = oldValue - (hours*60);
- newValue = padZeros(hours, 2) + ':' + padZeros(mins, 2);
+ newValue = ((hours < 0) ? padZeros(hours, 3) : padZeros(hours, 2)) + ':' + padZeros(mins, 2);
} else {
newValue = Number((oldValue / multiplier)).toFixed(decimalPlaces);
}
@@ -581,6 +580,14 @@ var Settings = (function () {
} else if (multiplier === 'TZHOURS') {
let inputTZ = input.val().split(':');
value = (parseInt(inputTZ[0]) * 60) + parseInt(inputTZ[1]);
+
+ if (value > parseInt(input.attr('max'))) {
+ value = parseInt(input.attr('max'));
+ }
+
+ if (value < parseInt(input.attr('min'))) {
+ value = parseInt(input.attr('min'));
+ }
} else {
multiplier = parseFloat(multiplier);
diff --git a/main.js b/main.js
index d27b0a07..64f8c7de 100644
--- a/main.js
+++ b/main.js
@@ -651,8 +651,18 @@ String.prototype.format = function () {
function padZeros(val, length) {
let str = val.toString();
- return str.length < length ? padZeros("0" + str, length) : str;
-};
+
+ if (str.length < length) {
+ if (str.charAt(0) === '-') {
+ str = "-0" + str.substring(1);
+ str = padZeros(str, length);
+ } else {
+ str = padZeros("0" + str, length);
+ }
+ }
+
+ return str;
+}
function updateActivatedTab() {
var activeTab = $('#tabs > ul li.active');