Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let numMarkers = (max - min) / step;
// In case distance between max & min is indivisible to step,
// we place the secondary to last marker proportionally at where thumb
// could reach and place the last marker at max value
const indivisible = Math.ceil(numMarkers) !== numMarkers;
if (indivisible) {
numMarkers = Math.ceil(numMarkers);
}
this.adapter_.removeTrackMarkers();
this.adapter_.appendTrackMarkers(numMarkers);
if (indivisible) {
const lastStepRatio = (max - numMarkers * step) / step + 1;
const flex = getCorrectPropertyName(window, 'flex');
this.adapter_.setLastTrackMarkersStyleProperty(flex, String(lastStepRatio));
}
}
}
updateUIForCurrentValue_() {
const {max_: max, min_: min, value_: value} = this;
const pctComplete = (value - min) / (max - min);
let translatePx = pctComplete * this.rect_.width;
if (this.adapter_.isRTL()) {
translatePx = this.rect_.width - translatePx;
}
const transformProp = getCorrectPropertyName(window, 'transform');
const transitionendEvtName = getCorrectEventName(window, 'transitionend');
if (this.inTransit_) {
const onTransitionEnd = () => {
this.setInTransit_(false);
this.adapter_.deregisterThumbContainerInteractionHandler(transitionendEvtName, onTransitionEnd);
};
this.adapter_.registerThumbContainerInteractionHandler(transitionendEvtName, onTransitionEnd);
}
this.updateUIFrame_ = requestAnimationFrame(() => {
// NOTE(traviskaufman): It would be nice to use calc() here,
// but IE cannot handle calcs in transforms correctly.
// See: https://goo.gl/NC2itk
// Also note that the -50% offset is used to center the slider thumb.
this.adapter_.setThumbContainerStyleProperty(transformProp, `translateX(${translatePx}px) translateX(-50%)`);