Skip to content

Commit

Permalink
implemented minRange option in range slider module
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey authored and Sergey committed Jul 30, 2015
1 parent 400fbd6 commit 9cce84c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ Each module has options. Some of options are common between modules and some are
<td>string</td>
<td><code>"auto"</code></td>
</tr>
<tr>
<td><code>minRange</code></td>
<td>Works only when multiple slider handles are used. Sets the minimum range value that can be selected between the two handles</td>
<td>number</td>
<td><code>0</code></td>
</tr>
<tr>
<td><code>dragHandleCenter</code></td>
<td>Enable this option to make the cursor stick to the center of the input handle</td>
Expand Down
11 changes: 6 additions & 5 deletions js/jcf.range.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
}

Expand Down

1 comment on commit 9cce84c

@Rendez
Copy link
Contributor

@Rendez Rendez commented on 9cce84c Jul 31, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent. An example for my particular use case:

 // size in PX of the handle, 15px
minRange: $('input[name=price]').attr('max') - $('input[name=price]').attr('min')) / (15 * 2)
// of course this is always percentual when it comes to the handle positioning, but it's a handy solution either way.

Please sign in to comment.