mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-16 21:05:28 +03:00
extending implementation
This commit is contained in:
parent
3d5e333c6d
commit
98c587c3d9
1 changed files with 94 additions and 91 deletions
185
main.js
185
main.js
|
@ -170,100 +170,103 @@ function add_custom_spinners() {
|
||||||
$('input[type="number"]').each(function() {
|
$('input[type="number"]').each(function() {
|
||||||
var input = $(this);
|
var input = $(this);
|
||||||
|
|
||||||
var isInt = true;
|
// only add new spinner if one doesn't already exist
|
||||||
if (input.prop('step') == '') {
|
if (!input.next().hasClass('spinner')) {
|
||||||
isInt = true;
|
var isInt = true;
|
||||||
} else {
|
if (input.prop('step') == '') {
|
||||||
if (input.prop('step').indexOf('.') == -1) {
|
|
||||||
isInt = true;
|
isInt = true;
|
||||||
} else {
|
} else {
|
||||||
isInt = false;
|
if (input.prop('step').indexOf('.') == -1) {
|
||||||
|
isInt = true;
|
||||||
|
} else {
|
||||||
|
isInt = 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() {
|
||||||
|
up();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.up', spinner).mousedown(function() {
|
||||||
|
GUI.timeout_add('spinner', function() {
|
||||||
|
GUI.interval_add('spinner', function() {
|
||||||
|
up();
|
||||||
|
}, 100, true);
|
||||||
|
}, 250);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.up', spinner).mouseup(function() {
|
||||||
|
GUI.timeout_remove('spinner');
|
||||||
|
GUI.interval_remove('spinner');
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.up', spinner).mouseleave(function() {
|
||||||
|
GUI.timeout_remove('spinner');
|
||||||
|
GUI.interval_remove('spinner');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$('.down', spinner).click(function() {
|
||||||
|
down();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.down', spinner).mousedown(function() {
|
||||||
|
GUI.timeout_add('spinner', function() {
|
||||||
|
GUI.interval_add('spinner', function() {
|
||||||
|
down();
|
||||||
|
}, 100, true);
|
||||||
|
}, 250);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.down', spinner).mouseup(function() {
|
||||||
|
GUI.timeout_remove('spinner');
|
||||||
|
GUI.interval_remove('spinner');
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.down', spinner).mouseleave(function() {
|
||||||
|
GUI.timeout_remove('spinner');
|
||||||
|
GUI.interval_remove('spinner');
|
||||||
|
});
|
||||||
|
|
||||||
|
var up = 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();
|
||||||
|
};
|
||||||
|
|
||||||
|
var down = 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();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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() {
|
|
||||||
up();
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.up', spinner).mousedown(function() {
|
|
||||||
GUI.timeout_add('spinner', function() {
|
|
||||||
GUI.interval_add('spinner', function() {
|
|
||||||
up();
|
|
||||||
}, 100, true);
|
|
||||||
}, 250);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.up', spinner).mouseup(function() {
|
|
||||||
GUI.timeout_remove('spinner');
|
|
||||||
GUI.interval_remove('spinner');
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.up', spinner).mouseleave(function() {
|
|
||||||
GUI.timeout_remove('spinner');
|
|
||||||
GUI.interval_remove('spinner');
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
$('.down', spinner).click(function() {
|
|
||||||
down();
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.down', spinner).mousedown(function() {
|
|
||||||
GUI.timeout_add('spinner', function() {
|
|
||||||
GUI.interval_add('spinner', function() {
|
|
||||||
down();
|
|
||||||
}, 100, true);
|
|
||||||
}, 250);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.down', spinner).mouseup(function() {
|
|
||||||
GUI.timeout_remove('spinner');
|
|
||||||
GUI.interval_remove('spinner');
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.down', spinner).mouseleave(function() {
|
|
||||||
GUI.timeout_remove('spinner');
|
|
||||||
GUI.interval_remove('spinner');
|
|
||||||
});
|
|
||||||
|
|
||||||
var up = 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();
|
|
||||||
};
|
|
||||||
|
|
||||||
var down = 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