mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Backport pull request #5667 from jellyfin-web/release-10.9.z
Fix uneven slider value
Original-merge: 5495ef220a
Merged-by: thornbill <thornbill@users.noreply.github.com>
Backported-by: Joshua M. Boniface <joshua@boniface.me>
This commit is contained in:
parent
83c1b47688
commit
b568f7845e
1 changed files with 51 additions and 1 deletions
|
@ -22,6 +22,23 @@ if (Object.getOwnPropertyDescriptor && Object.defineProperty) {
|
|||
}
|
||||
}
|
||||
|
||||
let supportsValueAutoSnap = false;
|
||||
{
|
||||
const slider = document.createElement('input');
|
||||
slider.type = 'range';
|
||||
slider.min = '-30';
|
||||
slider.max = '30';
|
||||
slider.step = '0.1';
|
||||
|
||||
slider.value = '0.30000000000000004';
|
||||
|
||||
supportsValueAutoSnap = slider.value === '0.3';
|
||||
|
||||
if (!supportsValueAutoSnap) {
|
||||
console.debug('[EmbySlider] HTMLInputElement doesn\'t snap value - use workaround.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns normalized slider step.
|
||||
*
|
||||
|
@ -112,12 +129,45 @@ function mapValueToFraction(range, value) {
|
|||
return Math.min(Math.max(fraction, 0), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns value snapped to the slider step.
|
||||
*
|
||||
* @param {HTMLInputElement} range slider itself
|
||||
* @param {number} value slider value
|
||||
* @return {number} value snapped to the slider step
|
||||
*/
|
||||
function snapValue(range, value) {
|
||||
if (range.step !== 'any') {
|
||||
const min = parseFloat(range.min);
|
||||
const step = normalizeSliderStep(range);
|
||||
const decimals = Math.max(decimalCount(min), decimalCount(step));
|
||||
|
||||
value -= min;
|
||||
value = Math.round(value / step) * step;
|
||||
value += min;
|
||||
|
||||
value = parseFloat(value.toFixed(decimals));
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates progress bar.
|
||||
*
|
||||
* @param {boolean} [isValueSet] update by 'valueset' event or by timer
|
||||
*/
|
||||
function updateValues(isValueSet) {
|
||||
if (!!isValueSet && !supportsValueAutoSnap) {
|
||||
const value = snapValue(this, parseFloat(this.value)).toString();
|
||||
|
||||
if (this.value !== value) {
|
||||
this.value = value;
|
||||
|
||||
if (supportsValueSetOverride) return;
|
||||
}
|
||||
}
|
||||
|
||||
// Do not update values by 'valueset' in case of soft-implemented dragging
|
||||
if (!!isValueSet && (!!this.keyboardDragging || !!this.touched)) {
|
||||
return;
|
||||
|
@ -465,7 +515,7 @@ function finishKeyboardDragging(elem) {
|
|||
function stepKeyboard(elem, delta) {
|
||||
startKeyboardDragging(elem);
|
||||
|
||||
elem.value = Math.max(elem.min, Math.min(elem.max, parseFloat(elem.value) + delta));
|
||||
elem.value = parseFloat(elem.value) + delta;
|
||||
|
||||
const event = new Event('input', {
|
||||
bubbles: true,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue