Skip to content

Commit b646617

Browse files
committed
Merge pull request #203 from angular-slider/draggableRangeOnly
Add a draggableRangeOnly options.
2 parents 0a50096 + 02fb4aa commit b646617

File tree

9 files changed

+160
-51
lines changed

9 files changed

+160
-51
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ $scope.slider = {
206206

207207
**stepsArray** - _Array_: If you want to display a slider with non linear/number steps. Just pass an array with each slider value and that's it; the floor, ceil and step settings of the slider will be computed automatically. The `rz-slider-model` value will be the index of the selected item in the stepsArray.
208208

209-
**draggableRange** - _Boolean (defaults to false)_: When set to true and using a range slider, the range can be dragged by the selection bar. _This doesn't work when ticks are shown._
209+
**draggableRange** - _Boolean (defaults to false)_: When set to true and using a range slider, the range can be dragged by the selection bar.
210+
211+
**draggableRangeOnly** - _Boolean (defaults to false)_: Same as draggableRange but the slider range can't be changed.
210212

211213
**showSelectionBar** - _Boolean (defaults to false)_: Set to true to always show the selection bar.
212214

demo/demo.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
139139
}
140140
};
141141

142+
//Slider with draggable range only
143+
$scope.slider_draggable_range_only = {
144+
minValue: 4,
145+
maxValue: 6,
146+
options: {
147+
ceil: 10,
148+
floor: 0,
149+
draggableRangeOnly: true
150+
}
151+
};
152+
142153
//Vertical sliders
143154
$scope.verticalSlider1 = {
144155
value: 0,

demo/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ <h2>Slider with draggable range</h2>
123123
></rzslider>
124124
</article>
125125

126+
<article>
127+
<h2>Slider with draggable range only</h2>
128+
<rzslider
129+
rz-slider-model="slider_draggable_range_only.minValue"
130+
rz-slider-high="slider_draggable_range_only.maxValue"
131+
rz-slider-options="slider_draggable_range_only.options"
132+
></rzslider>
133+
</article>
134+
126135
<article>
127136
<h2>Vertical sliders</h2>
128137
<div class="row vertical-sliders" style="margin: 20px;">

dist/rzslider.css

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
/*! angularjs-slider - v2.2.0 -
2-
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
3-
https://github.com/angular-slider/angularjs-slider -
4-
2015-12-21 */
1+
/**
2+
* Angular JS slider directive
3+
*
4+
* (c) Rafal Zajac <[email protected]>
5+
* http://github.com/rzajac/angularjs-slider
6+
*
7+
* Licensed under the MIT license
8+
*/
9+
510
rzslider {
611
position: relative;
712
display: inline-block;
@@ -126,6 +131,7 @@ rzslider .rz-ticks {
126131
display: -ms-flexbox;
127132
display: flex;
128133
width: 100%;
134+
height: 0;
129135
padding: 0 11px;
130136
margin: 0;
131137
list-style: none;
@@ -206,7 +212,7 @@ rzslider.vertical .rz-ticks {
206212
top: 0;
207213
left: -3px;
208214
z-index: 1;
209-
width: auto;
215+
width: 0;
210216
height: 100%;
211217
padding: 11px 0;
212218
-webkit-flex-direction: column-reverse;

dist/rzslider.js

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
translate: null,
3535
stepsArray: null,
3636
draggableRange: false,
37+
draggableRangeOnly: false,
3738
showSelectionBar: false,
3839
hideLimitLabels: false,
3940
readOnly: false,
@@ -292,9 +293,6 @@
292293
// Recalculate stuff if view port dimensions have changed
293294
angular.element($window).on('resize', calcDimFn);
294295

295-
if (this.options.vertical)
296-
this.sliderElem.addClass('vertical');
297-
298296
this.initHasRun = true;
299297

300298
// Watch for changes to the model
@@ -369,8 +367,14 @@
369367

370368
if (this.options.step <= 0)
371369
this.options.step = 1;
370+
372371
this.range = this.scope.rzSliderModel !== undefined && this.scope.rzSliderHigh !== undefined;
373372
this.options.draggableRange = this.range && this.options.draggableRange;
373+
this.options.draggableRangeOnly = this.range && this.options.draggableRangeOnly;
374+
if (this.options.draggableRangeOnly) {
375+
this.options.draggableRange = true;
376+
}
377+
374378
this.options.showTicks = this.options.showTicks || this.options.showTicksValues;
375379
this.scope.showTicks = this.options.showTicks; //scope is used in the template
376380

@@ -486,6 +490,9 @@
486490
this.alwaysHide(this.cmbLab, this.options.showTicksValues || !this.range);
487491
this.alwaysHide(this.selBar, !this.range && !this.options.showSelectionBar);
488492

493+
if (this.options.vertical)
494+
this.sliderElem.addClass('vertical');
495+
489496
if (this.options.draggableRange)
490497
this.selBar.addClass('rz-draggable');
491498
else
@@ -1143,27 +1150,42 @@
11431150
barMove = this.onMove;
11441151
}
11451152

1146-
this.minH.on('mousedown', angular.bind(this, this.onStart, this.minH, 'rzSliderModel'));
1147-
if (this.range) {
1148-
this.maxH.on('mousedown', angular.bind(this, this.onStart, this.maxH, 'rzSliderHigh'));
1149-
}
1150-
this.fullBar.on('mousedown', angular.bind(this, this.onStart, null, null));
1151-
this.fullBar.on('mousedown', angular.bind(this, this.onMove, this.fullBar));
11521153
this.selBar.on('mousedown', angular.bind(this, barStart, null, barTracking));
11531154
this.selBar.on('mousedown', angular.bind(this, barMove, this.selBar));
1154-
this.ticks.on('mousedown', angular.bind(this, this.onStart, null, null));
1155-
this.ticks.on('mousedown', angular.bind(this, this.onMove, this.ticks));
11561155

1157-
this.minH.on('touchstart', angular.bind(this, this.onStart, this.minH, 'rzSliderModel'));
1158-
if (this.range) {
1159-
this.maxH.on('touchstart', angular.bind(this, this.onStart, this.maxH, 'rzSliderHigh'));
1156+
if (this.options.draggableRangeOnly) {
1157+
this.minH.on('mousedown', angular.bind(this, barStart, null, barTracking));
1158+
if (this.range) {
1159+
this.maxH.on('mousedown', angular.bind(this, barStart, null, barTracking));
1160+
}
1161+
} else {
1162+
this.minH.on('mousedown', angular.bind(this, this.onStart, this.minH, 'rzSliderModel'));
1163+
if (this.range) {
1164+
this.maxH.on('mousedown', angular.bind(this, this.onStart, this.maxH, 'rzSliderHigh'));
1165+
}
1166+
this.fullBar.on('mousedown', angular.bind(this, this.onStart, null, null));
1167+
this.fullBar.on('mousedown', angular.bind(this, this.onMove, this.fullBar));
1168+
this.ticks.on('mousedown', angular.bind(this, this.onStart, null, null));
1169+
this.ticks.on('mousedown', angular.bind(this, this.onMove, this.ticks));
11601170
}
1161-
this.fullBar.on('touchstart', angular.bind(this, this.onStart, null, null));
1162-
this.fullBar.on('touchstart', angular.bind(this, this.onMove, this.fullBar));
1171+
11631172
this.selBar.on('touchstart', angular.bind(this, barStart, null, barTracking));
11641173
this.selBar.on('touchstart', angular.bind(this, barMove, this.selBar));
1165-
this.ticks.on('touchstart', angular.bind(this, this.onStart, null, null));
1166-
this.ticks.on('touchstart', angular.bind(this, this.onMove, this.ticks));
1174+
if (this.options.draggableRangeOnly) {
1175+
this.minH.on('touchstart', angular.bind(this, barStart, null, barTracking));
1176+
if (this.range) {
1177+
this.maxH.on('touchstart', angular.bind(this, barStart, null, barTracking));
1178+
}
1179+
} else {
1180+
this.minH.on('touchstart', angular.bind(this, this.onStart, this.minH, 'rzSliderModel'));
1181+
if (this.range) {
1182+
this.maxH.on('touchstart', angular.bind(this, this.onStart, this.maxH, 'rzSliderHigh'));
1183+
}
1184+
this.fullBar.on('touchstart', angular.bind(this, this.onStart, null, null));
1185+
this.fullBar.on('touchstart', angular.bind(this, this.onMove, this.fullBar));
1186+
this.ticks.on('touchstart', angular.bind(this, this.onStart, null, null));
1187+
this.ticks.on('touchstart', angular.bind(this, this.onMove, this.ticks));
1188+
}
11671189

11681190
if (this.options.keyboardSupport) {
11691191
this.minH.on('focus', angular.bind(this, this.onPointerFocus, this.minH, 'rzSliderModel'));
@@ -1319,7 +1341,27 @@
13191341

13201342
var newValue = this.roundStep(this.sanitizeValue(action)),
13211343
newOffset = this.valueToOffset(newValue);
1322-
this.positionTrackingHandle(newValue, newOffset);
1344+
if (!this.options.draggableRangeOnly) {
1345+
this.positionTrackingHandle(newValue, newOffset);
1346+
} else {
1347+
var difference = this.scope.rzSliderHigh - this.scope.rzSliderModel,
1348+
newMinOffset, newMaxOffset,
1349+
newMinValue, newMaxValue;
1350+
if (this.tracking === 'rzSliderModel') {
1351+
newMinValue = newValue;
1352+
newMinOffset = newOffset;
1353+
newMaxValue = newValue + difference;
1354+
if (newMaxValue > this.maxValue) return;
1355+
newMaxOffset = this.valueToOffset(newMaxValue);
1356+
} else {
1357+
newMaxValue = newValue;
1358+
newMaxOffset = newOffset;
1359+
newMinValue = newValue - difference;
1360+
if (newMinValue < this.minValue) return;
1361+
newMinOffset = this.valueToOffset(newMinValue);
1362+
}
1363+
this.positionTrackingBar(newMinValue, newMaxValue, newMinOffset, newMaxOffset);
1364+
}
13231365
},
13241366

13251367
/**
@@ -1342,8 +1384,6 @@
13421384
lowDist: offset - this.minH.rzsp,
13431385
highDist: this.maxH.rzsp - offset
13441386
};
1345-
this.minH.addClass('rz-active');
1346-
this.maxH.addClass('rz-active');
13471387

13481388
this.onStart(pointer, ref, event);
13491389
},

dist/rzslider.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rzslider.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)