Skip to content

Commit

Permalink
fixed dual slider fill
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattk70 committed Sep 27, 2024
1 parent 3390751 commit 14378dd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@
</div>
<div class="form_control">
<div class="form_control_container">
<div class="form_control_container__time">Min</div>
<div class="form_control_container__time">Min Hz</div>
<input class="rounded" type="number" id="fromInput" value="0" min="0" max="11950" step="50"/>
</div>
<div class="form_control_container">
<div class="form_control_container__time">Max</div>
<div class="form_control_container__time">Max Hz</div>
<input class="rounded" type="number" id="toInput" value="11950" min="0" max="11950" step="50"/>
</div>
<div class="form_control_container d-flex">
Expand Down
9 changes: 3 additions & 6 deletions js/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ function controlToSlider(fromSlider, toSlider, toInput) {
}

function getParsed(currentFrom, currentTo) {
const from = parseInt(currentFrom.value, 10);
const to = parseInt(currentTo.value, 10);
const from = currentFrom.valueAsNumber;
const to = currentTo.valueAsNumber;
return [from, to];
}

Expand All @@ -75,10 +75,7 @@ function setToggleAccessible(currentTarget) {
}
}

const fromSlider = document.querySelector('#fromSlider');
const toSlider = document.querySelector('#toSlider');
const fromInput = document.querySelector('#fromInput');
const toInput = document.querySelector('#toInput');

fillSlider(fromSlider, toSlider, '#C6C6C6', '#0d6efd', toSlider);
setToggleAccessible(toSlider);

Expand Down
30 changes: 18 additions & 12 deletions js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ const bodyElement = document.body;
let specElement, waveElement, specCanvasElement, specWaveElement;
let waveCanvasElement, waveWaveElement;
const DOM = {
fromSlider: document.getElementById('fromSlider'),
toSlider: document.getElementById('toSlider'),
fromInput: document.getElementById('fromInput'),
toInput: document.getElementById('toInput'),
audioBitrate: document.getElementById('bitrate'),
audioBitrateContainer: document.getElementById('bitrate-container'),
audioDownmix: document.getElementById('downmix'),
Expand Down Expand Up @@ -1624,10 +1628,11 @@ window.onload = async () => {
// Spectrogram labels
DOM.specLabels.checked = config.specLabels;
// Spectrogram frequencies
document.getElementById('fromInput').value = config.minFrequency;
document.getElementById('fromSlider').value = config.minFrequency;
document.getElementById('toInput').value = config.maxFrequency;
document.getElementById('toSlider').value = config.maxFrequency;
DOM.fromInput.value = config.minFrequency;
DOM.fromSlider.value = config.minFrequency;
DOM.toInput.value = config.maxFrequency;
DOM.toSlider.value = config.maxFrequency;
fillSlider(DOM.fromInput, DOM.toInput, '#C6C6C6', '#0d6efd', DOM.toSlider)
if (config.minFrequency > 0 || config.maxFrequency < 11950) {
document.getElementById('frequency-range').classList.add('text-warning');
}
Expand Down Expand Up @@ -4317,10 +4322,11 @@ DOM.gain.addEventListener('input', () => {
case 'reset-spec-frequency': {
config.minFrequency = 0;
config.maxFrequency = 11950;
document.getElementById('fromInput').value = config.minFrequency;
document.getElementById('fromSlider').value = config.minFrequency;
document.getElementById('toInput').value = config.maxFrequency;
document.getElementById('toSlider').value = config.maxFrequency;
DOM.fromInput.value = config.minFrequency;
DOM.fromSlider.value = config.minFrequency;
DOM.toInput.value = config.maxFrequency;
DOM.toSlider.value = config.maxFrequency;
fillSlider(DOM.fromInput, DOM.toInput, '#C6C6C6', '#0d6efd', DOM.toSlider)
const fftSamples = wavesurfer.spectrogram.fftSamples;
wavesurfer.destroy();
wavesurfer = undefined;
Expand Down Expand Up @@ -4583,8 +4589,8 @@ DOM.gain.addEventListener('input', () => {
case 'fromInput':
case 'fromSlider': {
config.minFrequency = Math.max(element.valueAsNumber, 0);
document.getElementById('fromInput').value = config.minFrequency;
document.getElementById('fromSlider').value = config.minFrequency;
DOM.fromInput.value = config.minFrequency;
DOM.fromSlider.value = config.minFrequency;
const fftSamples = wavesurfer.spectrogram.fftSamples;
wavesurfer.destroy();
wavesurfer = undefined;
Expand All @@ -4599,8 +4605,8 @@ DOM.gain.addEventListener('input', () => {
case 'toInput':
case 'toSlider': {
config.maxFrequency = Math.min(element.valueAsNumber, 11950);
document.getElementById('toInput').value = config.maxFrequency;
document.getElementById('toSlider').value = config.maxFrequency;
DOM.toInput.value = config.maxFrequency;
DOM.toSlider.value = config.maxFrequency;
const fftSamples = wavesurfer.spectrogram.fftSamples;
wavesurfer.destroy();
wavesurfer = undefined;
Expand Down

0 comments on commit 14378dd

Please sign in to comment.