mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Merge pull request #5667 from dmitrylyzo/fix-slider-float
This commit is contained in:
commit
5495ef220a
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.
|
* Returns normalized slider step.
|
||||||
*
|
*
|
||||||
|
@ -112,12 +129,45 @@ function mapValueToFraction(range, value) {
|
||||||
return Math.min(Math.max(fraction, 0), 1);
|
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.
|
* Updates progress bar.
|
||||||
*
|
*
|
||||||
* @param {boolean} [isValueSet] update by 'valueset' event or by timer
|
* @param {boolean} [isValueSet] update by 'valueset' event or by timer
|
||||||
*/
|
*/
|
||||||
function updateValues(isValueSet) {
|
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
|
// Do not update values by 'valueset' in case of soft-implemented dragging
|
||||||
if (!!isValueSet && (!!this.keyboardDragging || !!this.touched)) {
|
if (!!isValueSet && (!!this.keyboardDragging || !!this.touched)) {
|
||||||
return;
|
return;
|
||||||
|
@ -465,7 +515,7 @@ function finishKeyboardDragging(elem) {
|
||||||
function stepKeyboard(elem, delta) {
|
function stepKeyboard(elem, delta) {
|
||||||
startKeyboardDragging(elem);
|
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', {
|
const event = new Event('input', {
|
||||||
bubbles: true,
|
bubbles: true,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue