diff --git a/CHANGELOG.md b/CHANGELOG.md
index 34439ae..411d67d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+# 2.6.0 (not-released)
+## Features
+- Add a `noSwitching` option to prevent the user from switching the min and max handles (#233).
+
# 2.5.0 (2016-01-24)
## Features
- Add a `minRange` option to set a minimal range (#231).
diff --git a/README.md b/README.md
index bea474a..cf1ea03 100644
--- a/README.md
+++ b/README.md
@@ -184,6 +184,7 @@ The default options are:
keyboardSupport: true,
scale: 1,
enforceRange: false,
+ noSwitching: false,
onlyBindHandles: false,
onStart: null,
onChange: null,
@@ -199,7 +200,7 @@ The default options are:
**precision** - _Number (defaults to 0)_: The precision to display values with. The `toFixed()` is used internally for this.
-**minRange** - _Number (defaults to 0)_: The minimum range authorized on the slider.
+**minRange** - _Number (defaults to 0)_: The minimum range authorized on the slider. *Applies to range slider only.*
**translate** - _Function(value, sliderId)_: Custom translate function. Use this if you want to translate values displayed on the slider. For example if you want to display dollar amounts instead of just numbers:
```html
@@ -226,9 +227,9 @@ $scope.slider = {
**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.
-**draggableRange** - _Boolean (defaults to false)_: When set to true and using a range slider, the range can be dragged by the selection bar.
+**draggableRange** - _Boolean (defaults to false)_: When set to true and using a range slider, the range can be dragged by the selection bar. *Applies to range slider only.*
-**draggableRangeOnly** - _Boolean (defaults to false)_: Same as draggableRange but the slider range can't be changed.
+**draggableRangeOnly** - _Boolean (defaults to false)_: Same as draggableRange but the slider range can't be changed. *Applies to range slider only.*
**showSelectionBar** - _Boolean (defaults to false)_: Set to true to always show the selection bar before the slider handle.
@@ -256,6 +257,8 @@ $scope.slider = {
**enforceRange** - _Boolean (defaults to false)_: Set to true to round the `rzSliderModel` and `rzSliderHigh` to the slider range even when modified from outside the slider. When set to false, if the model values are modified from outside the slider, they are not rounded but they are still rendered properly on the slider.
+**noSwitching** - _Boolean (defaults to false)_: Set to true to prevent to user from switching the min and max handles. *Applies to range slider only.*
+
**onlyBindHandles** - _Boolean (defaults to false)_: Set to true to only bind events on slider handles.
**onStart** - _Function(sliderId, modelValue, highValue)_: Function to be called when a slider update is started. If an id was set in the options, then it's passed to this callback. This callback is called before any update on the model.
diff --git a/demo/demo.js b/demo/demo.js
index b4cd571..909dd5b 100644
--- a/demo/demo.js
+++ b/demo/demo.js
@@ -29,6 +29,18 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
}
};
+ //Range slider with noSwitching config
+ $scope.noSwitchingSlider = {
+ minValue: 10,
+ maxValue: 90,
+ options: {
+ floor: 0,
+ ceil: 100,
+ step: 1,
+ noSwitching: true
+ }
+ };
+
//Slider with selection bar
$scope.slider_visible_bar = {
value: 10,
diff --git a/demo/index.html b/demo/index.html
index 282d44a..052c81f 100644
--- a/demo/index.html
+++ b/demo/index.html
@@ -45,6 +45,15 @@
Range slider with minimum range of 10
>
+
+ Range slider with noSwitching=true
+
+
+
Slider with visible selection bar
, Valentin Hervieu , Jussi Saarivirta , Angelin Sirbu -
https://github.com/angular-slider/angularjs-slider -
- 2016-01-24 */
+ 2016-01-31 */
rzslider {
position: relative;
display: inline-block;
@@ -98,6 +98,10 @@ rzslider .rz-pointer:hover:after {
background-color: #ffffff;
}
+rzslider .rz-pointer.rz-active {
+ z-index: 4;
+}
+
rzslider .rz-pointer.rz-active:after {
background-color: #451aff;
}
diff --git a/dist/rzslider.js b/dist/rzslider.js
index cf144bb..493997d 100644
--- a/dist/rzslider.js
+++ b/dist/rzslider.js
@@ -52,6 +52,7 @@
keyboardSupport: true,
scale: 1,
enforceRange: false,
+ noSwitching: false,
onlyBindHandles: false,
onStart: null,
onChange: null,
@@ -843,7 +844,7 @@
updateHandles: function(which, newOffset) {
if (which === 'rzSliderModel')
this.updateLowHandle(newOffset);
- else if (which === 'rzSliderHigh')
+ else
this.updateHighHandle(newOffset);
this.updateSelectionBar();
@@ -883,7 +884,7 @@
},
/**
- * Show / hide floor / ceiling label
+ * Show/hide floor/ceiling label
*
* @returns {undefined}
*/
@@ -1177,8 +1178,15 @@
if (!this.range) {
return this.minH;
}
- var offset = this.getEventPosition(event);
- return Math.abs(offset - this.minH.rzsp) < Math.abs(offset - this.maxH.rzsp) ? this.minH : this.maxH;
+ var offset = this.getEventPosition(event),
+ distanceMin = Math.abs(offset - this.minH.rzsp),
+ distanceMax = Math.abs(offset - this.maxH.rzsp);
+ if (distanceMin < distanceMax)
+ return this.minH;
+ else if (distanceMin > distanceMax)
+ return this.maxH;
+ else //if event is at the same distance from min/max then if it's at left of minH, we return minH else maxH
+ return offset < this.minH.rzsp ? this.minH : this.maxH;
},
/**
@@ -1322,21 +1330,14 @@
newValue;
if (newOffset <= 0) {
- if (pointer.rzsp === 0)
- return;
newValue = this.minValue;
- newOffset = 0;
} else if (newOffset >= this.maxPos) {
- if (pointer.rzsp === this.maxPos)
- return;
newValue = this.maxValue;
- newOffset = this.maxPos;
} else {
newValue = this.offsetToValue(newOffset);
newValue = this.roundStep(newValue);
- newOffset = this.valueToOffset(newValue);
}
- this.positionTrackingHandle(newValue, newOffset);
+ this.positionTrackingHandle(newValue);
},
/**
@@ -1402,36 +1403,28 @@
if (action == null || this.tracking === '') return;
event.preventDefault();
- var newValue = this.roundStep(this.sanitizeValue(action)),
- newOffset = this.valueToOffset(newValue);
+ var newValue = this.roundStep(this.sanitizeValue(action));
if (!this.options.draggableRangeOnly) {
- this.positionTrackingHandle(newValue, newOffset);
+ this.positionTrackingHandle(newValue);
} else {
var difference = this.scope.rzSliderHigh - this.scope.rzSliderModel,
- newMinOffset, newMaxOffset,
newMinValue, newMaxValue;
if (this.tracking === 'rzSliderModel') {
newMinValue = newValue;
- newMinOffset = newOffset;
newMaxValue = newValue + difference;
if (newMaxValue > this.maxValue) {
newMaxValue = this.maxValue;
newMinValue = newMaxValue - difference;
- newMinOffset = this.valueToOffset(newMinValue);
}
- newMaxOffset = this.valueToOffset(newMaxValue);
} else {
newMaxValue = newValue;
- newMaxOffset = newOffset;
newMinValue = newValue - difference;
if (newMinValue < this.minValue) {
newMinValue = this.minValue;
newMaxValue = newMinValue + difference;
- newMaxOffset = this.valueToOffset(newMaxValue);
}
- newMinOffset = this.valueToOffset(newMinValue);
}
- this.positionTrackingBar(newMinValue, newMaxValue, newMinOffset, newMaxOffset);
+ this.positionTrackingBar(newMinValue, newMaxValue);
}
},
@@ -1469,32 +1462,25 @@
*/
onDragMove: function(pointer, event) {
var newOffset = this.getEventPosition(event),
- newMinOffset, newMaxOffset,
newMinValue, newMaxValue;
if (newOffset <= this.dragging.lowLimit) {
if (this.minH.rzsp === 0)
return;
newMinValue = this.minValue;
- newMinOffset = 0;
newMaxValue = this.minValue + this.dragging.difference;
- newMaxOffset = this.valueToOffset(newMaxValue);
} else if (newOffset >= this.maxPos - this.dragging.highLimit) {
if (this.maxH.rzsp === this.maxPos)
return;
newMaxValue = this.maxValue;
- newMaxOffset = this.maxPos;
newMinValue = this.maxValue - this.dragging.difference;
- newMinOffset = this.valueToOffset(newMinValue);
} else {
newMinValue = this.offsetToValue(newOffset - this.dragging.lowLimit);
newMinValue = this.roundStep(newMinValue);
- newMinOffset = this.valueToOffset(newMinValue);
newMaxValue = newMinValue + this.dragging.difference;
- newMaxOffset = this.valueToOffset(newMaxValue);
}
- this.positionTrackingBar(newMinValue, newMaxValue, newMinOffset, newMaxOffset);
+ this.positionTrackingBar(newMinValue, newMaxValue);
},
/**
@@ -1502,14 +1488,12 @@
*
* @param {number} newMinValue the new minimum value
* @param {number} newMaxValue the new maximum value
- * @param {number} newMinOffset the new minimum offset
- * @param {number} newMaxOffset the new maximum offset
*/
- positionTrackingBar: function(newMinValue, newMaxValue, newMinOffset, newMaxOffset) {
+ positionTrackingBar: function(newMinValue, newMaxValue) {
this.scope.rzSliderModel = newMinValue;
this.scope.rzSliderHigh = newMaxValue;
- this.updateHandles('rzSliderModel', newMinOffset);
- this.updateHandles('rzSliderHigh', newMaxOffset);
+ this.updateHandles('rzSliderModel', this.valueToOffset(newMinValue));
+ this.updateHandles('rzSliderHigh', this.valueToOffset(newMaxValue));
this.applyModel();
},
@@ -1517,52 +1501,55 @@
* Set the new value and offset to the current tracking handle
*
* @param {number} newValue new model value
- * @param {number} newOffset new offset value
*/
- positionTrackingHandle: function(newValue, newOffset) {
+ positionTrackingHandle: function(newValue) {
var valueChanged = false;
- var switched = false;
if (this.range) {
newValue = this.applyMinRange(newValue);
- newOffset = this.valueToOffset(newValue);
/* This is to check if we need to switch the min and max handles */
- if (this.tracking === 'rzSliderModel' && newValue >= this.scope.rzSliderHigh) {
- switched = true;
- this.scope[this.tracking] = this.scope.rzSliderHigh;
- this.updateHandles(this.tracking, this.maxH.rzsp);
- this.updateAriaAttributes();
- this.tracking = 'rzSliderHigh';
- this.minH.removeClass('rz-active');
- this.maxH.addClass('rz-active');
- if (this.options.keyboardSupport)
- this.focusElement(this.maxH);
+ if (this.tracking === 'rzSliderModel' && newValue > this.scope.rzSliderHigh) {
+ if (this.options.noSwitching && this.scope.rzSliderHigh !== this.minValue) {
+ newValue = this.applyMinRange(this.scope.rzSliderHigh);
+ }
+ else {
+ this.scope[this.tracking] = this.scope.rzSliderHigh;
+ this.updateHandles(this.tracking, this.maxH.rzsp);
+ this.updateAriaAttributes();
+ this.tracking = 'rzSliderHigh';
+ this.minH.removeClass('rz-active');
+ this.maxH.addClass('rz-active');
+ if (this.options.keyboardSupport)
+ this.focusElement(this.maxH);
+ }
valueChanged = true;
- } else if (this.tracking === 'rzSliderHigh' && newValue <= this.scope.rzSliderModel) {
- switched = true;
- this.scope[this.tracking] = this.scope.rzSliderModel;
- this.updateHandles(this.tracking, this.minH.rzsp);
- this.updateAriaAttributes();
- this.tracking = 'rzSliderModel';
- this.maxH.removeClass('rz-active');
- this.minH.addClass('rz-active');
- if (this.options.keyboardSupport)
- this.focusElement(this.minH);
+ } else if (this.tracking === 'rzSliderHigh' && newValue < this.scope.rzSliderModel) {
+ if (this.options.noSwitching && this.scope.rzSliderModel !== this.maxValue) {
+ newValue = this.applyMinRange(this.scope.rzSliderModel);
+ }
+ else {
+ this.scope[this.tracking] = this.scope.rzSliderModel;
+ this.updateHandles(this.tracking, this.minH.rzsp);
+ this.updateAriaAttributes();
+ this.tracking = 'rzSliderModel';
+ this.maxH.removeClass('rz-active');
+ this.minH.addClass('rz-active');
+ if (this.options.keyboardSupport)
+ this.focusElement(this.minH);
+ }
valueChanged = true;
}
}
if (this.scope[this.tracking] !== newValue) {
this.scope[this.tracking] = newValue;
- this.updateHandles(this.tracking, newOffset);
+ this.updateHandles(this.tracking, this.valueToOffset(newValue));
this.updateAriaAttributes();
valueChanged = true;
}
- if (valueChanged) {
+ if (valueChanged)
this.applyModel();
- }
- return switched;
},
applyMinRange: function(newValue) {
diff --git a/dist/rzslider.min.css b/dist/rzslider.min.css
index bbbcdc1..989944e 100644
--- a/dist/rzslider.min.css
+++ b/dist/rzslider.min.css
@@ -1,2 +1,2 @@
-/*! angularjs-slider - v2.5.0 - (c) Rafal Zajac , Valentin Hervieu , Jussi Saarivirta , Angelin Sirbu - https://github.com/angular-slider/angularjs-slider - 2016-01-24 */
-rzslider{position:relative;display:inline-block;width:100%;height:4px;margin:35px 0 15px 0;vertical-align:middle;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}rzslider[disabled]{cursor:not-allowed}rzslider[disabled] .rz-pointer{cursor:not-allowed;background-color:#d8e0f3}rzslider span{position:absolute;display:inline-block;white-space:nowrap}rzslider .rz-base{width:100%;height:100%;padding:0}rzslider .rz-bar-wrapper{left:0;z-index:1;width:100%;height:32px;padding-top:16px;margin-top:-16px;box-sizing:border-box}rzslider .rz-bar-wrapper.rz-draggable{cursor:move}rzslider .rz-bar{left:0;z-index:1;width:100%;height:4px;background:#d8e0f3;-webkit-border-radius:2px;-moz-border-radius:2px;border-radius:2px}rzslider .rz-bar.rz-selection{z-index:2;background:#0db9f0;-webkit-border-radius:2px;-moz-border-radius:2px;border-radius:2px}rzslider .rz-pointer{top:-14px;z-index:3;width:32px;height:32px;cursor:pointer;background-color:#0db9f0;-webkit-border-radius:16px;-moz-border-radius:16px;border-radius:16px}rzslider .rz-pointer:after{position:absolute;top:12px;left:12px;width:8px;height:8px;background:#fff;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;content:''}rzslider .rz-pointer:hover:after{background-color:#fff}rzslider .rz-pointer.rz-active:after{background-color:#451aff}rzslider .rz-bubble{bottom:16px;padding:1px 3px;color:#55637d;cursor:default}rzslider .rz-bubble.rz-selection{top:16px}rzslider .rz-bubble.rz-limit{color:#55637d}rzslider .rz-ticks{position:absolute;top:-3px;left:0;z-index:1;display:-webkit-flex;display:-ms-flexbox;display:flex;width:100%;height:0;padding:0 11px;margin:0;list-style:none;box-sizing:border-box;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between}rzslider .rz-ticks .tick{width:10px;height:10px;text-align:center;cursor:pointer;background:#d8e0f3;border-radius:50%}rzslider .rz-ticks .tick.selected{background:#0db9f0}rzslider .rz-ticks .tick .tick-value{position:absolute;top:-30px;transform:translate(-50%,0)}rzslider.vertical{position:relative;width:4px;height:100%;padding:0;margin:0 20px;vertical-align:baseline}rzslider.vertical .rz-base{width:100%;height:100%;padding:0}rzslider.vertical .rz-bar-wrapper{top:auto;left:0;width:32px;height:100%;padding:0 0 0 16px;margin:0 0 0 -16px}rzslider.vertical .rz-bar{bottom:0;left:auto;width:4px;height:100%}rzslider.vertical .rz-pointer{top:auto;bottom:0;left:-14px!important}rzslider.vertical .rz-bubble{bottom:0;left:16px!important;margin-left:3px}rzslider.vertical .rz-bubble.rz-selection{top:auto;left:16px!important}rzslider.vertical .rz-ticks{top:0;left:-3px;z-index:1;width:0;height:100%;padding:11px 0;-webkit-flex-direction:column-reverse;-ms-flex-direction:column-reverse;flex-direction:column-reverse}rzslider.vertical .rz-ticks .tick{vertical-align:middle}rzslider.vertical .rz-ticks .tick .tick-value{top:auto;right:-30px;transform:translate(0,-28%)}
\ No newline at end of file
+/*! angularjs-slider - v2.5.0 - (c) Rafal Zajac , Valentin Hervieu , Jussi Saarivirta , Angelin Sirbu - https://github.com/angular-slider/angularjs-slider - 2016-01-31 */
+rzslider{position:relative;display:inline-block;width:100%;height:4px;margin:35px 0 15px 0;vertical-align:middle;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}rzslider[disabled]{cursor:not-allowed}rzslider[disabled] .rz-pointer{cursor:not-allowed;background-color:#d8e0f3}rzslider span{position:absolute;display:inline-block;white-space:nowrap}rzslider .rz-base{width:100%;height:100%;padding:0}rzslider .rz-bar-wrapper{left:0;z-index:1;width:100%;height:32px;padding-top:16px;margin-top:-16px;box-sizing:border-box}rzslider .rz-bar-wrapper.rz-draggable{cursor:move}rzslider .rz-bar{left:0;z-index:1;width:100%;height:4px;background:#d8e0f3;-webkit-border-radius:2px;-moz-border-radius:2px;border-radius:2px}rzslider .rz-bar.rz-selection{z-index:2;background:#0db9f0;-webkit-border-radius:2px;-moz-border-radius:2px;border-radius:2px}rzslider .rz-pointer{top:-14px;z-index:3;width:32px;height:32px;cursor:pointer;background-color:#0db9f0;-webkit-border-radius:16px;-moz-border-radius:16px;border-radius:16px}rzslider .rz-pointer:after{position:absolute;top:12px;left:12px;width:8px;height:8px;background:#fff;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;content:''}rzslider .rz-pointer:hover:after{background-color:#fff}rzslider .rz-pointer.rz-active{z-index:4}rzslider .rz-pointer.rz-active:after{background-color:#451aff}rzslider .rz-bubble{bottom:16px;padding:1px 3px;color:#55637d;cursor:default}rzslider .rz-bubble.rz-selection{top:16px}rzslider .rz-bubble.rz-limit{color:#55637d}rzslider .rz-ticks{position:absolute;top:-3px;left:0;z-index:1;display:-webkit-flex;display:-ms-flexbox;display:flex;width:100%;height:0;padding:0 11px;margin:0;list-style:none;box-sizing:border-box;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between}rzslider .rz-ticks .tick{width:10px;height:10px;text-align:center;cursor:pointer;background:#d8e0f3;border-radius:50%}rzslider .rz-ticks .tick.selected{background:#0db9f0}rzslider .rz-ticks .tick .tick-value{position:absolute;top:-30px;transform:translate(-50%,0)}rzslider.vertical{position:relative;width:4px;height:100%;padding:0;margin:0 20px;vertical-align:baseline}rzslider.vertical .rz-base{width:100%;height:100%;padding:0}rzslider.vertical .rz-bar-wrapper{top:auto;left:0;width:32px;height:100%;padding:0 0 0 16px;margin:0 0 0 -16px}rzslider.vertical .rz-bar{bottom:0;left:auto;width:4px;height:100%}rzslider.vertical .rz-pointer{top:auto;bottom:0;left:-14px!important}rzslider.vertical .rz-bubble{bottom:0;left:16px!important;margin-left:3px}rzslider.vertical .rz-bubble.rz-selection{top:auto;left:16px!important}rzslider.vertical .rz-ticks{top:0;left:-3px;z-index:1;width:0;height:100%;padding:11px 0;-webkit-flex-direction:column-reverse;-ms-flex-direction:column-reverse;flex-direction:column-reverse}rzslider.vertical .rz-ticks .tick{vertical-align:middle}rzslider.vertical .rz-ticks .tick .tick-value{top:auto;right:-30px;transform:translate(0,-28%)}
\ No newline at end of file
diff --git a/dist/rzslider.min.js b/dist/rzslider.min.js
index 71a9fb4..c3728d7 100644
--- a/dist/rzslider.min.js
+++ b/dist/rzslider.min.js
@@ -1,2 +1,2 @@
/*! angularjs-slider - v2.5.0 - (c) Rafal Zajac , Valentin Hervieu , Jussi Saarivirta , Angelin Sirbu - https://github.com/angular-slider/angularjs-slider - 2016-01-31 */
-!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["angular"],b):"object"==typeof module&&module.exports?module.exports=b(require("angular")):b(a.angular)}(this,function(a){"use strict";var b=a.module("rzModule",[]).factory("RzSliderOptions",function(){var b={floor:0,ceil:null,step:1,precision:0,minRange:0,id:null,translate:null,stepsArray:null,draggableRange:!1,draggableRangeOnly:!1,showSelectionBar:!1,showSelectionBarEnd:!1,hideLimitLabels:!1,readOnly:!1,disabled:!1,interval:350,showTicks:!1,showTicksValues:!1,ticksTooltip:null,ticksValuesTooltip:null,vertical:!1,selectionBarColor:null,keyboardSupport:!0,scale:1,enforceRange:!1,onlyBindHandles:!1,onStart:null,onChange:null,onEnd:null},c={},d={};return d.options=function(b){a.extend(c,b)},d.getOptions=function(d){return a.extend({},b,c,d)},d}).factory("rzThrottle",["$timeout",function(a){return function(b,c,d){var e,f,g,h=Date.now||function(){return(new Date).getTime()},i=null,j=0;d=d||{};var k=function(){j=h(),i=null,g=b.apply(e,f),e=f=null};return function(){var l=h(),m=c-(l-j);return e=this,f=arguments,0>=m?(a.cancel(i),i=null,j=l,g=b.apply(e,f),e=f=null):i||d.trailing===!1||(i=a(k,m)),g}}}]).factory("RzSlider",["$timeout","$document","$window","$compile","RzSliderOptions","rzThrottle",function(b,c,d,e,f,g){var h=function(a,b){this.scope=a,this.sliderElem=b,this.range=void 0!==this.scope.rzSliderModel&&void 0!==this.scope.rzSliderHigh,this.dragging={active:!1,value:0,difference:0,offset:0,lowLimit:0,highLimit:0},this.positionProperty="left",this.dimensionProperty="width",this.handleHalfDim=0,this.maxPos=0,this.precision=0,this.step=1,this.tracking="",this.minValue=0,this.maxValue=0,this.valueRange=0,this.initHasRun=!1,this.internalChange=!1,this.fullBar=null,this.selBar=null,this.minH=null,this.maxH=null,this.flrLab=null,this.ceilLab=null,this.minLab=null,this.maxLab=null,this.cmbLab=null,this.ticks=null,this.init()};return h.prototype={init:function(){var b,c,e=this,f=function(){e.calcViewDimensions()};this.applyOptions(),this.initElemHandles(),this.manageElementsStyle(),this.setDisabledState(),this.calcViewDimensions(),this.setMinAndMax(),this.addAccessibility(),this.updateCeilLab(),this.updateFloorLab(),this.initHandles(),this.manageEventsBindings(),this.scope.$on("reCalcViewDimensions",f),a.element(d).on("resize",f),this.initHasRun=!0,b=g(function(){e.onLowHandleChange()},e.options.interval),c=g(function(){e.onHighHandleChange()},e.options.interval),this.scope.$on("rzSliderForceRender",function(){e.resetLabelsValue(),b(),e.range&&c(),e.resetSlider()}),this.scope.$watch("rzSliderOptions",function(a,b){a!==b&&(e.applyOptions(),e.resetSlider())},!0),this.scope.$watch("rzSliderModel",function(a,c){e.internalChange||a!==c&&b()}),this.scope.$watch("rzSliderHigh",function(a,b){e.internalChange||a!==b&&(null!=a&&c(),(e.range&&null==a||!e.range&&null!=a)&&(e.applyOptions(),e.resetSlider()))}),this.scope.$on("$destroy",function(){e.unbindEvents(),a.element(d).off("resize",f)})},onLowHandleChange:function(){this.setMinAndMax(),this.updateLowHandle(this.valueToOffset(this.scope.rzSliderModel)),this.updateSelectionBar(),this.updateTicksScale(),this.updateAriaAttributes(),this.range&&this.updateCmbLabel()},onHighHandleChange:function(){this.setMinAndMax(),this.updateHighHandle(this.valueToOffset(this.scope.rzSliderHigh)),this.updateSelectionBar(),this.updateTicksScale(),this.updateCmbLabel(),this.updateAriaAttributes()},applyOptions:function(){this.options=f.getOptions(this.scope.rzSliderOptions),this.options.step<=0&&(this.options.step=1),this.range=void 0!==this.scope.rzSliderModel&&void 0!==this.scope.rzSliderHigh,this.options.draggableRange=this.range&&this.options.draggableRange,this.options.draggableRangeOnly=this.range&&this.options.draggableRangeOnly,this.options.draggableRangeOnly&&(this.options.draggableRange=!0),this.options.showTicks=this.options.showTicks||this.options.showTicksValues,this.scope.showTicks=this.options.showTicks,this.options.showSelectionBar=this.options.showSelectionBar||this.options.showSelectionBarEnd,this.options.stepsArray?(this.options.floor=0,this.options.ceil=this.options.stepsArray.length-1,this.options.step=1,this.customTrFn=function(a){return this.options.stepsArray[a]}):this.options.translate?this.customTrFn=this.options.translate:this.customTrFn=function(a){return String(a)},this.options.vertical&&(this.positionProperty="bottom",this.dimensionProperty="height")},resetSlider:function(){this.manageElementsStyle(),this.addAccessibility(),this.setMinAndMax(),this.updateCeilLab(),this.updateFloorLab(),this.unbindEvents(),this.manageEventsBindings(),this.setDisabledState(),this.calcViewDimensions()},initElemHandles:function(){a.forEach(this.sliderElem.children(),function(b,c){var d=a.element(b);switch(c){case 0:this.fullBar=d;break;case 1:this.selBar=d;break;case 2:this.minH=d;break;case 3:this.maxH=d;break;case 4:this.flrLab=d;break;case 5:this.ceilLab=d;break;case 6:this.minLab=d;break;case 7:this.maxLab=d;break;case 8:this.cmbLab=d;break;case 9:this.ticks=d}},this),this.selBar.rzsp=0,this.minH.rzsp=0,this.maxH.rzsp=0,this.flrLab.rzsp=0,this.ceilLab.rzsp=0,this.minLab.rzsp=0,this.maxLab.rzsp=0,this.cmbLab.rzsp=0},manageElementsStyle:function(){this.range?this.maxH.css("display",""):this.maxH.css("display","none"),this.alwaysHide(this.flrLab,this.options.showTicksValues||this.options.hideLimitLabels),this.alwaysHide(this.ceilLab,this.options.showTicksValues||this.options.hideLimitLabels),this.alwaysHide(this.minLab,this.options.showTicksValues),this.alwaysHide(this.maxLab,this.options.showTicksValues||!this.range),this.alwaysHide(this.cmbLab,this.options.showTicksValues||!this.range),this.alwaysHide(this.selBar,!this.range&&!this.options.showSelectionBar),this.options.vertical&&this.sliderElem.addClass("vertical"),this.options.draggableRange?this.selBar.addClass("rz-draggable"):this.selBar.removeClass("rz-draggable")},alwaysHide:function(a,b){a.rzAlwaysHide=b,b?this.hideEl(a):this.showEl(a)},manageEventsBindings:function(){this.options.disabled||this.options.readOnly?this.unbindEvents():this.bindEvents()},setDisabledState:function(){this.options.disabled?this.sliderElem.attr("disabled","disabled"):this.sliderElem.attr("disabled",null)},resetLabelsValue:function(){this.minLab.rzsv=void 0,this.maxLab.rzsv=void 0},initHandles:function(){this.updateLowHandle(this.valueToOffset(this.scope.rzSliderModel)),this.range&&this.updateHighHandle(this.valueToOffset(this.scope.rzSliderHigh)),this.updateSelectionBar(),this.range&&this.updateCmbLabel(),this.updateTicksScale()},translateFn:function(a,b,c){c=void 0===c?!0:c;var d=String(c?this.customTrFn(a,this.options.id):a),e=!1;(void 0===b.rzsv||b.rzsv.length!==d.length||b.rzsv.length>0&&0===b.rzsd)&&(e=!0,b.rzsv=d),b.text(d),e&&this.getDimension(b)},setMinAndMax:function(){this.step=+this.options.step,this.precision=+this.options.precision,this.minValue=this.options.floor,this.scope.rzSliderModel=this.roundStep(this.scope.rzSliderModel),this.range&&(this.scope.rzSliderHigh=this.roundStep(this.scope.rzSliderHigh)),null!=this.options.ceil?this.maxValue=this.options.ceil:this.maxValue=this.options.ceil=this.range?this.scope.rzSliderHigh:this.scope.rzSliderModel,this.options.enforceRange&&(this.scope.rzSliderModel=this.sanitizeValue(this.scope.rzSliderModel),this.range&&(this.scope.rzSliderHigh=this.sanitizeValue(this.scope.rzSliderHigh))),this.valueRange=this.maxValue-this.minValue},addAccessibility:function(){this.minH.attr("role","slider"),this.updateAriaAttributes(),!this.options.keyboardSupport||this.options.readOnly||this.options.disabled?this.minH.attr("tabindex",""):this.minH.attr("tabindex","0"),this.options.vertical&&this.minH.attr("aria-orientation","vertical"),this.range&&(this.maxH.attr("role","slider"),!this.options.keyboardSupport||this.options.readOnly||this.options.disabled?this.maxH.attr("tabindex",""):this.maxH.attr("tabindex","0"),this.options.vertical&&this.maxH.attr("aria-orientation","vertical"))},updateAriaAttributes:function(){this.minH.attr({"aria-valuenow":this.scope.rzSliderModel,"aria-valuetext":this.customTrFn(this.scope.rzSliderModel),"aria-valuemin":this.minValue,"aria-valuemax":this.maxValue}),this.range&&this.maxH.attr({"aria-valuenow":this.scope.rzSliderHigh,"aria-valuetext":this.customTrFn(this.scope.rzSliderHigh),"aria-valuemin":this.minValue,"aria-valuemax":this.maxValue})},calcViewDimensions:function(){var a=this.getDimension(this.minH);this.handleHalfDim=a/2,this.barDimension=this.getDimension(this.fullBar),this.maxPos=this.barDimension-a,this.getDimension(this.sliderElem),this.sliderElem.rzsp=this.sliderElem[0].getBoundingClientRect()[this.positionProperty],this.initHasRun&&(this.updateFloorLab(),this.updateCeilLab(),this.initHandles())},updateTicksScale:function(){if(this.options.showTicks){var a=Math.round((this.maxValue-this.minValue)/this.step)+1;this.scope.ticks=[];for(var b=0;a>b;b++){var c=this.roundStep(this.minValue+b*this.step),d={selected:this.isTickSelected(c)};d.selected&&this.options.getSelectionBarColor&&(d.style={"background-color":this.getSelectionBarColor()}),this.options.ticksTooltip&&(d.tooltip=this.options.ticksTooltip(c),d.tooltipPlacement=this.options.vertical?"right":"top"),this.options.showTicksValues&&(d.value=this.getDisplayValue(c),this.options.ticksValuesTooltip&&(d.valueTooltip=this.options.ticksValuesTooltip(c),d.valueTooltipPlacement=this.options.vertical?"right":"top")),this.scope.ticks.push(d)}}},isTickSelected:function(a){return!this.range&&this.options.showSelectionBar&&a<=this.scope.rzSliderModel?!0:this.range&&a>=this.scope.rzSliderModel&&a<=this.scope.rzSliderHigh?!0:!1},updateCeilLab:function(){this.translateFn(this.maxValue,this.ceilLab),this.setPosition(this.ceilLab,this.barDimension-this.ceilLab.rzsd),this.getDimension(this.ceilLab)},updateFloorLab:function(){this.translateFn(this.minValue,this.flrLab),this.getDimension(this.flrLab)},callOnStart:function(){if(this.options.onStart){var a=this;this.scope.$evalAsync(function(){a.options.onStart(a.options.id,a.scope.rzSliderModel,a.scope.rzSliderHigh)})}},callOnChange:function(){if(this.options.onChange){var a=this;this.scope.$evalAsync(function(){a.options.onChange(a.options.id,a.scope.rzSliderModel,a.scope.rzSliderHigh)})}},callOnEnd:function(){if(this.options.onEnd){var a=this;this.scope.$evalAsync(function(){a.options.onEnd(a.options.id,a.scope.rzSliderModel,a.scope.rzSliderHigh)})}},updateHandles:function(a,b){"rzSliderModel"===a?this.updateLowHandle(b):"rzSliderHigh"===a&&this.updateHighHandle(b),this.updateSelectionBar(),this.updateTicksScale(),this.range&&this.updateCmbLabel()},updateLowHandle:function(a){this.setPosition(this.minH,a),this.translateFn(this.scope.rzSliderModel,this.minLab);var b=Math.min(Math.max(a-this.minLab.rzsd/2+this.handleHalfDim,0),this.barDimension-this.ceilLab.rzsd);this.setPosition(this.minLab,b),this.shFloorCeil()},updateHighHandle:function(a){this.setPosition(this.maxH,a),this.translateFn(this.scope.rzSliderHigh,this.maxLab);var b=Math.min(a-this.maxLab.rzsd/2+this.handleHalfDim,this.barDimension-this.ceilLab.rzsd);this.setPosition(this.maxLab,b),this.shFloorCeil()},shFloorCeil:function(){var a=!1,b=!1;this.minLab.rzsp<=this.flrLab.rzsp+this.flrLab.rzsd+5?(a=!0,this.hideEl(this.flrLab)):(a=!1,this.showEl(this.flrLab)),this.minLab.rzsp+this.minLab.rzsd>=this.ceilLab.rzsp-this.handleHalfDim-10?(b=!0,this.hideEl(this.ceilLab)):(b=!1,this.showEl(this.ceilLab)),this.range&&(this.maxLab.rzsp+this.maxLab.rzsd>=this.ceilLab.rzsp-10?this.hideEl(this.ceilLab):b||this.showEl(this.ceilLab),this.maxLab.rzsp<=this.flrLab.rzsp+this.flrLab.rzsd+this.handleHalfDim?this.hideEl(this.flrLab):a||this.showEl(this.flrLab))},updateSelectionBar:function(){var a=0,b=0;if(this.range||!this.options.showSelectionBarEnd?(b=Math.abs(this.maxH.rzsp-this.minH.rzsp)+this.handleHalfDim,a=this.range?this.minH.rzsp+this.handleHalfDim:0):(b=Math.abs(this.maxPos-this.minH.rzsp)+this.handleHalfDim,a=this.minH.rzsp+this.handleHalfDim),this.setDimension(this.selBar,b),this.setPosition(this.selBar,a),this.options.getSelectionBarColor){var c=this.getSelectionBarColor();this.scope.barStyle={backgroundColor:c}}},getSelectionBarColor:function(){return this.range?this.options.getSelectionBarColor(this.scope.rzSliderModel,this.scope.rzSliderHigh):this.options.getSelectionBarColor(this.scope.rzSliderModel)},updateCmbLabel:function(){var a,b;if(this.minLab.rzsp+this.minLab.rzsd+10>=this.maxLab.rzsp){a=this.getDisplayValue(this.scope.rzSliderModel),b=this.getDisplayValue(this.scope.rzSliderHigh),this.translateFn(a+" - "+b,this.cmbLab,!1);var c=Math.min(Math.max(this.selBar.rzsp+this.selBar.rzsd/2-this.cmbLab.rzsd/2,0),this.barDimension-this.cmbLab.rzsd);this.setPosition(this.cmbLab,c),this.hideEl(this.minLab),this.hideEl(this.maxLab),this.showEl(this.cmbLab)}else this.showEl(this.maxLab),this.showEl(this.minLab),this.hideEl(this.cmbLab)},getDisplayValue:function(a){return this.customTrFn(a,this.options.id)},roundStep:function(a){var b=parseFloat((a-this.minValue)/this.step).toPrecision(12);b=Math.round(+b)*this.step;var c=(this.minValue+ +b).toFixed(this.precision);return+c},hideEl:function(a){return a.css({opacity:0})},showEl:function(a){return a.rzAlwaysHide?a:a.css({opacity:1})},setPosition:function(a,b){a.rzsp=b;var c={};return c[this.positionProperty]=b+"px",a.css(c),b},getDimension:function(a){var b=a[0].getBoundingClientRect();return this.options.vertical?a.rzsd=(b.bottom-b.top)*this.options.scale:a.rzsd=(b.right-b.left)*this.options.scale,a.rzsd},setDimension:function(a,b){a.rzsd=b;var c={};return c[this.dimensionProperty]=b+"px",a.css(c),b},valueToOffset:function(a){return(this.sanitizeValue(a)-this.minValue)*this.maxPos/this.valueRange||0},sanitizeValue:function(a){return Math.min(Math.max(a,this.minValue),this.maxValue)},offsetToValue:function(a){return a/this.maxPos*this.valueRange+this.minValue},getEventXY:function(a){var b=this.options.vertical?"clientY":"clientX";return b in a?a[b]:void 0===a.originalEvent?a.touches[0][b]:a.originalEvent.touches[0][b]},getEventPosition:function(a){var b=this.sliderElem.rzsp,c=0;return c=this.options.vertical?-this.getEventXY(a)+b:this.getEventXY(a)-b,(c-this.handleHalfDim)*this.options.scale},getEventNames:function(a){var b={moveEvent:"",endEvent:""};return a.touches||void 0!==a.originalEvent&&a.originalEvent.touches?(b.moveEvent="touchmove",b.endEvent="touchend"):(b.moveEvent="mousemove",b.endEvent="mouseup"),b},getNearestHandle:function(a){if(!this.range)return this.minH;var b=this.getEventPosition(a);return Math.abs(b-this.minH.rzsp)=d){if(0===a.rzsp)return;c=this.minValue,d=0}else if(d>=this.maxPos){if(a.rzsp===this.maxPos)return;c=this.maxValue,d=this.maxPos}else c=this.offsetToValue(d),c=this.roundStep(c),d=this.valueToOffset(c);this.positionTrackingHandle(c,d)},onEnd:function(a,b){var d=this.getEventNames(b).moveEvent;this.options.keyboardSupport||(this.minH.removeClass("rz-active"),this.maxH.removeClass("rz-active"),this.tracking=""),this.dragging.active=!1,c.off(d,a),this.scope.$emit("slideEnded"),this.callOnEnd()},onPointerFocus:function(b,c){this.tracking=c,b.one("blur",a.bind(this,this.onPointerBlur,b)),b.on("keydown",a.bind(this,this.onKeyboardEvent)),b.addClass("rz-active")},onPointerBlur:function(a){a.off("keydown"),this.tracking="",a.removeClass("rz-active")},onKeyboardEvent:function(a){var b=this.scope[this.tracking],c=a.keyCode||a.which,d={38:"UP",40:"DOWN",37:"LEFT",39:"RIGHT",33:"PAGEUP",34:"PAGEDOWN",36:"HOME",35:"END"},e={UP:b+this.step,DOWN:b-this.step,LEFT:b-this.step,RIGHT:b+this.step,PAGEUP:b+this.valueRange/10,PAGEDOWN:b-this.valueRange/10,HOME:this.minValue,END:this.maxValue},f=d[c],g=e[f];if(null!=g&&""!==this.tracking){a.preventDefault();var h=this.roundStep(this.sanitizeValue(g)),i=this.valueToOffset(h);if(this.options.draggableRangeOnly){var j,k,l,m,n=this.scope.rzSliderHigh-this.scope.rzSliderModel;"rzSliderModel"===this.tracking?(l=h,j=i,m=h+n,m>this.maxValue&&(m=this.maxValue,l=m-n,j=this.valueToOffset(l)),k=this.valueToOffset(m)):(m=h,k=i,l=h-n,l=this.maxPos-this.dragging.highLimit){if(this.maxH.rzsp===this.maxPos)return;f=this.maxValue,d=this.maxPos,e=this.maxValue-this.dragging.difference,c=this.valueToOffset(e)}else e=this.offsetToValue(g-this.dragging.lowLimit),e=this.roundStep(e),c=this.valueToOffset(e),f=e+this.dragging.difference,d=this.valueToOffset(f);this.positionTrackingBar(e,f,c,d)},positionTrackingBar:function(a,b,c,d){this.scope.rzSliderModel=a,this.scope.rzSliderHigh=b,this.updateHandles("rzSliderModel",c),this.updateHandles("rzSliderHigh",d),this.applyModel()},positionTrackingHandle:function(a,b){var c=!1,d=!1;return this.range&&(a=this.applyMinRange(a),b=this.valueToOffset(a),"rzSliderModel"===this.tracking&&a>=this.scope.rzSliderHigh?(d=!0,this.scope[this.tracking]=this.scope.rzSliderHigh,this.updateHandles(this.tracking,this.maxH.rzsp),this.updateAriaAttributes(),this.tracking="rzSliderHigh",this.minH.removeClass("rz-active"),this.maxH.addClass("rz-active"),this.options.keyboardSupport&&this.focusElement(this.maxH),c=!0):"rzSliderHigh"===this.tracking&&a<=this.scope.rzSliderModel&&(d=!0,this.scope[this.tracking]=this.scope.rzSliderModel,this.updateHandles(this.tracking,this.minH.rzsp),this.updateAriaAttributes(),this.tracking="rzSliderModel",this.maxH.removeClass("rz-active"),this.minH.addClass("rz-active"),this.options.keyboardSupport&&this.focusElement(this.minH),c=!0)),this.scope[this.tracking]!==a&&(this.scope[this.tracking]=a,this.updateHandles(this.tracking,b),this.updateAriaAttributes(),c=!0),c&&this.applyModel(),d},applyMinRange:function(a){if(0!==this.options.minRange){var b="rzSliderModel"===this.tracking?this.scope.rzSliderHigh:this.scope.rzSliderModel,c=Math.abs(a-b);if(c ')}]),b});
\ No newline at end of file
+!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["angular"],b):"object"==typeof module&&module.exports?module.exports=b(require("angular")):b(a.angular)}(this,function(a){"use strict";var b=a.module("rzModule",[]).factory("RzSliderOptions",function(){var b={floor:0,ceil:null,step:1,precision:0,minRange:0,id:null,translate:null,stepsArray:null,draggableRange:!1,draggableRangeOnly:!1,showSelectionBar:!1,showSelectionBarEnd:!1,hideLimitLabels:!1,readOnly:!1,disabled:!1,interval:350,showTicks:!1,showTicksValues:!1,ticksTooltip:null,ticksValuesTooltip:null,vertical:!1,selectionBarColor:null,keyboardSupport:!0,scale:1,enforceRange:!1,noSwitching:!1,onlyBindHandles:!1,onStart:null,onChange:null,onEnd:null},c={},d={};return d.options=function(b){a.extend(c,b)},d.getOptions=function(d){return a.extend({},b,c,d)},d}).factory("rzThrottle",["$timeout",function(a){return function(b,c,d){var e,f,g,h=Date.now||function(){return(new Date).getTime()},i=null,j=0;d=d||{};var k=function(){j=h(),i=null,g=b.apply(e,f),e=f=null};return function(){var l=h(),m=c-(l-j);return e=this,f=arguments,0>=m?(a.cancel(i),i=null,j=l,g=b.apply(e,f),e=f=null):i||d.trailing===!1||(i=a(k,m)),g}}}]).factory("RzSlider",["$timeout","$document","$window","$compile","RzSliderOptions","rzThrottle",function(b,c,d,e,f,g){var h=function(a,b){this.scope=a,this.sliderElem=b,this.range=void 0!==this.scope.rzSliderModel&&void 0!==this.scope.rzSliderHigh,this.dragging={active:!1,value:0,difference:0,offset:0,lowLimit:0,highLimit:0},this.positionProperty="left",this.dimensionProperty="width",this.handleHalfDim=0,this.maxPos=0,this.precision=0,this.step=1,this.tracking="",this.minValue=0,this.maxValue=0,this.valueRange=0,this.initHasRun=!1,this.internalChange=!1,this.fullBar=null,this.selBar=null,this.minH=null,this.maxH=null,this.flrLab=null,this.ceilLab=null,this.minLab=null,this.maxLab=null,this.cmbLab=null,this.ticks=null,this.init()};return h.prototype={init:function(){var b,c,e=this,f=function(){e.calcViewDimensions()};this.applyOptions(),this.initElemHandles(),this.manageElementsStyle(),this.setDisabledState(),this.calcViewDimensions(),this.setMinAndMax(),this.addAccessibility(),this.updateCeilLab(),this.updateFloorLab(),this.initHandles(),this.manageEventsBindings(),this.scope.$on("reCalcViewDimensions",f),a.element(d).on("resize",f),this.initHasRun=!0,b=g(function(){e.onLowHandleChange()},e.options.interval),c=g(function(){e.onHighHandleChange()},e.options.interval),this.scope.$on("rzSliderForceRender",function(){e.resetLabelsValue(),b(),e.range&&c(),e.resetSlider()}),this.scope.$watch("rzSliderOptions",function(a,b){a!==b&&(e.applyOptions(),e.resetSlider())},!0),this.scope.$watch("rzSliderModel",function(a,c){e.internalChange||a!==c&&b()}),this.scope.$watch("rzSliderHigh",function(a,b){e.internalChange||a!==b&&(null!=a&&c(),(e.range&&null==a||!e.range&&null!=a)&&(e.applyOptions(),e.resetSlider()))}),this.scope.$on("$destroy",function(){e.unbindEvents(),a.element(d).off("resize",f)})},onLowHandleChange:function(){this.setMinAndMax(),this.updateLowHandle(this.valueToOffset(this.scope.rzSliderModel)),this.updateSelectionBar(),this.updateTicksScale(),this.updateAriaAttributes(),this.range&&this.updateCmbLabel()},onHighHandleChange:function(){this.setMinAndMax(),this.updateHighHandle(this.valueToOffset(this.scope.rzSliderHigh)),this.updateSelectionBar(),this.updateTicksScale(),this.updateCmbLabel(),this.updateAriaAttributes()},applyOptions:function(){this.options=f.getOptions(this.scope.rzSliderOptions),this.options.step<=0&&(this.options.step=1),this.range=void 0!==this.scope.rzSliderModel&&void 0!==this.scope.rzSliderHigh,this.options.draggableRange=this.range&&this.options.draggableRange,this.options.draggableRangeOnly=this.range&&this.options.draggableRangeOnly,this.options.draggableRangeOnly&&(this.options.draggableRange=!0),this.options.showTicks=this.options.showTicks||this.options.showTicksValues,this.scope.showTicks=this.options.showTicks,this.options.showSelectionBar=this.options.showSelectionBar||this.options.showSelectionBarEnd,this.options.stepsArray?(this.options.floor=0,this.options.ceil=this.options.stepsArray.length-1,this.options.step=1,this.customTrFn=function(a){return this.options.stepsArray[a]}):this.options.translate?this.customTrFn=this.options.translate:this.customTrFn=function(a){return String(a)},this.options.vertical&&(this.positionProperty="bottom",this.dimensionProperty="height")},resetSlider:function(){this.manageElementsStyle(),this.addAccessibility(),this.setMinAndMax(),this.updateCeilLab(),this.updateFloorLab(),this.unbindEvents(),this.manageEventsBindings(),this.setDisabledState(),this.calcViewDimensions()},initElemHandles:function(){a.forEach(this.sliderElem.children(),function(b,c){var d=a.element(b);switch(c){case 0:this.fullBar=d;break;case 1:this.selBar=d;break;case 2:this.minH=d;break;case 3:this.maxH=d;break;case 4:this.flrLab=d;break;case 5:this.ceilLab=d;break;case 6:this.minLab=d;break;case 7:this.maxLab=d;break;case 8:this.cmbLab=d;break;case 9:this.ticks=d}},this),this.selBar.rzsp=0,this.minH.rzsp=0,this.maxH.rzsp=0,this.flrLab.rzsp=0,this.ceilLab.rzsp=0,this.minLab.rzsp=0,this.maxLab.rzsp=0,this.cmbLab.rzsp=0},manageElementsStyle:function(){this.range?this.maxH.css("display",""):this.maxH.css("display","none"),this.alwaysHide(this.flrLab,this.options.showTicksValues||this.options.hideLimitLabels),this.alwaysHide(this.ceilLab,this.options.showTicksValues||this.options.hideLimitLabels),this.alwaysHide(this.minLab,this.options.showTicksValues),this.alwaysHide(this.maxLab,this.options.showTicksValues||!this.range),this.alwaysHide(this.cmbLab,this.options.showTicksValues||!this.range),this.alwaysHide(this.selBar,!this.range&&!this.options.showSelectionBar),this.options.vertical&&this.sliderElem.addClass("vertical"),this.options.draggableRange?this.selBar.addClass("rz-draggable"):this.selBar.removeClass("rz-draggable")},alwaysHide:function(a,b){a.rzAlwaysHide=b,b?this.hideEl(a):this.showEl(a)},manageEventsBindings:function(){this.options.disabled||this.options.readOnly?this.unbindEvents():this.bindEvents()},setDisabledState:function(){this.options.disabled?this.sliderElem.attr("disabled","disabled"):this.sliderElem.attr("disabled",null)},resetLabelsValue:function(){this.minLab.rzsv=void 0,this.maxLab.rzsv=void 0},initHandles:function(){this.updateLowHandle(this.valueToOffset(this.scope.rzSliderModel)),this.range&&this.updateHighHandle(this.valueToOffset(this.scope.rzSliderHigh)),this.updateSelectionBar(),this.range&&this.updateCmbLabel(),this.updateTicksScale()},translateFn:function(a,b,c){c=void 0===c?!0:c;var d=String(c?this.customTrFn(a,this.options.id):a),e=!1;(void 0===b.rzsv||b.rzsv.length!==d.length||b.rzsv.length>0&&0===b.rzsd)&&(e=!0,b.rzsv=d),b.text(d),e&&this.getDimension(b)},setMinAndMax:function(){this.step=+this.options.step,this.precision=+this.options.precision,this.minValue=this.options.floor,this.scope.rzSliderModel=this.roundStep(this.scope.rzSliderModel),this.range&&(this.scope.rzSliderHigh=this.roundStep(this.scope.rzSliderHigh)),null!=this.options.ceil?this.maxValue=this.options.ceil:this.maxValue=this.options.ceil=this.range?this.scope.rzSliderHigh:this.scope.rzSliderModel,this.options.enforceRange&&(this.scope.rzSliderModel=this.sanitizeValue(this.scope.rzSliderModel),this.range&&(this.scope.rzSliderHigh=this.sanitizeValue(this.scope.rzSliderHigh))),this.valueRange=this.maxValue-this.minValue},addAccessibility:function(){this.minH.attr("role","slider"),this.updateAriaAttributes(),!this.options.keyboardSupport||this.options.readOnly||this.options.disabled?this.minH.attr("tabindex",""):this.minH.attr("tabindex","0"),this.options.vertical&&this.minH.attr("aria-orientation","vertical"),this.range&&(this.maxH.attr("role","slider"),!this.options.keyboardSupport||this.options.readOnly||this.options.disabled?this.maxH.attr("tabindex",""):this.maxH.attr("tabindex","0"),this.options.vertical&&this.maxH.attr("aria-orientation","vertical"))},updateAriaAttributes:function(){this.minH.attr({"aria-valuenow":this.scope.rzSliderModel,"aria-valuetext":this.customTrFn(this.scope.rzSliderModel),"aria-valuemin":this.minValue,"aria-valuemax":this.maxValue}),this.range&&this.maxH.attr({"aria-valuenow":this.scope.rzSliderHigh,"aria-valuetext":this.customTrFn(this.scope.rzSliderHigh),"aria-valuemin":this.minValue,"aria-valuemax":this.maxValue})},calcViewDimensions:function(){var a=this.getDimension(this.minH);this.handleHalfDim=a/2,this.barDimension=this.getDimension(this.fullBar),this.maxPos=this.barDimension-a,this.getDimension(this.sliderElem),this.sliderElem.rzsp=this.sliderElem[0].getBoundingClientRect()[this.positionProperty],this.initHasRun&&(this.updateFloorLab(),this.updateCeilLab(),this.initHandles())},updateTicksScale:function(){if(this.options.showTicks){var a=Math.round((this.maxValue-this.minValue)/this.step)+1;this.scope.ticks=[];for(var b=0;a>b;b++){var c=this.roundStep(this.minValue+b*this.step),d={selected:this.isTickSelected(c)};d.selected&&this.options.getSelectionBarColor&&(d.style={"background-color":this.getSelectionBarColor()}),this.options.ticksTooltip&&(d.tooltip=this.options.ticksTooltip(c),d.tooltipPlacement=this.options.vertical?"right":"top"),this.options.showTicksValues&&(d.value=this.getDisplayValue(c),this.options.ticksValuesTooltip&&(d.valueTooltip=this.options.ticksValuesTooltip(c),d.valueTooltipPlacement=this.options.vertical?"right":"top")),this.scope.ticks.push(d)}}},isTickSelected:function(a){return!this.range&&this.options.showSelectionBar&&a<=this.scope.rzSliderModel?!0:this.range&&a>=this.scope.rzSliderModel&&a<=this.scope.rzSliderHigh?!0:!1},updateCeilLab:function(){this.translateFn(this.maxValue,this.ceilLab),this.setPosition(this.ceilLab,this.barDimension-this.ceilLab.rzsd),this.getDimension(this.ceilLab)},updateFloorLab:function(){this.translateFn(this.minValue,this.flrLab),this.getDimension(this.flrLab)},callOnStart:function(){if(this.options.onStart){var a=this;this.scope.$evalAsync(function(){a.options.onStart(a.options.id,a.scope.rzSliderModel,a.scope.rzSliderHigh)})}},callOnChange:function(){if(this.options.onChange){var a=this;this.scope.$evalAsync(function(){a.options.onChange(a.options.id,a.scope.rzSliderModel,a.scope.rzSliderHigh)})}},callOnEnd:function(){if(this.options.onEnd){var a=this;this.scope.$evalAsync(function(){a.options.onEnd(a.options.id,a.scope.rzSliderModel,a.scope.rzSliderHigh)})}},updateHandles:function(a,b){"rzSliderModel"===a?this.updateLowHandle(b):this.updateHighHandle(b),this.updateSelectionBar(),this.updateTicksScale(),this.range&&this.updateCmbLabel()},updateLowHandle:function(a){this.setPosition(this.minH,a),this.translateFn(this.scope.rzSliderModel,this.minLab);var b=Math.min(Math.max(a-this.minLab.rzsd/2+this.handleHalfDim,0),this.barDimension-this.ceilLab.rzsd);this.setPosition(this.minLab,b),this.shFloorCeil()},updateHighHandle:function(a){this.setPosition(this.maxH,a),this.translateFn(this.scope.rzSliderHigh,this.maxLab);var b=Math.min(a-this.maxLab.rzsd/2+this.handleHalfDim,this.barDimension-this.ceilLab.rzsd);this.setPosition(this.maxLab,b),this.shFloorCeil()},shFloorCeil:function(){var a=!1,b=!1;this.minLab.rzsp<=this.flrLab.rzsp+this.flrLab.rzsd+5?(a=!0,this.hideEl(this.flrLab)):(a=!1,this.showEl(this.flrLab)),this.minLab.rzsp+this.minLab.rzsd>=this.ceilLab.rzsp-this.handleHalfDim-10?(b=!0,this.hideEl(this.ceilLab)):(b=!1,this.showEl(this.ceilLab)),this.range&&(this.maxLab.rzsp+this.maxLab.rzsd>=this.ceilLab.rzsp-10?this.hideEl(this.ceilLab):b||this.showEl(this.ceilLab),this.maxLab.rzsp<=this.flrLab.rzsp+this.flrLab.rzsd+this.handleHalfDim?this.hideEl(this.flrLab):a||this.showEl(this.flrLab))},updateSelectionBar:function(){var a=0,b=0;if(this.range||!this.options.showSelectionBarEnd?(b=Math.abs(this.maxH.rzsp-this.minH.rzsp)+this.handleHalfDim,a=this.range?this.minH.rzsp+this.handleHalfDim:0):(b=Math.abs(this.maxPos-this.minH.rzsp)+this.handleHalfDim,a=this.minH.rzsp+this.handleHalfDim),this.setDimension(this.selBar,b),this.setPosition(this.selBar,a),this.options.getSelectionBarColor){var c=this.getSelectionBarColor();this.scope.barStyle={backgroundColor:c}}},getSelectionBarColor:function(){return this.range?this.options.getSelectionBarColor(this.scope.rzSliderModel,this.scope.rzSliderHigh):this.options.getSelectionBarColor(this.scope.rzSliderModel)},updateCmbLabel:function(){var a,b;if(this.minLab.rzsp+this.minLab.rzsd+10>=this.maxLab.rzsp){a=this.getDisplayValue(this.scope.rzSliderModel),b=this.getDisplayValue(this.scope.rzSliderHigh),this.translateFn(a+" - "+b,this.cmbLab,!1);var c=Math.min(Math.max(this.selBar.rzsp+this.selBar.rzsd/2-this.cmbLab.rzsd/2,0),this.barDimension-this.cmbLab.rzsd);this.setPosition(this.cmbLab,c),this.hideEl(this.minLab),this.hideEl(this.maxLab),this.showEl(this.cmbLab)}else this.showEl(this.maxLab),this.showEl(this.minLab),this.hideEl(this.cmbLab)},getDisplayValue:function(a){return this.customTrFn(a,this.options.id)},roundStep:function(a){var b=parseFloat((a-this.minValue)/this.step).toPrecision(12);b=Math.round(+b)*this.step;var c=(this.minValue+ +b).toFixed(this.precision);return+c},hideEl:function(a){return a.css({opacity:0})},showEl:function(a){return a.rzAlwaysHide?a:a.css({opacity:1})},setPosition:function(a,b){a.rzsp=b;var c={};return c[this.positionProperty]=b+"px",a.css(c),b},getDimension:function(a){var b=a[0].getBoundingClientRect();return this.options.vertical?a.rzsd=(b.bottom-b.top)*this.options.scale:a.rzsd=(b.right-b.left)*this.options.scale,a.rzsd},setDimension:function(a,b){a.rzsd=b;var c={};return c[this.dimensionProperty]=b+"px",a.css(c),b},valueToOffset:function(a){return(this.sanitizeValue(a)-this.minValue)*this.maxPos/this.valueRange||0},sanitizeValue:function(a){return Math.min(Math.max(a,this.minValue),this.maxValue)},offsetToValue:function(a){return a/this.maxPos*this.valueRange+this.minValue},getEventXY:function(a){var b=this.options.vertical?"clientY":"clientX";return b in a?a[b]:void 0===a.originalEvent?a.touches[0][b]:a.originalEvent.touches[0][b]},getEventPosition:function(a){var b=this.sliderElem.rzsp,c=0;return c=this.options.vertical?-this.getEventXY(a)+b:this.getEventXY(a)-b,(c-this.handleHalfDim)*this.options.scale},getEventNames:function(a){var b={moveEvent:"",endEvent:""};return a.touches||void 0!==a.originalEvent&&a.originalEvent.touches?(b.moveEvent="touchmove",b.endEvent="touchend"):(b.moveEvent="mousemove",b.endEvent="mouseup"),b},getNearestHandle:function(a){if(!this.range)return this.minH;var b=this.getEventPosition(a),c=Math.abs(b-this.minH.rzsp),d=Math.abs(b-this.maxH.rzsp);return d>c?this.minH:c>d?this.maxH:b=d?c=this.minValue:d>=this.maxPos?c=this.maxValue:(c=this.offsetToValue(d),c=this.roundStep(c)),this.positionTrackingHandle(c)},onEnd:function(a,b){var d=this.getEventNames(b).moveEvent;this.options.keyboardSupport||(this.minH.removeClass("rz-active"),this.maxH.removeClass("rz-active"),this.tracking=""),this.dragging.active=!1,c.off(d,a),this.scope.$emit("slideEnded"),this.callOnEnd()},onPointerFocus:function(b,c){this.tracking=c,b.one("blur",a.bind(this,this.onPointerBlur,b)),b.on("keydown",a.bind(this,this.onKeyboardEvent)),b.addClass("rz-active")},onPointerBlur:function(a){a.off("keydown"),this.tracking="",a.removeClass("rz-active")},onKeyboardEvent:function(a){var b=this.scope[this.tracking],c=a.keyCode||a.which,d={38:"UP",40:"DOWN",37:"LEFT",39:"RIGHT",33:"PAGEUP",34:"PAGEDOWN",36:"HOME",35:"END"},e={UP:b+this.step,DOWN:b-this.step,LEFT:b-this.step,RIGHT:b+this.step,PAGEUP:b+this.valueRange/10,PAGEDOWN:b-this.valueRange/10,HOME:this.minValue,END:this.maxValue},f=d[c],g=e[f];if(null!=g&&""!==this.tracking){a.preventDefault();var h=this.roundStep(this.sanitizeValue(g));if(this.options.draggableRangeOnly){var i,j,k=this.scope.rzSliderHigh-this.scope.rzSliderModel;"rzSliderModel"===this.tracking?(i=h,j=h+k,j>this.maxValue&&(j=this.maxValue,i=j-k)):(j=h,i=h-k,i=this.maxPos-this.dragging.highLimit){if(this.maxH.rzsp===this.maxPos)return;d=this.maxValue,c=this.maxValue-this.dragging.difference}else c=this.offsetToValue(e-this.dragging.lowLimit),c=this.roundStep(c),d=c+this.dragging.difference;this.positionTrackingBar(c,d)},positionTrackingBar:function(a,b){this.scope.rzSliderModel=a,this.scope.rzSliderHigh=b,this.updateHandles("rzSliderModel",this.valueToOffset(a)),this.updateHandles("rzSliderHigh",this.valueToOffset(b)),this.applyModel()},positionTrackingHandle:function(a){var b=!1;this.range&&(a=this.applyMinRange(a),"rzSliderModel"===this.tracking&&a>this.scope.rzSliderHigh?(this.options.noSwitching&&this.scope.rzSliderHigh!==this.minValue?a=this.applyMinRange(this.scope.rzSliderHigh):(this.scope[this.tracking]=this.scope.rzSliderHigh,this.updateHandles(this.tracking,this.maxH.rzsp),this.updateAriaAttributes(),this.tracking="rzSliderHigh",this.minH.removeClass("rz-active"),this.maxH.addClass("rz-active"),this.options.keyboardSupport&&this.focusElement(this.maxH)),b=!0):"rzSliderHigh"===this.tracking&&a ')}]),b});
\ No newline at end of file
diff --git a/src/rzslider.js b/src/rzslider.js
index 3bc7db2..49bdaf5 100644
--- a/src/rzslider.js
+++ b/src/rzslider.js
@@ -56,6 +56,7 @@
keyboardSupport: true,
scale: 1,
enforceRange: false,
+ noSwitching: false,
onlyBindHandles: false,
onStart: null,
onChange: null,
@@ -847,7 +848,7 @@
updateHandles: function(which, newOffset) {
if (which === 'rzSliderModel')
this.updateLowHandle(newOffset);
- else if (which === 'rzSliderHigh')
+ else
this.updateHighHandle(newOffset);
this.updateSelectionBar();
@@ -887,7 +888,7 @@
},
/**
- * Show / hide floor / ceiling label
+ * Show/hide floor/ceiling label
*
* @returns {undefined}
*/
@@ -1181,8 +1182,15 @@
if (!this.range) {
return this.minH;
}
- var offset = this.getEventPosition(event);
- return Math.abs(offset - this.minH.rzsp) < Math.abs(offset - this.maxH.rzsp) ? this.minH : this.maxH;
+ var offset = this.getEventPosition(event),
+ distanceMin = Math.abs(offset - this.minH.rzsp),
+ distanceMax = Math.abs(offset - this.maxH.rzsp);
+ if (distanceMin < distanceMax)
+ return this.minH;
+ else if (distanceMin > distanceMax)
+ return this.maxH;
+ else //if event is at the same distance from min/max then if it's at left of minH, we return minH else maxH
+ return offset < this.minH.rzsp ? this.minH : this.maxH;
},
/**
@@ -1326,21 +1334,14 @@
newValue;
if (newOffset <= 0) {
- if (pointer.rzsp === 0)
- return;
newValue = this.minValue;
- newOffset = 0;
} else if (newOffset >= this.maxPos) {
- if (pointer.rzsp === this.maxPos)
- return;
newValue = this.maxValue;
- newOffset = this.maxPos;
} else {
newValue = this.offsetToValue(newOffset);
newValue = this.roundStep(newValue);
- newOffset = this.valueToOffset(newValue);
}
- this.positionTrackingHandle(newValue, newOffset);
+ this.positionTrackingHandle(newValue);
},
/**
@@ -1406,36 +1407,28 @@
if (action == null || this.tracking === '') return;
event.preventDefault();
- var newValue = this.roundStep(this.sanitizeValue(action)),
- newOffset = this.valueToOffset(newValue);
+ var newValue = this.roundStep(this.sanitizeValue(action));
if (!this.options.draggableRangeOnly) {
- this.positionTrackingHandle(newValue, newOffset);
+ this.positionTrackingHandle(newValue);
} else {
var difference = this.scope.rzSliderHigh - this.scope.rzSliderModel,
- newMinOffset, newMaxOffset,
newMinValue, newMaxValue;
if (this.tracking === 'rzSliderModel') {
newMinValue = newValue;
- newMinOffset = newOffset;
newMaxValue = newValue + difference;
if (newMaxValue > this.maxValue) {
newMaxValue = this.maxValue;
newMinValue = newMaxValue - difference;
- newMinOffset = this.valueToOffset(newMinValue);
}
- newMaxOffset = this.valueToOffset(newMaxValue);
} else {
newMaxValue = newValue;
- newMaxOffset = newOffset;
newMinValue = newValue - difference;
if (newMinValue < this.minValue) {
newMinValue = this.minValue;
newMaxValue = newMinValue + difference;
- newMaxOffset = this.valueToOffset(newMaxValue);
}
- newMinOffset = this.valueToOffset(newMinValue);
}
- this.positionTrackingBar(newMinValue, newMaxValue, newMinOffset, newMaxOffset);
+ this.positionTrackingBar(newMinValue, newMaxValue);
}
},
@@ -1473,32 +1466,25 @@
*/
onDragMove: function(pointer, event) {
var newOffset = this.getEventPosition(event),
- newMinOffset, newMaxOffset,
newMinValue, newMaxValue;
if (newOffset <= this.dragging.lowLimit) {
if (this.minH.rzsp === 0)
return;
newMinValue = this.minValue;
- newMinOffset = 0;
newMaxValue = this.minValue + this.dragging.difference;
- newMaxOffset = this.valueToOffset(newMaxValue);
} else if (newOffset >= this.maxPos - this.dragging.highLimit) {
if (this.maxH.rzsp === this.maxPos)
return;
newMaxValue = this.maxValue;
- newMaxOffset = this.maxPos;
newMinValue = this.maxValue - this.dragging.difference;
- newMinOffset = this.valueToOffset(newMinValue);
} else {
newMinValue = this.offsetToValue(newOffset - this.dragging.lowLimit);
newMinValue = this.roundStep(newMinValue);
- newMinOffset = this.valueToOffset(newMinValue);
newMaxValue = newMinValue + this.dragging.difference;
- newMaxOffset = this.valueToOffset(newMaxValue);
}
- this.positionTrackingBar(newMinValue, newMaxValue, newMinOffset, newMaxOffset);
+ this.positionTrackingBar(newMinValue, newMaxValue);
},
/**
@@ -1506,14 +1492,12 @@
*
* @param {number} newMinValue the new minimum value
* @param {number} newMaxValue the new maximum value
- * @param {number} newMinOffset the new minimum offset
- * @param {number} newMaxOffset the new maximum offset
*/
- positionTrackingBar: function(newMinValue, newMaxValue, newMinOffset, newMaxOffset) {
+ positionTrackingBar: function(newMinValue, newMaxValue) {
this.scope.rzSliderModel = newMinValue;
this.scope.rzSliderHigh = newMaxValue;
- this.updateHandles('rzSliderModel', newMinOffset);
- this.updateHandles('rzSliderHigh', newMaxOffset);
+ this.updateHandles('rzSliderModel', this.valueToOffset(newMinValue));
+ this.updateHandles('rzSliderHigh', this.valueToOffset(newMaxValue));
this.applyModel();
},
@@ -1521,52 +1505,55 @@
* Set the new value and offset to the current tracking handle
*
* @param {number} newValue new model value
- * @param {number} newOffset new offset value
*/
- positionTrackingHandle: function(newValue, newOffset) {
+ positionTrackingHandle: function(newValue) {
var valueChanged = false;
- var switched = false;
if (this.range) {
newValue = this.applyMinRange(newValue);
- newOffset = this.valueToOffset(newValue);
/* This is to check if we need to switch the min and max handles */
- if (this.tracking === 'rzSliderModel' && newValue >= this.scope.rzSliderHigh) {
- switched = true;
- this.scope[this.tracking] = this.scope.rzSliderHigh;
- this.updateHandles(this.tracking, this.maxH.rzsp);
- this.updateAriaAttributes();
- this.tracking = 'rzSliderHigh';
- this.minH.removeClass('rz-active');
- this.maxH.addClass('rz-active');
- if (this.options.keyboardSupport)
- this.focusElement(this.maxH);
+ if (this.tracking === 'rzSliderModel' && newValue > this.scope.rzSliderHigh) {
+ if (this.options.noSwitching && this.scope.rzSliderHigh !== this.minValue) {
+ newValue = this.applyMinRange(this.scope.rzSliderHigh);
+ }
+ else {
+ this.scope[this.tracking] = this.scope.rzSliderHigh;
+ this.updateHandles(this.tracking, this.maxH.rzsp);
+ this.updateAriaAttributes();
+ this.tracking = 'rzSliderHigh';
+ this.minH.removeClass('rz-active');
+ this.maxH.addClass('rz-active');
+ if (this.options.keyboardSupport)
+ this.focusElement(this.maxH);
+ }
valueChanged = true;
- } else if (this.tracking === 'rzSliderHigh' && newValue <= this.scope.rzSliderModel) {
- switched = true;
- this.scope[this.tracking] = this.scope.rzSliderModel;
- this.updateHandles(this.tracking, this.minH.rzsp);
- this.updateAriaAttributes();
- this.tracking = 'rzSliderModel';
- this.maxH.removeClass('rz-active');
- this.minH.addClass('rz-active');
- if (this.options.keyboardSupport)
- this.focusElement(this.minH);
+ } else if (this.tracking === 'rzSliderHigh' && newValue < this.scope.rzSliderModel) {
+ if (this.options.noSwitching && this.scope.rzSliderModel !== this.maxValue) {
+ newValue = this.applyMinRange(this.scope.rzSliderModel);
+ }
+ else {
+ this.scope[this.tracking] = this.scope.rzSliderModel;
+ this.updateHandles(this.tracking, this.minH.rzsp);
+ this.updateAriaAttributes();
+ this.tracking = 'rzSliderModel';
+ this.maxH.removeClass('rz-active');
+ this.minH.addClass('rz-active');
+ if (this.options.keyboardSupport)
+ this.focusElement(this.minH);
+ }
valueChanged = true;
}
}
if (this.scope[this.tracking] !== newValue) {
this.scope[this.tracking] = newValue;
- this.updateHandles(this.tracking, newOffset);
+ this.updateHandles(this.tracking, this.valueToOffset(newValue));
this.updateAriaAttributes();
valueChanged = true;
}
- if (valueChanged) {
+ if (valueChanged)
this.applyModel();
- }
- return switched;
},
applyMinRange: function(newValue) {
diff --git a/src/rzslider.less b/src/rzslider.less
index 67dba2b..4a9368f 100644
--- a/src/rzslider.less
+++ b/src/rzslider.less
@@ -94,8 +94,11 @@ rzslider {
&:hover:after {
background-color: @handleHoverColor;
}
- &.rz-active:after {
- background-color: @handleActiveColor;
+ &.rz-active{
+ z-index: 4;
+ &:after {
+ background-color: @handleActiveColor;
+ }
}
}
diff --git a/tests/spec/rz-slider-service-test.js b/tests/spec/rz-slider-service-test.js
index e9bbec6..82680ef 100644
--- a/tests/spec/rz-slider-service-test.js
+++ b/tests/spec/rz-slider-service-test.js
@@ -909,7 +909,7 @@ describe('rzslider - ', function() {
expect(firstTick.css('background-color')).to.equal('green');
});
- it('should set a tooltip attribute if ticksTooltip is defined', function() {
+ it('should set correct tooltip attributes if ticksTooltip is defined for a horizontal slider', function() {
var sliderConf = {
value: 50,
options: {
@@ -925,17 +925,62 @@ describe('rzslider - ', function() {
createSlider(sliderConf);
var firstTick = angular.element(element[0].querySelectorAll('.tick')[0]);
expect(firstTick.attr('uib-tooltip')).to.equal('tooltip for 0');
+ expect(firstTick.attr('tooltip-placement')).to.equal('top');
var secondTick = angular.element(element[0].querySelectorAll('.tick')[1]);
expect(secondTick.attr('uib-tooltip')).to.equal('tooltip for 10');
});
- it('should set a tooltip attribute on tick-value if ticksValuesTooltip is defined', function() {
+ it('should set correct tooltip attributes if ticksTooltip is defined for a vertical slider', function() {
var sliderConf = {
value: 50,
options: {
floor: 0,
ceil: 100,
step: 10,
+ vertical: true,
+ showTicks: true,
+ ticksTooltip: function(value) {
+ return 'tooltip for ' + value;
+ }
+ }
+ };
+ createSlider(sliderConf);
+ var firstTick = angular.element(element[0].querySelectorAll('.tick')[0]);
+ expect(firstTick.attr('uib-tooltip')).to.equal('tooltip for 0');
+ expect(firstTick.attr('tooltip-placement')).to.equal('right');
+ var secondTick = angular.element(element[0].querySelectorAll('.tick')[1]);
+ expect(secondTick.attr('uib-tooltip')).to.equal('tooltip for 10');
+ });
+
+ it('should set correct tooltip attributes on tick-value if ticksValuesTooltip is defined for a horizontal slider', function() {
+ var sliderConf = {
+ value: 50,
+ options: {
+ floor: 0,
+ ceil: 100,
+ step: 10,
+ showTicksValues: true,
+ ticksValuesTooltip: function(value) {
+ return 'tooltip for ' + value;
+ }
+ }
+ };
+ createSlider(sliderConf);
+ var firstTick = angular.element(element[0].querySelectorAll('.tick-value')[0]);
+ expect(firstTick.attr('uib-tooltip')).to.equal('tooltip for 0');
+ expect(firstTick.attr('tooltip-placement')).to.equal('top');
+ var secondTick = angular.element(element[0].querySelectorAll('.tick-value')[1]);
+ expect(secondTick.attr('uib-tooltip')).to.equal('tooltip for 10');
+ });
+
+ it('should set correct tooltip attributes on tick-value if ticksValuesTooltip is defined for a vertical slider', function() {
+ var sliderConf = {
+ value: 50,
+ options: {
+ floor: 0,
+ ceil: 100,
+ step: 10,
+ vertical: true,
showTicksValues: true,
ticksValuesTooltip: function(value) {
return 'tooltip for ' + value;
@@ -945,6 +990,7 @@ describe('rzslider - ', function() {
createSlider(sliderConf);
var firstTick = angular.element(element[0].querySelectorAll('.tick-value')[0]);
expect(firstTick.attr('uib-tooltip')).to.equal('tooltip for 0');
+ expect(firstTick.attr('tooltip-placement')).to.equal('right');
var secondTick = angular.element(element[0].querySelectorAll('.tick-value')[1]);
expect(secondTick.attr('uib-tooltip')).to.equal('tooltip for 10');
});
@@ -1656,14 +1702,6 @@ describe('rzslider - ', function() {
slider.callOnChange.called.should.be.true;
});
- it('should handle click and drag on minH correctly when mouse is before the slider and previous value was already 0', function() {
- sinon.spy(slider, 'positionTrackingHandle');
- var event = fireMousedown(slider.minH, 0);
- fireMousemove(-100);
- expect(scope.slider.value).to.equal(0);
- slider.positionTrackingHandle.called.should.be.false;
- });
-
it('should handle click and drag on minH correctly when mouse is before the slider and previous value was different than 0', function() {
scope.slider.value = 50;
scope.$digest();
@@ -1683,17 +1721,6 @@ describe('rzslider - ', function() {
slider.positionTrackingHandle.called.should.be.true;
});
- it('should handle click and drag on minH correctly when mouse is after the slider and previous value was already 100', function() {
- scope.slider.value = 100;
- scope.$digest();
-
- sinon.spy(slider, 'positionTrackingHandle');
- var event = fireMousedown(slider.minH, 0);
- fireMousemove(slider.maxPos + 100);
- expect(scope.slider.value).to.equal(100);
- slider.positionTrackingHandle.called.should.be.false;
- });
-
it('should call correct callbacks on slider end and keep handle focused when keyboardSupport is true', function() {
var event = fireMousedown(slider.minH, 0);
@@ -1731,7 +1758,7 @@ describe('rzslider - ', function() {
var expectedValue = 12,
offset = slider.valueToOffset(expectedValue) + slider.handleHalfDim + slider.sliderElem.rzsp;
- var event = fireMousedown(slider.fullBar, offset);
+ fireMousedown(slider.fullBar, offset);
expect(scope.slider.value).to.equal(expectedValue);
expect(slider.tracking).to.equal('rzSliderModel');
@@ -1880,7 +1907,7 @@ describe('rzslider - ', function() {
it('should handle click and drag on maxH correctly when mouse is on the middle', function() {
sinon.spy(slider, 'positionTrackingHandle');
sinon.spy(slider, 'callOnChange');
- var event = fireMousedown(slider.maxH, 0);
+ fireMousedown(slider.maxH, 0);
var expectedValue = 50,
offset = slider.valueToOffset(expectedValue) + slider.handleHalfDim + slider.sliderElem.rzsp;
fireMousemove(offset);
@@ -1894,13 +1921,32 @@ describe('rzslider - ', function() {
scope.slider.max = 60;
scope.$digest();
- var event = fireMousedown(slider.minH, 0);
+ sinon.spy(slider, 'focusElement');
+ fireMousedown(slider.minH, 0);
var expectedValue = 80,
offset = slider.valueToOffset(expectedValue) + slider.handleHalfDim + slider.sliderElem.rzsp;
fireMousemove(offset);
expect(scope.slider.min).to.equal(60);
expect(scope.slider.max).to.equal(80);
+ slider.focusElement.calledWith(slider.maxH).should.be.true;
+ });
+
+ it('should handle click and drag on minH and switch min/max if needed when keyboardSupport is false', function() {
+ scope.slider.options.keyboardSupport = false;
+ scope.slider.min = 40;
+ scope.slider.max = 60;
+ scope.$digest();
+
+ sinon.spy(slider, 'focusElement');
+ fireMousedown(slider.minH, 0);
+ var expectedValue = 80,
+ offset = slider.valueToOffset(expectedValue) + slider.handleHalfDim + slider.sliderElem.rzsp;
+ fireMousemove(offset);
+
+ expect(scope.slider.min).to.equal(60);
+ expect(scope.slider.max).to.equal(80);
+ slider.focusElement.called.should.be.false;
});
it('should handle click and drag on maxH and switch min/max if needed', function() {
@@ -1908,13 +1954,32 @@ describe('rzslider - ', function() {
scope.slider.max = 60;
scope.$digest();
- var event = fireMousedown(slider.maxH, 0);
+ sinon.spy(slider, 'focusElement');
+ fireMousedown(slider.maxH, 0);
var expectedValue = 20,
offset = slider.valueToOffset(expectedValue) + slider.handleHalfDim + slider.sliderElem.rzsp;
fireMousemove(offset);
expect(scope.slider.min).to.equal(20);
expect(scope.slider.max).to.equal(40);
+ slider.focusElement.calledWith(slider.minH).should.be.true;
+ });
+
+ it('should handle click and drag on maxH and switch min/max if needed when keyboardSupport is false', function() {
+ scope.slider.options.keyboardSupport = false;
+ scope.slider.min = 40;
+ scope.slider.max = 60;
+ scope.$digest();
+
+ sinon.spy(slider, 'focusElement');
+ fireMousedown(slider.maxH, 0);
+ var expectedValue = 20,
+ offset = slider.valueToOffset(expectedValue) + slider.handleHalfDim + slider.sliderElem.rzsp;
+ fireMousemove(offset);
+
+ expect(scope.slider.min).to.equal(20);
+ expect(scope.slider.max).to.equal(40);
+ slider.focusElement.called.should.be.false;
});
it('should handle click on fullbar and move minH when click pos is nearer to minH', function() {
@@ -2060,14 +2125,6 @@ describe('rzslider - ', function() {
slider.callOnChange.called.should.be.true;
});
- it('should handle click and drag on minH correctly when mouse is before the slider and previous value was already 0', function() {
- sinon.spy(slider, 'positionTrackingHandle');
- fireMousedown(slider.minH, 0, true);
- fireMousemove(slider.maxPos + 100, true);
- expect(scope.slider.value).to.equal(0);
- slider.positionTrackingHandle.called.should.be.false;
- });
-
it('should handle click and drag on minH correctly when mouse is before the slider and previous value was different than 0', function() {
scope.slider.value = 50;
scope.$digest();
@@ -2087,17 +2144,6 @@ describe('rzslider - ', function() {
slider.positionTrackingHandle.called.should.be.true;
});
- it('should handle click and drag on minH correctly when mouse is after the slider and previous value was already 100', function() {
- scope.slider.value = 100;
- scope.$digest();
-
- sinon.spy(slider, 'positionTrackingHandle');
- var event = fireMousedown(slider.minH, 0, true);
- fireMousemove(-100, true);
- expect(scope.slider.value).to.equal(100);
- slider.positionTrackingHandle.called.should.be.false;
- });
-
it('should call correct callbacks on slider end and keep handle focused when keyboardSupport is true', function() {
var event = fireMousedown(slider.minH, 0, true);
@@ -2756,7 +2802,7 @@ describe('rzslider - ', function() {
});
});
- describe('single horizontal slider with onlyBindHandles - ', function() {
+ describe('range horizontal slider with minRange!=0 - ', function() {
beforeEach(function() {
var sliderConf = {
min: 45,
@@ -2805,8 +2851,156 @@ describe('rzslider - ', function() {
fireMousemove(offset);
expect(scope.slider.max).to.equal(expectedValue);
});
+
+ it('should modify the min value if switch min/max with a value large enough', function() {
+ fireMousedown(slider.minH, 0);
+ var expectedValue = 80,
+ offset = slider.valueToOffset(expectedValue) + slider.handleHalfDim + slider.sliderElem.rzsp;
+ fireMousemove(offset);
+ expect(scope.slider.min).to.equal(55);
+ expect(scope.slider.max).to.equal(expectedValue);
+ });
+
+ it('should modify the max value if switch min/max with a value large enough', function() {
+ fireMousedown(slider.maxH, 0);
+ var expectedValue = 20,
+ offset = slider.valueToOffset(expectedValue) + slider.handleHalfDim + slider.sliderElem.rzsp;
+ fireMousemove(offset);
+ expect(scope.slider.min).to.equal(expectedValue);
+ expect(scope.slider.max).to.equal(45);
+ });
+ });
+
+ describe('range horizontal slider with noSwitching - ', function() {
+ beforeEach(function() {
+ var sliderConf = {
+ min: 45,
+ max: 55,
+ options: {
+ floor: 0,
+ ceil: 100,
+ noSwitching: true
+ }
+ };
+ createRangeSlider(sliderConf);
+ });
+ afterEach(function() {
+ // to clean document listener
+ fireMouseup();
+ });
+
+ it('should not switch min and max handles if minH is dragged after maxH', function() {
+ fireMousedown(slider.minH, 0);
+ var expectedValue = 60,
+ offset = slider.valueToOffset(expectedValue) + slider.handleHalfDim + slider.sliderElem.rzsp;
+ fireMousemove(offset);
+ expect(scope.slider.min).to.equal(55);
+ });
+
+ it('should not switch min and max handles if maxH is dragged before minH', function() {
+ fireMousedown(slider.maxH, 0);
+ var expectedValue = 20,
+ offset = slider.valueToOffset(expectedValue) + slider.handleHalfDim + slider.sliderElem.rzsp;
+ fireMousemove(offset);
+ expect(scope.slider.max).to.equal(45);
+ });
+
+ it('should move minH if minH==maxH and click is on the left side of the bar', function() {
+ scope.slider.min = scope.slider.max = 50;
+ scope.$digest();
+
+ var expectedValue = 30,
+ offset = slider.valueToOffset(expectedValue) + slider.handleHalfDim + slider.sliderElem.rzsp;
+
+ fireMousedown(slider.fullBar, offset);
+
+ expect(scope.slider.min).to.equal(30);
+ expect(scope.slider.max).to.equal(50);
+ });
+
+ it('should move maxH if minH==maxH and click is on the right side of the bar', function() {
+ scope.slider.min = scope.slider.max = 50;
+ scope.$digest();
+
+ var expectedValue = 70,
+ offset = slider.valueToOffset(expectedValue) + slider.handleHalfDim + slider.sliderElem.rzsp;
+
+ fireMousedown(slider.fullBar, offset);
+
+ expect(scope.slider.min).to.equal(50);
+ expect(scope.slider.max).to.equal(70);
+ });
});
+ describe('range horizontal slider with minRange!=0 and noSwitching - ', function() {
+ beforeEach(function() {
+ var sliderConf = {
+ min: 45,
+ max: 55,
+ options: {
+ floor: 0,
+ ceil: 100,
+ minRange: 10,
+ noSwitching: true
+ }
+ };
+ createRangeSlider(sliderConf);
+ });
+ afterEach(function() {
+ // to clean document listener
+ fireMouseup();
+ });
+
+ it('should not modify any value if new range would be smaller than minRange when moving minH', function() {
+ fireMousedown(slider.minH, 0);
+ var expectedValue = 50,
+ offset = slider.valueToOffset(expectedValue) + slider.handleHalfDim + slider.sliderElem.rzsp;
+ fireMousemove(offset);
+ expect(scope.slider.min).to.equal(45);
+ });
+
+ it('should not modify any value if new range would be smaller than minRange when moving maxH', function() {
+ fireMousedown(slider.maxH, 0);
+ var expectedValue = 50,
+ offset = slider.valueToOffset(expectedValue) + slider.handleHalfDim + slider.sliderElem.rzsp;
+ fireMousemove(offset);
+ expect(scope.slider.max).to.equal(55);
+ });
+
+ it('should modify the min value if new range is larger than minRange when moving minH', function() {
+ fireMousedown(slider.minH, 0);
+ var expectedValue = 30,
+ offset = slider.valueToOffset(expectedValue) + slider.handleHalfDim + slider.sliderElem.rzsp;
+ fireMousemove(offset);
+ expect(scope.slider.min).to.equal(expectedValue);
+ });
+
+ it('should modify the max value if new range is larger than than minRange when moving maxH', function() {
+ fireMousedown(slider.maxH, 0);
+ var expectedValue = 70,
+ offset = slider.valueToOffset(expectedValue) + slider.handleHalfDim + slider.sliderElem.rzsp;
+ fireMousemove(offset);
+ expect(scope.slider.max).to.equal(expectedValue);
+ });
+
+ it('should not switch min/max when moving minH even if the range is large enough', function() {
+ fireMousedown(slider.minH, 0);
+ var expectedValue = 80,
+ offset = slider.valueToOffset(expectedValue) + slider.handleHalfDim + slider.sliderElem.rzsp;
+ fireMousemove(offset);
+ expect(scope.slider.min).to.equal(45);
+ expect(scope.slider.max).to.equal(55);
+ });
+
+ it('should not switch min/max when moving maxH even if the range is large enough', function() {
+ fireMousedown(slider.maxH, 0);
+ var expectedValue = 20,
+ offset = slider.valueToOffset(expectedValue) + slider.handleHalfDim + slider.sliderElem.rzsp;
+ fireMousemove(offset);
+ expect(scope.slider.min).to.equal(45);
+ expect(scope.slider.max).to.equal(55);
+ });
+ });
});
/*
@@ -2841,6 +3035,12 @@ describe('rzslider - ', function() {
expect(scope.slider.value).to.equal(101);
});
+ it('should increment by 1 when RIGHT is pressed with oldAPI', function() {
+ slider.minH.triggerHandler('focus');
+ pressKeydown(slider.minH, 'RIGHT', true);
+ expect(scope.slider.value).to.equal(101);
+ });
+
it('should decrement by 1 when LEFT is pressed', function() {
slider.minH.triggerHandler('focus');
pressKeydown(slider.minH, 'LEFT');
@@ -3323,7 +3523,7 @@ describe('rzslider - ', function() {
};
var keyCode = keys[key];
if (oldAPI)
- eent.which = keyCode;
+ event.which = keyCode;
else event.keyCode = keyCode;
element.triggerHandler(event);
}