implement a frequency input with switchable exponent

This commit is contained in:
Jakob Ketterl
2021-02-27 22:15:19 +01:00
parent ccdb010e9d
commit c389d3b619
5 changed files with 71 additions and 2 deletions

View File

@ -0,0 +1,21 @@
$.fn.frequencyInput = function() {
this.each(function(){
var $group = $(this);
var currentExponent = 0;
$input = $group.find('input');
var setExponent = function() {
var newExponent = parseInt($exponent.val());
var delta = currentExponent - newExponent;
$input.val(parseFloat($input.val()) * 10 ** delta);
currentExponent = newExponent;
};
$exponent = $group.find('select.frequency-exponent');
$exponent.on('change', setExponent);
// calculate initial exponent
$exponent.val(Math.floor(Math.log10($input.val()) / 3) * 3);
setExponent();
})
};

View File

@ -7,4 +7,5 @@ $(function(){
$('#rf_gain').gainInput();
$('.optional-section').optionalSection();
$('#scheduler').schedulerInput();
$('.frequency-input').frequencyInput();
});