1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Merge pull request #4801 from dmitrylyzo/backport-fix-slider-step

This commit is contained in:
Bill Thornton 2023-09-24 19:01:11 -04:00 committed by GitHub
commit 274109d0d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,6 +19,27 @@ if (Object.getOwnPropertyDescriptor && Object.defineProperty) {
} }
} }
/**
* Returns normalized slider step.
*
* @param {HTMLInputElement} range slider itself
* @param {number|undefined} step step
* @returns {number} normalized slider step.
*/
function normalizeSliderStep(range, step) {
if (step > 0) {
return step;
}
step = parseFloat(range.step);
if (step > 0) {
return step;
}
return 1;
}
/** /**
* Returns slider fraction corresponding to client position. * Returns slider fraction corresponding to client position.
* *
@ -37,7 +58,7 @@ function mapClientToFraction(range, clientX) {
// Snap to step // Snap to step
const valueRange = range.max - range.min; const valueRange = range.max - range.min;
if (range.step !== 'any' && valueRange !== 0) { if (range.step !== 'any' && valueRange !== 0) {
const step = (range.step || 1) / valueRange; const step = normalizeSliderStep(range) / valueRange;
fraction = Math.round(fraction / step) * step; fraction = Math.round(fraction / step) * step;
} }
@ -56,7 +77,7 @@ function mapFractionToValue(range, fraction) {
// Snap to step // Snap to step
if (range.step !== 'any') { if (range.step !== 'any') {
const step = range.step || 1; const step = normalizeSliderStep(range);
value = Math.round(value / step) * step; value = Math.round(value / step) * step;
} }
@ -455,13 +476,13 @@ function onKeyDown(e) {
switch (keyboardnavigation.getKeyName(e)) { switch (keyboardnavigation.getKeyName(e)) {
case 'ArrowLeft': case 'ArrowLeft':
case 'Left': case 'Left':
stepKeyboard(this, -this.keyboardStepDown || -1); stepKeyboard(this, -normalizeSliderStep(this, this.keyboardStepDown));
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
break; break;
case 'ArrowRight': case 'ArrowRight':
case 'Right': case 'Right':
stepKeyboard(this, this.keyboardStepUp || 1); stepKeyboard(this, normalizeSliderStep(this, this.keyboardStepUp));
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
break; break;