From 9cce84c8f83986bcbb500b321dc6c79c35794d54 Mon Sep 17 00:00:00 2001 From: Sergey Date: Thu, 30 Jul 2015 11:19:28 +0300 Subject: [PATCH] implemented minRange option in range slider module --- README.md | 6 ++++++ js/jcf.range.js | 11 ++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 84f5f07..a585d14 100644 --- a/README.md +++ b/README.md @@ -281,6 +281,12 @@ Each module has options. Some of options are common between modules and some are string "auto" + + minRange + Works only when multiple slider handles are used. Sets the minimum range value that can be selected between the two handles + number + 0 + dragHandleCenter Enable this option to make the cursor stick to the center of the input handle diff --git a/js/jcf.range.js b/js/jcf.range.js index b1eb3ad..743c8fd 100644 --- a/js/jcf.range.js +++ b/js/jcf.range.js @@ -26,7 +26,8 @@ range: false, // or "min", "max", "all" dragHandleCenter: true, snapToMarks: true, - snapRadius: 5 + snapRadius: 5, + minRange: 0 }, matchElement: function(element) { return element.is(this.selector); @@ -145,10 +146,10 @@ maxStep = Infinity; if (handleIndex > 0) { - minStep = this.valueToStepIndex(this.values[handleIndex - 1]); + minStep = this.valueToStepIndex(parseFloat(this.values[handleIndex - 1]) + this.options.minRange); } if (handleIndex < this.handleCount - 1) { - maxStep = this.valueToStepIndex(this.values[handleIndex + 1]); + maxStep = this.valueToStepIndex(parseFloat(this.values[handleIndex + 1]) - this.options.minRange); } return { @@ -411,10 +412,10 @@ if (this.handleCount > 1) { if (this.activeDragHandleIndex > 0) { - minValue = parseFloat(this.values[this.activeDragHandleIndex - 1]); + minValue = parseFloat(this.values[this.activeDragHandleIndex - 1]) + this.options.minRange; } if (this.activeDragHandleIndex < this.handleCount - 1) { - maxValue = parseFloat(this.values[this.activeDragHandleIndex + 1]); + maxValue = parseFloat(this.values[this.activeDragHandleIndex + 1]) - this.options.minRange; } }