mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 16:25:31 +03:00
initial custom spinner implementation, needs work
This commit is contained in:
parent
fa6ae21076
commit
d0bf009abb
4 changed files with 69 additions and 14 deletions
49
main.js
49
main.js
|
@ -162,4 +162,53 @@ function array_difference(firstArray, secondArray) {
|
|||
}
|
||||
|
||||
return cloneArray;
|
||||
}
|
||||
|
||||
function add_custom_spinners() {
|
||||
var spinner_element = '<div class="spinner"><div class="up"></div><div class="down"></div></div>';
|
||||
|
||||
$('input[type="number"]').each(function() {
|
||||
var input = $(this);
|
||||
var isInt =(input.prop('step') == '') ? true : false;
|
||||
|
||||
// make space for spinner
|
||||
input.width(input.width() - 16);
|
||||
|
||||
// add spinner
|
||||
input.after(spinner_element);
|
||||
|
||||
// get spinner refference
|
||||
var spinner = input.next();
|
||||
|
||||
// bind UI hooks to spinner
|
||||
$('.up', spinner).click(function() {
|
||||
if (isInt) {
|
||||
var current_value = parseInt(input.val());
|
||||
input.val(current_value + 1);
|
||||
} else {
|
||||
var current_value = parseFloat(input.val());
|
||||
var step = parseFloat(input.prop('step'));
|
||||
var step_decimals = input.prop('step').length - 2;
|
||||
|
||||
input.val((current_value + step).toFixed(step_decimals));
|
||||
}
|
||||
|
||||
input.change();
|
||||
});
|
||||
|
||||
$('.down', spinner).click(function() {
|
||||
if (isInt) {
|
||||
var current_value = parseInt(input.val());
|
||||
input.val(current_value - 1);
|
||||
} else {
|
||||
var current_value = parseFloat(input.val());
|
||||
var step = parseFloat(input.prop('step'));
|
||||
var step_decimals = input.prop('step').length - 2;
|
||||
|
||||
input.val((current_value - step).toFixed(step_decimals));
|
||||
}
|
||||
|
||||
input.change();
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue