Skip to content

Commit

Permalink
Merge pull request #4801 from dmitrylyzo/backport-fix-slider-step
Browse files Browse the repository at this point in the history
  • Loading branch information
thornbill authored Sep 24, 2023
2 parents 286bbcb + b7be3af commit 274109d
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/elements/emby-slider/emby-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -37,7 +58,7 @@ function mapClientToFraction(range, clientX) {
// Snap to step
const valueRange = range.max - range.min;
if (range.step !== 'any' && valueRange !== 0) {
const step = (range.step || 1) / valueRange;
const step = normalizeSliderStep(range) / valueRange;
fraction = Math.round(fraction / step) * step;
}

Expand All @@ -56,7 +77,7 @@ function mapFractionToValue(range, fraction) {

// Snap to step
if (range.step !== 'any') {
const step = range.step || 1;
const step = normalizeSliderStep(range);
value = Math.round(value / step) * step;
}

Expand Down Expand Up @@ -455,13 +476,13 @@ function onKeyDown(e) {
switch (keyboardnavigation.getKeyName(e)) {
case 'ArrowLeft':
case 'Left':
stepKeyboard(this, -this.keyboardStepDown || -1);
stepKeyboard(this, -normalizeSliderStep(this, this.keyboardStepDown));
e.preventDefault();
e.stopPropagation();
break;
case 'ArrowRight':
case 'Right':
stepKeyboard(this, this.keyboardStepUp || 1);
stepKeyboard(this, normalizeSliderStep(this, this.keyboardStepUp));
e.preventDefault();
e.stopPropagation();
break;
Expand Down

0 comments on commit 274109d

Please sign in to comment.