Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

#243 introduce setPositionByValue #334

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions src/rangeslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,8 @@
return;
}

var value = e.target.value,
pos = _this.getPositionFromValue(value);
_this.setPosition(pos);
var value = e.target.value;
_this.setPositionByValue(value);
});
}

Expand Down Expand Up @@ -310,8 +309,7 @@
} else {
this.$range.removeClass(this.options.disabledClass);
}

this.setPosition(this.position, triggerSlide);
this.setPositionByValue(this.value, triggerSlide);
};

Plugin.prototype.handleDown = function(e) {
Expand Down Expand Up @@ -393,6 +391,30 @@
}
};

Plugin.prototype.setPositionByValue = function(value, triggerSlide) {
var newPos;

if (triggerSlide === undefined) {
triggerSlide = true;
}

// Snapping steps
newPos = this.getPositionFromValue(value);

// Update ui
this.$fill[0].style[this.DIMENSION] = (newPos + this.grabPos) + 'px';
this.$handle[0].style[this.DIRECTION_STYLE] = newPos + 'px';
this.setValue(value);

// Update globals
this.position = newPos;
this.value = value;

if (triggerSlide && this.onSlide && typeof this.onSlide === 'function') {
this.onSlide(newPos, value);
}
};

// Returns element position relative to the parent
Plugin.prototype.getPositionFromNode = function(node) {
var i = 0;
Expand Down