From f23909fef79cac9c48628b744163848124756ce7 Mon Sep 17 00:00:00 2001 From: Valentin Hervieu Date: Thu, 25 Feb 2016 19:24:24 +0100 Subject: [PATCH 1/3] feat(logScale): Implement a logScale option to display sliders with logarithmic scale --- demo/demo.js | 10 ++++++++++ demo/index.html | 8 ++++++++ src/rzslider.js | 32 ++++++++++++++++++++++++++------ 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/demo/demo.js b/demo/demo.js index 5fe680a..30c9646 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -137,6 +137,16 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) { } }; + //Slider config with logarithmic scale + $scope.slider_log = { + value: 1, + options: { + floor: 1, + ceil: 100, + logScale: true + } + }; + //Right to left slider with floor, ceil and step $scope.slider_floor_ceil_rtl = { value: 12, diff --git a/demo/index.html b/demo/index.html index 8bd87af..fbe9ca3 100644 --- a/demo/index.html +++ b/demo/index.html @@ -119,6 +119,14 @@

Slider with custom floor/ceil/step

> +
+

Slider with logarithmic scale

+ +
+

Right to left slider with custom floor/ceil/step

Date: Fri, 7 Oct 2016 09:39:45 +0200 Subject: [PATCH 2/3] Add rtl support --- dist/rzslider.js | 32 ++++++++++++++++++++++-------- dist/rzslider.min.js | 2 +- src/rzslider.js | 46 ++++++++++++++++++++------------------------ 3 files changed, 46 insertions(+), 34 deletions(-) diff --git a/dist/rzslider.js b/dist/rzslider.js index d1dbbb8..0340f19 100644 --- a/dist/rzslider.js +++ b/dist/rzslider.js @@ -62,6 +62,7 @@ getTickColor: null, getPointerColor: null, keyboardSupport: true, + logScale: false, scale: 1, enforceStep: true, enforceRange: false, @@ -832,6 +833,8 @@ this.precision = +this.options.precision; this.minValue = this.options.floor; + if (this.options.logScale && this.minValue === 0) + throw new Error("Can't use floor=0 with logarithmic scale"); if (this.options.enforceStep) { this.lowValue = this.roundStep(this.lowValue); @@ -1425,10 +1428,17 @@ * @returns {number} */ valueToOffset: function(val) { - if (this.options.rightToLeft) { - return (this.maxValue - this.sanitizeValue(val)) * this.maxPos / this.valueRange || 0; - } - return (this.sanitizeValue(val) - this.minValue) * this.maxPos / this.valueRange || 0; + var sanitizedValue = this.sanitizeValue(val), + minValue = this.options.logScale ? Math.log(this.minValue) : this.minValue, + maxValue = this.options.logScale ? Math.log(this.maxValue) : this.maxValue, + range = maxValue - minValue; + + if (this.options.logScale) + sanitizedValue = Math.log(sanitizedValue); + + if (this.options.rightToLeft) + return (maxValue - sanitizedValue) * this.maxPos / range || 0; + return (sanitizedValue - minValue) * this.maxPos / range || 0; }, /** @@ -1448,10 +1458,16 @@ * @returns {number} */ offsetToValue: function(offset) { - if (this.options.rightToLeft) { - return (1 - (offset / this.maxPos)) * this.valueRange + this.minValue; - } - return (offset / this.maxPos) * this.valueRange + this.minValue; + var minValue = this.options.logScale ? Math.log(this.minValue) : this.minValue, + maxValue = this.options.logScale ? Math.log(this.maxValue) : this.maxValue, + range = maxValue - minValue, + value = 0; + if (this.options.rightToLeft) + value = (1 - offset / this.maxPos) * range + minValue; + else + value = offset / this.maxPos * range + minValue; + + return this.options.logScale ? Math.exp(value) : value; }, // Events diff --git a/dist/rzslider.min.js b/dist/rzslider.min.js index e515100..e684c2b 100644 --- a/dist/rzslider.min.js +++ b/dist/rzslider.min.js @@ -1,2 +1,2 @@ /*! angularjs-slider - v5.6.0 - (c) Rafal Zajac , Valentin Hervieu , Jussi Saarivirta , Angelin Sirbu - https://github.com/angular-slider/angularjs-slider - 2016-10-16 */ -!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:null,maxRange:null,pushRange:!1,minLimit:null,maxLimit:null,id:null,translate:null,getLegend:null,stepsArray:null,bindIndexForStepsArray:!1,draggableRange:!1,draggableRangeOnly:!1,showSelectionBar:!1,showSelectionBarEnd:!1,showSelectionBarFromValue:null,hidePointerLabels:!1,hideLimitLabels:!1,autoHideLimitLabels:!0,readOnly:!1,disabled:!1,interval:350,showTicks:!1,showTicksValues:!1,ticksArray:null,ticksTooltip:null,ticksValuesTooltip:null,vertical:!1,getSelectionBarColor:null,getTickColor:null,getPointerColor:null,keyboardSupport:!0,scale:1,enforceStep:!0,enforceRange:!1,noSwitching:!1,onlyBindHandles:!1,onStart:null,onChange:null,onEnd:null,rightToLeft:!1,boundPointerLabels:!0,mergeRangeLabelsIfSame:!1,customTemplateScope: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.lowValue=0,this.highValue=0,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.intermediateTicks=!1,this.initHasRun=!1,this.firstKeyDown=!1,this.internalChange=!1,this.cmbLabelShown=!1,this.currentFocusElement=null,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.syncLowValue(),this.range&&this.syncHighValue(),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.syncLowValue(),e.range&&e.syncHighValue(),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),e.currentFocusElement=null})},findStepIndex:function(b){for(var c=0,d=0;d0&&0===b.rzsd)&&(f=!0,b.rzsv=e),g||b.html(e),this.scope[c+"Label"]=e,f&&this.getDimension(b)},setMinAndMax:function(){this.step=+this.options.step,this.precision=+this.options.precision,this.minValue=this.options.floor,this.options.enforceStep&&(this.lowValue=this.roundStep(this.lowValue),this.range&&(this.highValue=this.roundStep(this.highValue))),null!=this.options.ceil?this.maxValue=this.options.ceil:this.maxValue=this.options.ceil=this.range?this.highValue:this.lowValue,this.options.enforceRange&&(this.lowValue=this.sanitizeValue(this.lowValue),this.range&&(this.highValue=this.sanitizeValue(this.highValue))),this.applyLowValue(),this.range&&this.applyHighValue(),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,this.options.id,"model"),"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,this.options.id,"high"),"aria-valuemin":this.minValue,"aria-valuemax":this.maxValue})},calcViewDimensions:function(){var a=this.getDimension(this.minH);if(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();var c=this;b(function(){c.updateTicksScale()})}},updateTicksScale:function(){if(this.options.showTicks){var a=this.options.ticksArray||this.getTicksArray(),b=this.options.vertical?"translateY":"translateX",c=this;this.options.rightToLeft&&a.reverse(),this.scope.ticks=a.map(function(a){var d=c.valueToOffset(a);c.options.vertical&&(d=c.maxPos-d);var e={selected:c.isTickSelected(a),style:{transform:b+"("+d+"px)"}};if(e.selected&&c.options.getSelectionBarColor&&(e.style["background-color"]=c.getSelectionBarColor()),!e.selected&&c.options.getTickColor&&(e.style["background-color"]=c.getTickColor(a)),c.options.ticksTooltip&&(e.tooltip=c.options.ticksTooltip(a),e.tooltipPlacement=c.options.vertical?"right":"top"),c.options.showTicksValues&&(e.value=c.getDisplayValue(a,"tick-value"),c.options.ticksValuesTooltip&&(e.valueTooltip=c.options.ticksValuesTooltip(a),e.valueTooltipPlacement=c.options.vertical?"right":"top")),c.getLegend){var f=c.getLegend(a,c.options.id);f&&(e.legend=f)}return e})}},getTicksArray:function(){var a=this.step,b=[];this.intermediateTicks&&(a=this.options.showTicks);for(var c=this.minValue;c<=this.maxValue;c+=a)b.push(c);return b},isTickSelected:function(a){if(!this.range)if(null!==this.options.showSelectionBarFromValue){var b=this.options.showSelectionBarFromValue;if(this.lowValue>b&&a>=b&&a<=this.lowValue)return!0;if(this.lowValue=a&&a>=this.lowValue)return!0}else if(this.options.showSelectionBarEnd){if(a>=this.lowValue)return!0}else if(this.options.showSelectionBar&&a<=this.lowValue)return!0;return this.range&&a>=this.lowValue&&a<=this.highValue?!0:!1},updateFloorLab:function(){this.translateFn(this.minValue,this.flrLab,"floor"),this.getDimension(this.flrLab);var a=this.options.rightToLeft?this.barDimension-this.flrLab.rzsd:0;this.setPosition(this.flrLab,a)},updateCeilLab:function(){this.translateFn(this.maxValue,this.ceilLab,"ceil"),this.getDimension(this.ceilLab);var a=this.options.rightToLeft?0:this.barDimension-this.ceilLab.rzsd;this.setPosition(this.ceilLab,a)},updateHandles:function(a,b){"lowValue"===a?this.updateLowHandle(b):this.updateHighHandle(b),this.updateSelectionBar(),this.updateTicksScale(),this.range&&this.updateCmbLabel()},getHandleLabelPos:function(a,b){var c=this[a].rzsd,d=b-c/2+this.handleHalfDim,e=this.barDimension-c;return this.options.boundPointerLabels?this.options.rightToLeft&&"minLab"===a||!this.options.rightToLeft&&"maxLab"===a?Math.min(d,e):Math.min(Math.max(d,0),e):d},updateLowHandle:function(a){if(this.setPosition(this.minH,a),this.translateFn(this.lowValue,this.minLab,"model"),this.setPosition(this.minLab,this.getHandleLabelPos("minLab",a)),this.options.getPointerColor){var b=this.getPointerColor("min");this.scope.minPointerStyle={backgroundColor:b}}this.options.autoHideLimitLabels&&this.shFloorCeil()},updateHighHandle:function(a){if(this.setPosition(this.maxH,a),this.translateFn(this.highValue,this.maxLab,"high"),this.setPosition(this.maxLab,this.getHandleLabelPos("maxLab",a)),this.options.getPointerColor){var b=this.getPointerColor("max");this.scope.maxPointerStyle={backgroundColor:b}}this.options.autoHideLimitLabels&&this.shFloorCeil()},shFloorCeil:function(){if(!this.options.hidePointerLabels){var a=!1,b=!1,c=this.options.rightToLeft,d=this.flrLab.rzsp,e=this.flrLab.rzsd,f=this.minLab.rzsp,g=this.minLab.rzsd,h=this.maxLab.rzsp,i=this.maxLab.rzsd,j=this.cmbLab.rzsp,k=this.cmbLab.rzsd,l=this.ceilLab.rzsp,m=this.handleHalfDim,n=c?f+g>=d-e-5:d+e+5>=f,o=c?l+m+10>=f-g:f+g>=l-m-10,p=c?l+10>=h-i:h+i>=l-10,q=c?j>=d-e-m:d+e+m>=j,r=c?l+10>=j-k:j+k>=l-10;if(n?(a=!0,this.hideEl(this.flrLab)):(a=!1,this.showEl(this.flrLab)),o?(b=!0,this.hideEl(this.ceilLab)):(b=!1,this.showEl(this.ceilLab)),this.range){var s=this.cmbLabelShown?r:p,t=this.cmbLabelShown?q:n;s?this.hideEl(this.ceilLab):b||this.showEl(this.ceilLab),t?this.hideEl(this.flrLab):a||this.showEl(this.flrLab)}}},updateSelectionBar:function(){var a=0,b=0,c=this.options.rightToLeft?!this.options.showSelectionBarEnd:this.options.showSelectionBarEnd,d=this.options.rightToLeft?this.maxH.rzsp+this.handleHalfDim:this.minH.rzsp+this.handleHalfDim;if(this.range)b=Math.abs(this.maxH.rzsp-this.minH.rzsp),a=d;else if(null!==this.options.showSelectionBarFromValue){var e=this.options.showSelectionBarFromValue,f=this.valueToOffset(e),g=this.options.rightToLeft?this.lowValue<=e:this.lowValue>e;g?(b=this.minH.rzsp-f,a=f+this.handleHalfDim):(b=f-this.minH.rzsp,a=this.minH.rzsp+this.handleHalfDim)}else c?(b=Math.abs(this.maxPos-this.minH.rzsp)+this.handleHalfDim,a=this.minH.rzsp+this.handleHalfDim):(b=Math.abs(this.maxH.rzsp-this.minH.rzsp)+this.handleHalfDim,a=0);if(this.setDimension(this.selBar,b),this.setPosition(this.selBar,a),this.options.getSelectionBarColor){var h=this.getSelectionBarColor();this.scope.barStyle={backgroundColor:h}}},getSelectionBarColor:function(){return this.range?this.options.getSelectionBarColor(this.scope.rzSliderModel,this.scope.rzSliderHigh):this.options.getSelectionBarColor(this.scope.rzSliderModel)},getPointerColor:function(a){return"max"===a?this.options.getPointerColor(this.scope.rzSliderHigh,a):this.options.getPointerColor(this.scope.rzSliderModel,a)},getTickColor:function(a){return this.options.getTickColor(a)},updateCmbLabel:function(){var a=null;if(a=this.options.rightToLeft?this.minLab.rzsp-this.minLab.rzsd-10<=this.maxLab.rzsp:this.minLab.rzsp+this.minLab.rzsd+10>=this.maxLab.rzsp){var b=this.getDisplayValue(this.lowValue,"model"),c=this.getDisplayValue(this.highValue,"high"),d="";d=this.options.mergeRangeLabelsIfSame&&b===c?b:this.options.rightToLeft?c+" - "+b:b+" - "+c,this.translateFn(d,this.cmbLab,"cmb",!1);var e=this.options.boundPointerLabels?Math.min(Math.max(this.selBar.rzsp+this.selBar.rzsd/2-this.cmbLab.rzsd/2,0),this.barDimension-this.cmbLab.rzsd):this.selBar.rzsp+this.selBar.rzsd/2-this.cmbLab.rzsd/2;this.setPosition(this.cmbLab,e),this.cmbLabelShown=!0,this.hideEl(this.minLab),this.hideEl(this.maxLab),this.showEl(this.cmbLab)}else this.cmbLabelShown=!1,this.showEl(this.maxLab),this.showEl(this.minLab),this.hideEl(this.cmbLab)},getDisplayValue:function(a,b){return this.options.stepsArray&&!this.options.bindIndexForStepsArray&&(a=this.getStepValue(a)),this.customTrFn(a,this.options.id,b)},roundStep:function(a,b){var c=b?b:this.step,d=parseFloat((a-this.minValue)/c).toPrecision(12);d=Math.round(+d)*c;var e=(this.minValue+d).toFixed(this.precision);return+e},hideEl:function(a){return a.css({visibility:"hidden"})},showEl:function(a){return a.rzAlwaysHide?a:a.css({visibility:"visible"})},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.options.rightToLeft?(this.maxValue-this.sanitizeValue(a))*this.maxPos/this.valueRange||0:(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 this.options.rightToLeft?(1-a/this.maxPos)*this.valueRange+this.minValue:a/this.maxPos*this.valueRange+this.minValue},getEventXY:function(a){var b=this.options.vertical?"clientY":"clientX";return void 0!==a[b]?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:this.options.rightToLeft?b>this.minH.rzsp?this.minH:this.maxH:b=f?e=h:f>=this.maxPos?e=g:(e=this.offsetToValue(f),e=d&&a.isNumber(this.options.showTicks)?this.roundStep(e,this.options.showTicks):this.roundStep(e)),this.positionTrackingHandle(e)},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.callOnEnd()},onTickClick:function(a,b){this.onMove(a,b,!0)},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.on("keyup",a.bind(this,this.onKeyUp)),this.firstKeyDown=!0,b.addClass("rz-active"),this.currentFocusElement={pointer:b,ref:c}},onKeyUp:function(){this.firstKeyDown=!0,this.callOnEnd()},onPointerBlur:function(a){a.off("keydown"),a.off("keyup"),this.tracking="",a.removeClass("rz-active"),this.currentFocusElement=null},getKeyActions:function(a){var b=a+this.step,c=a-this.step,d=a+this.valueRange/10,e=a-this.valueRange/10,f={UP:b,DOWN:c,LEFT:c,RIGHT:b,PAGEUP:d,PAGEDOWN:e,HOME:this.minValue,END:this.maxValue};return this.options.rightToLeft&&(f.LEFT=b,f.RIGHT=c,this.options.vertical&&(f.UP=c,f.DOWN=b)),f},onKeyboardEvent:function(a){var c=this[this.tracking],d=a.keyCode||a.which,e={38:"UP",40:"DOWN",37:"LEFT",39:"RIGHT",33:"PAGEUP",34:"PAGEDOWN",36:"HOME",35:"END"},f=this.getKeyActions(c),g=e[d],h=f[g];if(null!=h&&""!==this.tracking){a.preventDefault(),this.firstKeyDown&&(this.firstKeyDown=!1,this.callOnStart());var i=this;b(function(){var a=i.roundStep(i.sanitizeValue(h));if(i.options.draggableRangeOnly){var b,c,d=i.highValue-i.lowValue;"lowValue"===i.tracking?(b=a,c=a+d,c>i.maxValue&&(c=i.maxValue,b=c-d)):(c=a,b=a-d,b=k,h=k>=this.maxPos-e,g){if(0===i.rzsp)return;c=this.getValue("min",k,!0,!1),d=this.getValue("max",k,!0,!1)}else if(h){if(j.rzsp===this.maxPos)return;d=this.getValue("max",k,!0,!0),c=this.getValue("min",k,!0,!0)}else c=this.getValue("min",k,!1),d=this.getValue("max",k,!1);this.positionTrackingBar(c,d)},positionTrackingBar:function(a,b){null!=this.options.minLimit&&athis.options.maxLimit&&(b=this.options.maxLimit,a=b-this.dragging.difference),this.lowValue=a,this.highValue=b,this.applyLowValue(),this.range&&this.applyHighValue(),this.applyModel(),this.updateHandles("lowValue",this.valueToOffset(a)),this.updateHandles("highValue",this.valueToOffset(b))},positionTrackingHandle:function(a){var b=!1;a=this.applyMinMaxLimit(a),this.range&&(this.options.pushRange?(a=this.applyPushRange(a),b=!0):(this.options.noSwitching&&("lowValue"===this.tracking&&a>this.highValue?a=this.applyMinMaxRange(this.highValue):"highValue"===this.tracking&&athis.highValue?(this.lowValue=this.highValue,this.applyLowValue(),this.updateHandles(this.tracking,this.maxH.rzsp),this.updateAriaAttributes(),this.tracking="highValue",this.minH.removeClass("rz-active"),this.maxH.addClass("rz-active"),this.options.keyboardSupport&&this.focusElement(this.maxH),b=!0):"highValue"===this.tracking&&athis.options.maxLimit?this.options.maxLimit:a},applyMinMaxRange:function(a){var b="lowValue"===this.tracking?this.highValue:this.lowValue,c=Math.abs(a-b);return null!=this.options.minRange&&cthis.options.maxRange?"lowValue"===this.tracking?this.highValue-this.options.maxRange:this.lowValue+this.options.maxRange:a},applyPushRange:function(a){var b="lowValue"===this.tracking?this.highValue-a:a-this.lowValue,c=null!==this.options.minRange?this.options.minRange:this.options.step;return c>b&&("lowValue"===this.tracking?(this.highValue=Math.min(a+c,this.maxValue),a=this.highValue-c,this.applyHighValue(),this.updateHandles("highValue",this.valueToOffset(this.highValue))):(this.lowValue=Math.max(a-c,this.minValue),a=this.lowValue+c,this.applyLowValue(),this.updateHandles("lowValue",this.valueToOffset(this.lowValue))),this.updateAriaAttributes()),a},applyModel:function(){this.internalChange=!0,this.scope.$apply(),this.callOnChange(),this.internalChange=!1},callOnStart:function(){if(this.options.onStart){var a=this,b="lowValue"===this.tracking?"min":"max";this.scope.$evalAsync(function(){a.options.onStart(a.options.id,a.scope.rzSliderModel,a.scope.rzSliderHigh,b)})}},callOnChange:function(){if(this.options.onChange){var a=this,b="lowValue"===this.tracking?"min":"max";this.scope.$evalAsync(function(){a.options.onChange(a.options.id,a.scope.rzSliderModel,a.scope.rzSliderHigh,b)})}},callOnEnd:function(){if(this.options.onEnd){var a=this,b="lowValue"===this.tracking?"min":"max";this.scope.$evalAsync(function(){a.options.onEnd(a.options.id,a.scope.rzSliderModel,a.scope.rzSliderHigh,b)})}this.scope.$emit("slideEnded")}},h}]).directive("rzslider",["RzSlider",function(a){return{restrict:"AE",replace:!0,scope:{rzSliderModel:"=?",rzSliderHigh:"=?",rzSliderOptions:"&?",rzSliderTplUrl:"@"},templateUrl:function(a,b){return b.rzSliderTplUrl||"rzSliderTpl.html"},link:function(b,c){b.slider=new a(b,c)}}}]);return b.run(["$templateCache",function(a){a.put("rzSliderTpl.html",'
  • {{ t.value }} {{ t.legend }}
')}]),b.name}); \ 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:null,maxRange:null,pushRange:!1,minLimit:null,maxLimit:null,id:null,translate:null,getLegend:null,stepsArray:null,bindIndexForStepsArray:!1,draggableRange:!1,draggableRangeOnly:!1,showSelectionBar:!1,showSelectionBarEnd:!1,showSelectionBarFromValue:null,hidePointerLabels:!1,hideLimitLabels:!1,autoHideLimitLabels:!0,readOnly:!1,disabled:!1,interval:350,showTicks:!1,showTicksValues:!1,ticksArray:null,ticksTooltip:null,ticksValuesTooltip:null,vertical:!1,getSelectionBarColor:null,getTickColor:null,getPointerColor:null,keyboardSupport:!0,logScale:!1,scale:1,enforceStep:!0,enforceRange:!1,noSwitching:!1,onlyBindHandles:!1,onStart:null,onChange:null,onEnd:null,rightToLeft:!1,boundPointerLabels:!0,mergeRangeLabelsIfSame:!1,customTemplateScope: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.lowValue=0,this.highValue=0,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.intermediateTicks=!1,this.initHasRun=!1,this.firstKeyDown=!1,this.internalChange=!1,this.cmbLabelShown=!1,this.currentFocusElement=null,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.syncLowValue(),this.range&&this.syncHighValue(),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.syncLowValue(),e.range&&e.syncHighValue(),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),e.currentFocusElement=null})},findStepIndex:function(b){for(var c=0,d=0;d0&&0===b.rzsd)&&(f=!0,b.rzsv=e),g||b.html(e),this.scope[c+"Label"]=e,f&&this.getDimension(b)},setMinAndMax:function(){if(this.step=+this.options.step,this.precision=+this.options.precision,this.minValue=this.options.floor,this.options.logScale&&0===this.minValue)throw new Error("Can't use floor=0 with logarithmic scale");this.options.enforceStep&&(this.lowValue=this.roundStep(this.lowValue),this.range&&(this.highValue=this.roundStep(this.highValue))),null!=this.options.ceil?this.maxValue=this.options.ceil:this.maxValue=this.options.ceil=this.range?this.highValue:this.lowValue,this.options.enforceRange&&(this.lowValue=this.sanitizeValue(this.lowValue),this.range&&(this.highValue=this.sanitizeValue(this.highValue))),this.applyLowValue(),this.range&&this.applyHighValue(),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,this.options.id,"model"),"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,this.options.id,"high"),"aria-valuemin":this.minValue,"aria-valuemax":this.maxValue})},calcViewDimensions:function(){var a=this.getDimension(this.minH);if(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();var c=this;b(function(){c.updateTicksScale()})}},updateTicksScale:function(){if(this.options.showTicks){var a=this.options.ticksArray||this.getTicksArray(),b=this.options.vertical?"translateY":"translateX",c=this;this.options.rightToLeft&&a.reverse(),this.scope.ticks=a.map(function(a){var d=c.valueToOffset(a);c.options.vertical&&(d=c.maxPos-d);var e={selected:c.isTickSelected(a),style:{transform:b+"("+d+"px)"}};if(e.selected&&c.options.getSelectionBarColor&&(e.style["background-color"]=c.getSelectionBarColor()),!e.selected&&c.options.getTickColor&&(e.style["background-color"]=c.getTickColor(a)),c.options.ticksTooltip&&(e.tooltip=c.options.ticksTooltip(a),e.tooltipPlacement=c.options.vertical?"right":"top"),c.options.showTicksValues&&(e.value=c.getDisplayValue(a,"tick-value"),c.options.ticksValuesTooltip&&(e.valueTooltip=c.options.ticksValuesTooltip(a),e.valueTooltipPlacement=c.options.vertical?"right":"top")),c.getLegend){var f=c.getLegend(a,c.options.id);f&&(e.legend=f)}return e})}},getTicksArray:function(){var a=this.step,b=[];this.intermediateTicks&&(a=this.options.showTicks);for(var c=this.minValue;c<=this.maxValue;c+=a)b.push(c);return b},isTickSelected:function(a){if(!this.range)if(null!==this.options.showSelectionBarFromValue){var b=this.options.showSelectionBarFromValue;if(this.lowValue>b&&a>=b&&a<=this.lowValue)return!0;if(this.lowValue=a&&a>=this.lowValue)return!0}else if(this.options.showSelectionBarEnd){if(a>=this.lowValue)return!0}else if(this.options.showSelectionBar&&a<=this.lowValue)return!0;return this.range&&a>=this.lowValue&&a<=this.highValue?!0:!1},updateFloorLab:function(){this.translateFn(this.minValue,this.flrLab,"floor"),this.getDimension(this.flrLab);var a=this.options.rightToLeft?this.barDimension-this.flrLab.rzsd:0;this.setPosition(this.flrLab,a)},updateCeilLab:function(){this.translateFn(this.maxValue,this.ceilLab,"ceil"),this.getDimension(this.ceilLab);var a=this.options.rightToLeft?0:this.barDimension-this.ceilLab.rzsd;this.setPosition(this.ceilLab,a)},updateHandles:function(a,b){"lowValue"===a?this.updateLowHandle(b):this.updateHighHandle(b),this.updateSelectionBar(),this.updateTicksScale(),this.range&&this.updateCmbLabel()},getHandleLabelPos:function(a,b){var c=this[a].rzsd,d=b-c/2+this.handleHalfDim,e=this.barDimension-c;return this.options.boundPointerLabels?this.options.rightToLeft&&"minLab"===a||!this.options.rightToLeft&&"maxLab"===a?Math.min(d,e):Math.min(Math.max(d,0),e):d},updateLowHandle:function(a){if(this.setPosition(this.minH,a),this.translateFn(this.lowValue,this.minLab,"model"),this.setPosition(this.minLab,this.getHandleLabelPos("minLab",a)),this.options.getPointerColor){var b=this.getPointerColor("min");this.scope.minPointerStyle={backgroundColor:b}}this.options.autoHideLimitLabels&&this.shFloorCeil()},updateHighHandle:function(a){if(this.setPosition(this.maxH,a),this.translateFn(this.highValue,this.maxLab,"high"),this.setPosition(this.maxLab,this.getHandleLabelPos("maxLab",a)),this.options.getPointerColor){var b=this.getPointerColor("max");this.scope.maxPointerStyle={backgroundColor:b}}this.options.autoHideLimitLabels&&this.shFloorCeil()},shFloorCeil:function(){if(!this.options.hidePointerLabels){var a=!1,b=!1,c=this.options.rightToLeft,d=this.flrLab.rzsp,e=this.flrLab.rzsd,f=this.minLab.rzsp,g=this.minLab.rzsd,h=this.maxLab.rzsp,i=this.maxLab.rzsd,j=this.cmbLab.rzsp,k=this.cmbLab.rzsd,l=this.ceilLab.rzsp,m=this.handleHalfDim,n=c?f+g>=d-e-5:d+e+5>=f,o=c?l+m+10>=f-g:f+g>=l-m-10,p=c?l+10>=h-i:h+i>=l-10,q=c?j>=d-e-m:d+e+m>=j,r=c?l+10>=j-k:j+k>=l-10;if(n?(a=!0,this.hideEl(this.flrLab)):(a=!1,this.showEl(this.flrLab)),o?(b=!0,this.hideEl(this.ceilLab)):(b=!1,this.showEl(this.ceilLab)),this.range){var s=this.cmbLabelShown?r:p,t=this.cmbLabelShown?q:n;s?this.hideEl(this.ceilLab):b||this.showEl(this.ceilLab),t?this.hideEl(this.flrLab):a||this.showEl(this.flrLab)}}},updateSelectionBar:function(){var a=0,b=0,c=this.options.rightToLeft?!this.options.showSelectionBarEnd:this.options.showSelectionBarEnd,d=this.options.rightToLeft?this.maxH.rzsp+this.handleHalfDim:this.minH.rzsp+this.handleHalfDim;if(this.range)b=Math.abs(this.maxH.rzsp-this.minH.rzsp),a=d;else if(null!==this.options.showSelectionBarFromValue){var e=this.options.showSelectionBarFromValue,f=this.valueToOffset(e),g=this.options.rightToLeft?this.lowValue<=e:this.lowValue>e;g?(b=this.minH.rzsp-f,a=f+this.handleHalfDim):(b=f-this.minH.rzsp,a=this.minH.rzsp+this.handleHalfDim)}else c?(b=Math.abs(this.maxPos-this.minH.rzsp)+this.handleHalfDim,a=this.minH.rzsp+this.handleHalfDim):(b=Math.abs(this.maxH.rzsp-this.minH.rzsp)+this.handleHalfDim,a=0);if(this.setDimension(this.selBar,b),this.setPosition(this.selBar,a),this.options.getSelectionBarColor){var h=this.getSelectionBarColor();this.scope.barStyle={backgroundColor:h}}},getSelectionBarColor:function(){return this.range?this.options.getSelectionBarColor(this.scope.rzSliderModel,this.scope.rzSliderHigh):this.options.getSelectionBarColor(this.scope.rzSliderModel)},getPointerColor:function(a){return"max"===a?this.options.getPointerColor(this.scope.rzSliderHigh,a):this.options.getPointerColor(this.scope.rzSliderModel,a)},getTickColor:function(a){return this.options.getTickColor(a)},updateCmbLabel:function(){var a=null;if(a=this.options.rightToLeft?this.minLab.rzsp-this.minLab.rzsd-10<=this.maxLab.rzsp:this.minLab.rzsp+this.minLab.rzsd+10>=this.maxLab.rzsp){var b=this.getDisplayValue(this.lowValue,"model"),c=this.getDisplayValue(this.highValue,"high"),d="";d=this.options.mergeRangeLabelsIfSame&&b===c?b:this.options.rightToLeft?c+" - "+b:b+" - "+c,this.translateFn(d,this.cmbLab,"cmb",!1);var e=this.options.boundPointerLabels?Math.min(Math.max(this.selBar.rzsp+this.selBar.rzsd/2-this.cmbLab.rzsd/2,0),this.barDimension-this.cmbLab.rzsd):this.selBar.rzsp+this.selBar.rzsd/2-this.cmbLab.rzsd/2;this.setPosition(this.cmbLab,e),this.cmbLabelShown=!0,this.hideEl(this.minLab),this.hideEl(this.maxLab),this.showEl(this.cmbLab)}else this.cmbLabelShown=!1,this.showEl(this.maxLab),this.showEl(this.minLab),this.hideEl(this.cmbLab)},getDisplayValue:function(a,b){return this.options.stepsArray&&!this.options.bindIndexForStepsArray&&(a=this.getStepValue(a)),this.customTrFn(a,this.options.id,b)},roundStep:function(a,b){var c=b?b:this.step,d=parseFloat((a-this.minValue)/c).toPrecision(12);d=Math.round(+d)*c;var e=(this.minValue+d).toFixed(this.precision);return+e},hideEl:function(a){return a.css({visibility:"hidden"})},showEl:function(a){return a.rzAlwaysHide?a:a.css({visibility:"visible"})},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){var b=this.sanitizeValue(a),c=this.options.logScale?Math.log(this.minValue):this.minValue,d=this.options.logScale?Math.log(this.maxValue):this.maxValue,e=d-c;return this.options.logScale&&(b=Math.log(b)),this.options.rightToLeft?(d-b)*this.maxPos/e||0:(b-c)*this.maxPos/e||0},sanitizeValue:function(a){return Math.min(Math.max(a,this.minValue),this.maxValue)},offsetToValue:function(a){var b=this.options.logScale?Math.log(this.minValue):this.minValue,c=this.options.logScale?Math.log(this.maxValue):this.maxValue,d=c-b,e=0;return e=this.options.rightToLeft?(1-a/this.maxPos)*d+b:a/this.maxPos*d+b,this.options.logScale?Math.exp(e):e},getEventXY:function(a){var b=this.options.vertical?"clientY":"clientX";return void 0!==a[b]?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:this.options.rightToLeft?b>this.minH.rzsp?this.minH:this.maxH:b=f?e=h:f>=this.maxPos?e=g:(e=this.offsetToValue(f),e=d&&a.isNumber(this.options.showTicks)?this.roundStep(e,this.options.showTicks):this.roundStep(e)),this.positionTrackingHandle(e)},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.callOnEnd()},onTickClick:function(a,b){this.onMove(a,b,!0)},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.on("keyup",a.bind(this,this.onKeyUp)),this.firstKeyDown=!0,b.addClass("rz-active"),this.currentFocusElement={pointer:b,ref:c}},onKeyUp:function(){this.firstKeyDown=!0,this.callOnEnd()},onPointerBlur:function(a){a.off("keydown"),a.off("keyup"),this.tracking="",a.removeClass("rz-active"),this.currentFocusElement=null},getKeyActions:function(a){var b=a+this.step,c=a-this.step,d=a+this.valueRange/10,e=a-this.valueRange/10,f={UP:b,DOWN:c,LEFT:c,RIGHT:b,PAGEUP:d,PAGEDOWN:e,HOME:this.minValue,END:this.maxValue};return this.options.rightToLeft&&(f.LEFT=b,f.RIGHT=c,this.options.vertical&&(f.UP=c,f.DOWN=b)),f},onKeyboardEvent:function(a){var c=this[this.tracking],d=a.keyCode||a.which,e={38:"UP",40:"DOWN",37:"LEFT",39:"RIGHT",33:"PAGEUP",34:"PAGEDOWN",36:"HOME",35:"END"},f=this.getKeyActions(c),g=e[d],h=f[g];if(null!=h&&""!==this.tracking){a.preventDefault(),this.firstKeyDown&&(this.firstKeyDown=!1,this.callOnStart());var i=this;b(function(){var a=i.roundStep(i.sanitizeValue(h));if(i.options.draggableRangeOnly){var b,c,d=i.highValue-i.lowValue;"lowValue"===i.tracking?(b=a,c=a+d,c>i.maxValue&&(c=i.maxValue,b=c-d)):(c=a,b=a-d,b=k,h=k>=this.maxPos-e,g){if(0===i.rzsp)return;c=this.getValue("min",k,!0,!1),d=this.getValue("max",k,!0,!1)}else if(h){if(j.rzsp===this.maxPos)return;d=this.getValue("max",k,!0,!0),c=this.getValue("min",k,!0,!0)}else c=this.getValue("min",k,!1),d=this.getValue("max",k,!1);this.positionTrackingBar(c,d)},positionTrackingBar:function(a,b){null!=this.options.minLimit&&athis.options.maxLimit&&(b=this.options.maxLimit,a=b-this.dragging.difference),this.lowValue=a,this.highValue=b,this.applyLowValue(),this.range&&this.applyHighValue(),this.applyModel(),this.updateHandles("lowValue",this.valueToOffset(a)),this.updateHandles("highValue",this.valueToOffset(b))},positionTrackingHandle:function(a){var b=!1;a=this.applyMinMaxLimit(a),this.range&&(this.options.pushRange?(a=this.applyPushRange(a),b=!0):(this.options.noSwitching&&("lowValue"===this.tracking&&a>this.highValue?a=this.applyMinMaxRange(this.highValue):"highValue"===this.tracking&&athis.highValue?(this.lowValue=this.highValue,this.applyLowValue(),this.updateHandles(this.tracking,this.maxH.rzsp),this.updateAriaAttributes(),this.tracking="highValue",this.minH.removeClass("rz-active"),this.maxH.addClass("rz-active"),this.options.keyboardSupport&&this.focusElement(this.maxH),b=!0):"highValue"===this.tracking&&athis.options.maxLimit?this.options.maxLimit:a},applyMinMaxRange:function(a){var b="lowValue"===this.tracking?this.highValue:this.lowValue,c=Math.abs(a-b);return null!=this.options.minRange&&cthis.options.maxRange?"lowValue"===this.tracking?this.highValue-this.options.maxRange:this.lowValue+this.options.maxRange:a},applyPushRange:function(a){var b="lowValue"===this.tracking?this.highValue-a:a-this.lowValue,c=null!==this.options.minRange?this.options.minRange:this.options.step;return c>b&&("lowValue"===this.tracking?(this.highValue=Math.min(a+c,this.maxValue),a=this.highValue-c,this.applyHighValue(),this.updateHandles("highValue",this.valueToOffset(this.highValue))):(this.lowValue=Math.max(a-c,this.minValue),a=this.lowValue+c,this.applyLowValue(),this.updateHandles("lowValue",this.valueToOffset(this.lowValue))),this.updateAriaAttributes()),a},applyModel:function(){this.internalChange=!0,this.scope.$apply(),this.callOnChange(),this.internalChange=!1},callOnStart:function(){if(this.options.onStart){var a=this,b="lowValue"===this.tracking?"min":"max";this.scope.$evalAsync(function(){a.options.onStart(a.options.id,a.scope.rzSliderModel,a.scope.rzSliderHigh,b)})}},callOnChange:function(){if(this.options.onChange){var a=this,b="lowValue"===this.tracking?"min":"max";this.scope.$evalAsync(function(){a.options.onChange(a.options.id,a.scope.rzSliderModel,a.scope.rzSliderHigh,b)})}},callOnEnd:function(){if(this.options.onEnd){var a=this,b="lowValue"===this.tracking?"min":"max";this.scope.$evalAsync(function(){a.options.onEnd(a.options.id,a.scope.rzSliderModel,a.scope.rzSliderHigh,b)})}this.scope.$emit("slideEnded")}},h}]).directive("rzslider",["RzSlider",function(a){return{restrict:"AE",replace:!0,scope:{rzSliderModel:"=?",rzSliderHigh:"=?",rzSliderOptions:"&?",rzSliderTplUrl:"@"},templateUrl:function(a,b){return b.rzSliderTplUrl||"rzSliderTpl.html"},link:function(b,c){b.slider=new a(b,c)}}}]);return b.run(["$templateCache",function(a){a.put("rzSliderTpl.html",'
  • {{ t.value }} {{ t.legend }}
')}]),b.name}); \ No newline at end of file diff --git a/src/rzslider.js b/src/rzslider.js index ab445a1..7146514 100644 --- a/src/rzslider.js +++ b/src/rzslider.js @@ -1432,19 +1432,17 @@ * @returns {number} */ valueToOffset: function(val) { - var sanitizedValue = this.sanitizeValue(val); - if (!this.options.logScale) { - if (this.options.rightToLeft) { - return (this.maxValue - sanitizedValue) * this.maxPos / this.valueRange || 0; - } - return (sanitizedValue - this.minValue) * this.maxPos / this.valueRange || 0; - } - else { - var minLog = Math.log(this.minValue), - maxLog = Math.log(this.maxValue), - scale = (maxLog - minLog) / (this.maxPos); - return (Math.log(sanitizedValue) - minLog) / scale || 0; - } + var sanitizedValue = this.sanitizeValue(val), + minValue = this.options.logScale ? Math.log(this.minValue) : this.minValue, + maxValue = this.options.logScale ? Math.log(this.maxValue) : this.maxValue, + range = maxValue - minValue; + + if (this.options.logScale) + sanitizedValue = Math.log(sanitizedValue); + + if (this.options.rightToLeft) + return (maxValue - sanitizedValue) * this.maxPos / range || 0; + return (sanitizedValue - minValue) * this.maxPos / range || 0; }, /** @@ -1464,18 +1462,16 @@ * @returns {number} */ offsetToValue: function(offset) { - if (!this.options.logScale) { - if (this.options.rightToLeft) { - return (1 - (offset / this.maxPos)) * this.valueRange + this.minValue; - } - return (offset / this.maxPos) * this.valueRange + this.minValue; - } - else { - var minLog = Math.log(this.minValue), - maxLog = Math.log(this.maxValue), - scale = (maxLog - minLog) / (this.maxPos); - return Math.exp(minLog + scale * offset); - } + var minValue = this.options.logScale ? Math.log(this.minValue) : this.minValue, + maxValue = this.options.logScale ? Math.log(this.maxValue) : this.maxValue, + range = maxValue - minValue, + value = 0; + if (this.options.rightToLeft) + value = (1 - offset / this.maxPos) * range + minValue; + else + value = offset / this.maxPos * range + minValue; + + return this.options.logScale ? Math.exp(value) : value; }, // Events From 7328dc610b3b76abb18c945a0139a0d07465071a Mon Sep 17 00:00:00 2001 From: Valentin Hervieu Date: Sun, 16 Oct 2016 18:57:17 +0200 Subject: [PATCH 3/3] Refactor logScale feature --- CHANGELOG.md | 7 +- README.md | 13 +- demo/demo.js | 37 ++- demo/index.html | 8 + dist/rzslider.js | 220 ++++++++++-------- dist/rzslider.min.js | 2 +- karma.conf.js | 6 +- package.json | 5 +- src/rzslider.js | 220 ++++++++++-------- tests/specs/helper-functions-test.js | 64 ++--- tests/specs/helper.js | 2 +- .../draggable-range-slider-horizontal-test.js | 60 ++--- ...ggableOnly-range-slider-horizontal-test.js | 32 +-- ...oSwitching-range-slider-horizontal-test.js | 12 +- ...oSwitching-range-slider-horizontal-test.js | 16 +- .../range-slider-horizontal-test.js | 32 +-- .../range-slider-vertical-test.js | 64 ++--- .../single-slider-horizontal-test.js | 40 ++-- .../single-slider-vertical-test.js | 40 ++-- tests/specs/options-handling-test.js | 59 +++-- tests/specs/scale-test.js | 158 +++++++++++++ 21 files changed, 684 insertions(+), 413 deletions(-) create mode 100644 tests/specs/scale-test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c89aa8..9f3a019 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ +# 5.7.0 (2016-10-16) +## Features +- Add a `logScale` option to display the slider using a logarithmic scale (#280). +- Add `customValueToPosition` and `customPositionToValue` options to display the slider using a custom scale (#280). + # 5.6.0 (2016-10-16) ## Features -- Add an `ticksArray` to display ticks at specific positions (#426). +- Add a `ticksArray` option to display ticks at specific positions (#426). To enable this new feature, the way the ticks are rendered has been changed. Now each tick is positioned absolutely using a `transform: translate()` instruction. diff --git a/README.md b/README.md index bd2a995..1abeb57 100644 --- a/README.md +++ b/README.md @@ -239,7 +239,10 @@ The default options are: rightToLeft: false, boundPointerLabels: true, mergeRangeLabelsIfSame: false, - customTemplateScope: null + customTemplateScope: null, + logScale: false, + customValueToPosition: null, + customPositionToValue: null } ```` @@ -382,6 +385,14 @@ _Changing this value at runtime is not currently supported._ **customTemplateScope** - _Object (default to null)_: The properties defined in this object will be exposed in the slider template under `custom.X`. +**logScale** - _Boolean (defaults to false)_: Set to true to use a logarithmic scale to display the slider. + +For custom scales: +**customValueToPosition** - _Function(val, minVal, maxVal): percent_: Function that returns the position on the slider for a given value. The position must be a percentage between 0 and 1. + +**customPositionToValue** - _Function(percent, minVal, maxVal): value_: Function that returns the value for a given position on the slider. The position is a percentage between 0 and 1. + + ## Change default options If you want the change the default options for all the sliders displayed in your application, you can set them using the `RzSliderOptions.options()` method: ```js diff --git a/demo/demo.js b/demo/demo.js index 30c9646..e75a0e1 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -13,6 +13,7 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) { options: { floor: 0, ceil: 100, + rightToLeft: true, step: 1 } }; @@ -143,7 +144,32 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) { options: { floor: 1, ceil: 100, - logScale: true + logScale: true, + showTicks: true + } + }; + + //Slider config with custom scale + $scope.slider_custom_scale = { + value: 50, + options: { + floor: 0, + ceil: 100, + step: 10, + showTicksValues: true, + customValueToPosition: function(val, minVal, maxVal) { + val = Math.sqrt(val); + minVal = Math.sqrt(minVal); + maxVal = Math.sqrt(maxVal); + var range = maxVal - minVal; + return (val - minVal) / range; + }, + customPositionToValue: function(percent, minVal, maxVal) { + minVal = Math.sqrt(minVal); + maxVal = Math.sqrt(maxVal); + var value = percent * (maxVal - minVal) + minVal; + return Math.pow(value, 2); + } } }; @@ -242,8 +268,7 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) { options: { ceil: 10, floor: 0, - ticksArray: [0, 1, 3, 8, 10], - showTicksValues: true + ticksArray: [0, 1, 3, 8, 10] } }; @@ -332,7 +357,7 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) { step: 50, showSelectionBar: true, showTicks: true, - getTickColor: function(value){ + getTickColor: function(value) { if (value < 300) return 'red'; if (value < 600) @@ -574,8 +599,8 @@ app.directive('clickableLabel', function() { scope: {label: '='}, replace: true, template: "", - link: function(scope, elem, attrs){ - scope.onclick = function(label){ + link: function(scope, elem, attrs) { + scope.onclick = function(label) { alert("I'm " + label); }; } diff --git a/demo/index.html b/demo/index.html index fbe9ca3..0eb6ed6 100644 --- a/demo/index.html +++ b/demo/index.html @@ -127,6 +127,14 @@

Slider with logarithmic scale

>
+
+

Slider with custom scale

+ +
+

Right to left slider with custom floor/ceil/step

center; if (isModelGreaterThanCenter) { dimension = this.minH.rzsp - centerPosition; @@ -1377,7 +1379,7 @@ }, /** - * Set element left/top offset depending on whether slider is horizontal or vertical + * Set element left/top position depending on whether slider is horizontal or vertical * * @param {jqLite} elem The jqLite wrapped DOM element * @param {number} pos @@ -1422,56 +1424,78 @@ }, /** - * Translate value to pixel offset + * Returns a value that is within slider range * * @param {number} val * @returns {number} */ - valueToOffset: function(val) { - var sanitizedValue = this.sanitizeValue(val), - minValue = this.options.logScale ? Math.log(this.minValue) : this.minValue, - maxValue = this.options.logScale ? Math.log(this.maxValue) : this.maxValue, - range = maxValue - minValue; - - if (this.options.logScale) - sanitizedValue = Math.log(sanitizedValue); - - if (this.options.rightToLeft) - return (maxValue - sanitizedValue) * this.maxPos / range || 0; - return (sanitizedValue - minValue) * this.maxPos / range || 0; + sanitizeValue: function(val) { + return Math.min(Math.max(val, this.minValue), this.maxValue); }, /** - * Returns a value that is within slider range + * Translate value to pixel position * * @param {number} val * @returns {number} */ - sanitizeValue: function(val) { - return Math.min(Math.max(val, this.minValue), this.maxValue); + valueToPosition: function(val) { + var fn = this.linearValueToPosition; + if (this.options.customValueToPosition) + fn = this.options.customValueToPosition; + else if (this.options.logScale) + fn = this.logValueToPosition; + + val = this.sanitizeValue(val); + var percent = fn(val, this.minValue, this.maxValue) || 0; + if(this.options.rightToLeft) + percent = 1 - percent; + return percent * this.maxPos; + }, + + linearValueToPosition: function(val, minVal, maxVal) { + var range = maxVal - minVal; + return (val - minVal) / range; + }, + + logValueToPosition: function(val, minVal, maxVal) { + val = Math.log(val); + minVal = Math.log(minVal); + maxVal = Math.log(maxVal); + var range = maxVal - minVal; + return (val - minVal) / range; }, /** - * Translate offset to model value + * Translate position to model value * - * @param {number} offset + * @param {number} position * @returns {number} */ - offsetToValue: function(offset) { - var minValue = this.options.logScale ? Math.log(this.minValue) : this.minValue, - maxValue = this.options.logScale ? Math.log(this.maxValue) : this.maxValue, - range = maxValue - minValue, - value = 0; - if (this.options.rightToLeft) - value = (1 - offset / this.maxPos) * range + minValue; - else - value = offset / this.maxPos * range + minValue; + positionToValue: function(position) { + var percent = position / this.maxPos; + if(this.options.rightToLeft) + percent = 1 - percent; + var fn = this.linearPositionToValue; + if (this.options.customPositionToValue) + fn = this.options.customPositionToValue; + else if (this.options.logScale) + fn = this.logPositionToValue; + return fn(percent, this.minValue, this.maxValue) || 0; + }, - return this.options.logScale ? Math.exp(value) : value; + linearPositionToValue: function(percent, minVal, maxVal) { + return percent * (maxVal - minVal) + minVal; }, - // Events + logPositionToValue: function(percent, minVal, maxVal) { + minVal = Math.log(minVal); + maxVal = Math.log(maxVal); + var value = percent * (maxVal - minVal) + minVal; + return Math.exp(value); + }, + // Events /** * Get the X-coordinate or Y-coordinate of an event * @@ -1539,19 +1563,19 @@ if (!this.range) { return this.minH; } - var offset = this.getEventPosition(event), - distanceMin = Math.abs(offset - this.minH.rzsp), - distanceMax = Math.abs(offset - this.maxH.rzsp); + var position = this.getEventPosition(event), + distanceMin = Math.abs(position - this.minH.rzsp), + distanceMax = Math.abs(position - this.maxH.rzsp); if (distanceMin < distanceMax) return this.minH; else if (distanceMin > distanceMax) return this.maxH; else if (!this.options.rightToLeft) //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; + return position < this.minH.rzsp ? this.minH : this.maxH; else //reverse in rtl - return offset > this.minH.rzsp ? this.minH : this.maxH; + return position > this.minH.rzsp ? this.minH : this.maxH; }, /** @@ -1692,17 +1716,17 @@ * @returns {undefined} */ onMove: function(pointer, event, fromTick) { - var newOffset = this.getEventPosition(event), + var newPos = this.getEventPosition(event), newValue, ceilValue = this.options.rightToLeft ? this.minValue : this.maxValue, flrValue = this.options.rightToLeft ? this.maxValue : this.minValue; - if (newOffset <= 0) { + if (newPos <= 0) { newValue = flrValue; - } else if (newOffset >= this.maxPos) { + } else if (newPos >= this.maxPos) { newValue = ceilValue; } else { - newValue = this.offsetToValue(newOffset); + newValue = this.positionToValue(newPos); if (fromTick && angular.isNumber(this.options.showTicks)) newValue = this.roundStep(newValue, this.options.showTicks); else @@ -1864,13 +1888,13 @@ * @returns {undefined} */ onDragStart: function(pointer, ref, event) { - var offset = this.getEventPosition(event); + var position = this.getEventPosition(event); this.dragging = { active: true, - value: this.offsetToValue(offset), + value: this.positionToValue(position), difference: this.highValue - this.lowValue, - lowLimit: this.options.rightToLeft ? this.minH.rzsp - offset : offset - this.minH.rzsp, - highLimit: this.options.rightToLeft ? offset - this.maxH.rzsp : this.maxH.rzsp - offset + lowLimit: this.options.rightToLeft ? this.minH.rzsp - position : position - this.minH.rzsp, + highLimit: this.options.rightToLeft ? position - this.maxH.rzsp : this.maxH.rzsp - position }; this.onStart(pointer, ref, event); @@ -1879,16 +1903,16 @@ /** * getValue helper function * - * gets max or min value depending on whether the newOffset is outOfBounds above or below the bar and rightToLeft + * gets max or min value depending on whether the newPos is outOfBounds above or below the bar and rightToLeft * * @param {string} type 'max' || 'min' The value we are calculating - * @param {number} newOffset The new offset - * @param {boolean} outOfBounds Is the new offset above or below the max/min? - * @param {boolean} isAbove Is the new offset above the bar if out of bounds? + * @param {number} newPos The new position + * @param {boolean} outOfBounds Is the new position above or below the max/min? + * @param {boolean} isAbove Is the new position above the bar if out of bounds? * * @returns {number} */ - getValue: function(type, newOffset, outOfBounds, isAbove) { + getValue: function(type, newPos, outOfBounds, isAbove) { var isRTL = this.options.rightToLeft, value = null; @@ -1900,7 +1924,7 @@ value = isRTL ? this.maxValue - this.dragging.difference : this.minValue; } } else { - value = isRTL ? this.offsetToValue(newOffset + this.dragging.lowLimit) : this.offsetToValue(newOffset - this.dragging.lowLimit) + value = isRTL ? this.positionToValue(newPos + this.dragging.lowLimit) : this.positionToValue(newPos - this.dragging.lowLimit) } } else { if (outOfBounds) { @@ -1911,9 +1935,9 @@ } } else { if (isRTL) { - value = this.offsetToValue(newOffset + this.dragging.lowLimit) + this.dragging.difference + value = this.positionToValue(newPos + this.dragging.lowLimit) + this.dragging.difference } else { - value = this.offsetToValue(newOffset - this.dragging.lowLimit) + this.dragging.difference; + value = this.positionToValue(newPos - this.dragging.lowLimit) + this.dragging.difference; } } } @@ -1930,7 +1954,7 @@ * @returns {undefined} */ onDragMove: function(pointer, event) { - var newOffset = this.getEventPosition(event), + var newPos = this.getEventPosition(event), newMinValue, newMaxValue, ceilLimit, flrLimit, isUnderFlrLimit, isOverCeilLimit, @@ -1947,28 +1971,28 @@ flrH = this.minH; ceilH = this.maxH; } - isUnderFlrLimit = newOffset <= flrLimit; - isOverCeilLimit = newOffset >= this.maxPos - ceilLimit; + isUnderFlrLimit = newPos <= flrLimit; + isOverCeilLimit = newPos >= this.maxPos - ceilLimit; if (isUnderFlrLimit) { if (flrH.rzsp === 0) return; - newMinValue = this.getValue('min', newOffset, true, false); - newMaxValue = this.getValue('max', newOffset, true, false); + newMinValue = this.getValue('min', newPos, true, false); + newMaxValue = this.getValue('max', newPos, true, false); } else if (isOverCeilLimit) { if (ceilH.rzsp === this.maxPos) return; - newMaxValue = this.getValue('max', newOffset, true, true); - newMinValue = this.getValue('min', newOffset, true, true); + newMaxValue = this.getValue('max', newPos, true, true); + newMinValue = this.getValue('min', newPos, true, true); } else { - newMinValue = this.getValue('min', newOffset, false); - newMaxValue = this.getValue('max', newOffset, false); + newMinValue = this.getValue('min', newPos, false); + newMaxValue = this.getValue('max', newPos, false); } this.positionTrackingBar(newMinValue, newMaxValue); }, /** - * Set the new value and offset for the entire bar + * Set the new value and position for the entire bar * * @param {number} newMinValue the new minimum value * @param {number} newMaxValue the new maximum value @@ -1990,12 +2014,12 @@ if (this.range) this.applyHighValue(); this.applyModel(); - this.updateHandles('lowValue', this.valueToOffset(newMinValue)); - this.updateHandles('highValue', this.valueToOffset(newMaxValue)); + this.updateHandles('lowValue', this.valueToPosition(newMinValue)); + this.updateHandles('highValue', this.valueToPosition(newMaxValue)); }, /** - * Set the new value and offset to the current tracking handle + * Set the new value and position to the current tracking handle * * @param {number} newValue new model value */ @@ -2050,7 +2074,7 @@ this.applyLowValue(); else this.applyHighValue(); - this.updateHandles(this.tracking, this.valueToOffset(newValue)); + this.updateHandles(this.tracking, this.valueToPosition(newValue)); this.updateAriaAttributes(); valueChanged = true; } @@ -2097,13 +2121,13 @@ this.highValue = Math.min(newValue + range, this.maxValue); newValue = this.highValue - range; this.applyHighValue(); - this.updateHandles('highValue', this.valueToOffset(this.highValue)); + this.updateHandles('highValue', this.valueToPosition(this.highValue)); } else { this.lowValue = Math.max(newValue - range, this.minValue); newValue = this.lowValue + range; this.applyLowValue(); - this.updateHandles('lowValue', this.valueToOffset(this.lowValue)); + this.updateHandles('lowValue', this.valueToPosition(this.lowValue)); } this.updateAriaAttributes(); } @@ -2218,7 +2242,7 @@ /** * @name jqLite * - * @property {number|undefined} rzsp rzslider label position offset + * @property {number|undefined} rzsp rzslider label position position * @property {number|undefined} rzsd rzslider element dimension * @property {string|undefined} rzsv rzslider label value/text * @property {Function} css diff --git a/dist/rzslider.min.js b/dist/rzslider.min.js index e684c2b..b9cd017 100644 --- a/dist/rzslider.min.js +++ b/dist/rzslider.min.js @@ -1,2 +1,2 @@ /*! angularjs-slider - v5.6.0 - (c) Rafal Zajac , Valentin Hervieu , Jussi Saarivirta , Angelin Sirbu - https://github.com/angular-slider/angularjs-slider - 2016-10-16 */ -!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:null,maxRange:null,pushRange:!1,minLimit:null,maxLimit:null,id:null,translate:null,getLegend:null,stepsArray:null,bindIndexForStepsArray:!1,draggableRange:!1,draggableRangeOnly:!1,showSelectionBar:!1,showSelectionBarEnd:!1,showSelectionBarFromValue:null,hidePointerLabels:!1,hideLimitLabels:!1,autoHideLimitLabels:!0,readOnly:!1,disabled:!1,interval:350,showTicks:!1,showTicksValues:!1,ticksArray:null,ticksTooltip:null,ticksValuesTooltip:null,vertical:!1,getSelectionBarColor:null,getTickColor:null,getPointerColor:null,keyboardSupport:!0,logScale:!1,scale:1,enforceStep:!0,enforceRange:!1,noSwitching:!1,onlyBindHandles:!1,onStart:null,onChange:null,onEnd:null,rightToLeft:!1,boundPointerLabels:!0,mergeRangeLabelsIfSame:!1,customTemplateScope: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.lowValue=0,this.highValue=0,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.intermediateTicks=!1,this.initHasRun=!1,this.firstKeyDown=!1,this.internalChange=!1,this.cmbLabelShown=!1,this.currentFocusElement=null,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.syncLowValue(),this.range&&this.syncHighValue(),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.syncLowValue(),e.range&&e.syncHighValue(),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),e.currentFocusElement=null})},findStepIndex:function(b){for(var c=0,d=0;d0&&0===b.rzsd)&&(f=!0,b.rzsv=e),g||b.html(e),this.scope[c+"Label"]=e,f&&this.getDimension(b)},setMinAndMax:function(){if(this.step=+this.options.step,this.precision=+this.options.precision,this.minValue=this.options.floor,this.options.logScale&&0===this.minValue)throw new Error("Can't use floor=0 with logarithmic scale");this.options.enforceStep&&(this.lowValue=this.roundStep(this.lowValue),this.range&&(this.highValue=this.roundStep(this.highValue))),null!=this.options.ceil?this.maxValue=this.options.ceil:this.maxValue=this.options.ceil=this.range?this.highValue:this.lowValue,this.options.enforceRange&&(this.lowValue=this.sanitizeValue(this.lowValue),this.range&&(this.highValue=this.sanitizeValue(this.highValue))),this.applyLowValue(),this.range&&this.applyHighValue(),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,this.options.id,"model"),"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,this.options.id,"high"),"aria-valuemin":this.minValue,"aria-valuemax":this.maxValue})},calcViewDimensions:function(){var a=this.getDimension(this.minH);if(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();var c=this;b(function(){c.updateTicksScale()})}},updateTicksScale:function(){if(this.options.showTicks){var a=this.options.ticksArray||this.getTicksArray(),b=this.options.vertical?"translateY":"translateX",c=this;this.options.rightToLeft&&a.reverse(),this.scope.ticks=a.map(function(a){var d=c.valueToOffset(a);c.options.vertical&&(d=c.maxPos-d);var e={selected:c.isTickSelected(a),style:{transform:b+"("+d+"px)"}};if(e.selected&&c.options.getSelectionBarColor&&(e.style["background-color"]=c.getSelectionBarColor()),!e.selected&&c.options.getTickColor&&(e.style["background-color"]=c.getTickColor(a)),c.options.ticksTooltip&&(e.tooltip=c.options.ticksTooltip(a),e.tooltipPlacement=c.options.vertical?"right":"top"),c.options.showTicksValues&&(e.value=c.getDisplayValue(a,"tick-value"),c.options.ticksValuesTooltip&&(e.valueTooltip=c.options.ticksValuesTooltip(a),e.valueTooltipPlacement=c.options.vertical?"right":"top")),c.getLegend){var f=c.getLegend(a,c.options.id);f&&(e.legend=f)}return e})}},getTicksArray:function(){var a=this.step,b=[];this.intermediateTicks&&(a=this.options.showTicks);for(var c=this.minValue;c<=this.maxValue;c+=a)b.push(c);return b},isTickSelected:function(a){if(!this.range)if(null!==this.options.showSelectionBarFromValue){var b=this.options.showSelectionBarFromValue;if(this.lowValue>b&&a>=b&&a<=this.lowValue)return!0;if(this.lowValue=a&&a>=this.lowValue)return!0}else if(this.options.showSelectionBarEnd){if(a>=this.lowValue)return!0}else if(this.options.showSelectionBar&&a<=this.lowValue)return!0;return this.range&&a>=this.lowValue&&a<=this.highValue?!0:!1},updateFloorLab:function(){this.translateFn(this.minValue,this.flrLab,"floor"),this.getDimension(this.flrLab);var a=this.options.rightToLeft?this.barDimension-this.flrLab.rzsd:0;this.setPosition(this.flrLab,a)},updateCeilLab:function(){this.translateFn(this.maxValue,this.ceilLab,"ceil"),this.getDimension(this.ceilLab);var a=this.options.rightToLeft?0:this.barDimension-this.ceilLab.rzsd;this.setPosition(this.ceilLab,a)},updateHandles:function(a,b){"lowValue"===a?this.updateLowHandle(b):this.updateHighHandle(b),this.updateSelectionBar(),this.updateTicksScale(),this.range&&this.updateCmbLabel()},getHandleLabelPos:function(a,b){var c=this[a].rzsd,d=b-c/2+this.handleHalfDim,e=this.barDimension-c;return this.options.boundPointerLabels?this.options.rightToLeft&&"minLab"===a||!this.options.rightToLeft&&"maxLab"===a?Math.min(d,e):Math.min(Math.max(d,0),e):d},updateLowHandle:function(a){if(this.setPosition(this.minH,a),this.translateFn(this.lowValue,this.minLab,"model"),this.setPosition(this.minLab,this.getHandleLabelPos("minLab",a)),this.options.getPointerColor){var b=this.getPointerColor("min");this.scope.minPointerStyle={backgroundColor:b}}this.options.autoHideLimitLabels&&this.shFloorCeil()},updateHighHandle:function(a){if(this.setPosition(this.maxH,a),this.translateFn(this.highValue,this.maxLab,"high"),this.setPosition(this.maxLab,this.getHandleLabelPos("maxLab",a)),this.options.getPointerColor){var b=this.getPointerColor("max");this.scope.maxPointerStyle={backgroundColor:b}}this.options.autoHideLimitLabels&&this.shFloorCeil()},shFloorCeil:function(){if(!this.options.hidePointerLabels){var a=!1,b=!1,c=this.options.rightToLeft,d=this.flrLab.rzsp,e=this.flrLab.rzsd,f=this.minLab.rzsp,g=this.minLab.rzsd,h=this.maxLab.rzsp,i=this.maxLab.rzsd,j=this.cmbLab.rzsp,k=this.cmbLab.rzsd,l=this.ceilLab.rzsp,m=this.handleHalfDim,n=c?f+g>=d-e-5:d+e+5>=f,o=c?l+m+10>=f-g:f+g>=l-m-10,p=c?l+10>=h-i:h+i>=l-10,q=c?j>=d-e-m:d+e+m>=j,r=c?l+10>=j-k:j+k>=l-10;if(n?(a=!0,this.hideEl(this.flrLab)):(a=!1,this.showEl(this.flrLab)),o?(b=!0,this.hideEl(this.ceilLab)):(b=!1,this.showEl(this.ceilLab)),this.range){var s=this.cmbLabelShown?r:p,t=this.cmbLabelShown?q:n;s?this.hideEl(this.ceilLab):b||this.showEl(this.ceilLab),t?this.hideEl(this.flrLab):a||this.showEl(this.flrLab)}}},updateSelectionBar:function(){var a=0,b=0,c=this.options.rightToLeft?!this.options.showSelectionBarEnd:this.options.showSelectionBarEnd,d=this.options.rightToLeft?this.maxH.rzsp+this.handleHalfDim:this.minH.rzsp+this.handleHalfDim;if(this.range)b=Math.abs(this.maxH.rzsp-this.minH.rzsp),a=d;else if(null!==this.options.showSelectionBarFromValue){var e=this.options.showSelectionBarFromValue,f=this.valueToOffset(e),g=this.options.rightToLeft?this.lowValue<=e:this.lowValue>e;g?(b=this.minH.rzsp-f,a=f+this.handleHalfDim):(b=f-this.minH.rzsp,a=this.minH.rzsp+this.handleHalfDim)}else c?(b=Math.abs(this.maxPos-this.minH.rzsp)+this.handleHalfDim,a=this.minH.rzsp+this.handleHalfDim):(b=Math.abs(this.maxH.rzsp-this.minH.rzsp)+this.handleHalfDim,a=0);if(this.setDimension(this.selBar,b),this.setPosition(this.selBar,a),this.options.getSelectionBarColor){var h=this.getSelectionBarColor();this.scope.barStyle={backgroundColor:h}}},getSelectionBarColor:function(){return this.range?this.options.getSelectionBarColor(this.scope.rzSliderModel,this.scope.rzSliderHigh):this.options.getSelectionBarColor(this.scope.rzSliderModel)},getPointerColor:function(a){return"max"===a?this.options.getPointerColor(this.scope.rzSliderHigh,a):this.options.getPointerColor(this.scope.rzSliderModel,a)},getTickColor:function(a){return this.options.getTickColor(a)},updateCmbLabel:function(){var a=null;if(a=this.options.rightToLeft?this.minLab.rzsp-this.minLab.rzsd-10<=this.maxLab.rzsp:this.minLab.rzsp+this.minLab.rzsd+10>=this.maxLab.rzsp){var b=this.getDisplayValue(this.lowValue,"model"),c=this.getDisplayValue(this.highValue,"high"),d="";d=this.options.mergeRangeLabelsIfSame&&b===c?b:this.options.rightToLeft?c+" - "+b:b+" - "+c,this.translateFn(d,this.cmbLab,"cmb",!1);var e=this.options.boundPointerLabels?Math.min(Math.max(this.selBar.rzsp+this.selBar.rzsd/2-this.cmbLab.rzsd/2,0),this.barDimension-this.cmbLab.rzsd):this.selBar.rzsp+this.selBar.rzsd/2-this.cmbLab.rzsd/2;this.setPosition(this.cmbLab,e),this.cmbLabelShown=!0,this.hideEl(this.minLab),this.hideEl(this.maxLab),this.showEl(this.cmbLab)}else this.cmbLabelShown=!1,this.showEl(this.maxLab),this.showEl(this.minLab),this.hideEl(this.cmbLab)},getDisplayValue:function(a,b){return this.options.stepsArray&&!this.options.bindIndexForStepsArray&&(a=this.getStepValue(a)),this.customTrFn(a,this.options.id,b)},roundStep:function(a,b){var c=b?b:this.step,d=parseFloat((a-this.minValue)/c).toPrecision(12);d=Math.round(+d)*c;var e=(this.minValue+d).toFixed(this.precision);return+e},hideEl:function(a){return a.css({visibility:"hidden"})},showEl:function(a){return a.rzAlwaysHide?a:a.css({visibility:"visible"})},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){var b=this.sanitizeValue(a),c=this.options.logScale?Math.log(this.minValue):this.minValue,d=this.options.logScale?Math.log(this.maxValue):this.maxValue,e=d-c;return this.options.logScale&&(b=Math.log(b)),this.options.rightToLeft?(d-b)*this.maxPos/e||0:(b-c)*this.maxPos/e||0},sanitizeValue:function(a){return Math.min(Math.max(a,this.minValue),this.maxValue)},offsetToValue:function(a){var b=this.options.logScale?Math.log(this.minValue):this.minValue,c=this.options.logScale?Math.log(this.maxValue):this.maxValue,d=c-b,e=0;return e=this.options.rightToLeft?(1-a/this.maxPos)*d+b:a/this.maxPos*d+b,this.options.logScale?Math.exp(e):e},getEventXY:function(a){var b=this.options.vertical?"clientY":"clientX";return void 0!==a[b]?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:this.options.rightToLeft?b>this.minH.rzsp?this.minH:this.maxH:b=f?e=h:f>=this.maxPos?e=g:(e=this.offsetToValue(f),e=d&&a.isNumber(this.options.showTicks)?this.roundStep(e,this.options.showTicks):this.roundStep(e)),this.positionTrackingHandle(e)},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.callOnEnd()},onTickClick:function(a,b){this.onMove(a,b,!0)},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.on("keyup",a.bind(this,this.onKeyUp)),this.firstKeyDown=!0,b.addClass("rz-active"),this.currentFocusElement={pointer:b,ref:c}},onKeyUp:function(){this.firstKeyDown=!0,this.callOnEnd()},onPointerBlur:function(a){a.off("keydown"),a.off("keyup"),this.tracking="",a.removeClass("rz-active"),this.currentFocusElement=null},getKeyActions:function(a){var b=a+this.step,c=a-this.step,d=a+this.valueRange/10,e=a-this.valueRange/10,f={UP:b,DOWN:c,LEFT:c,RIGHT:b,PAGEUP:d,PAGEDOWN:e,HOME:this.minValue,END:this.maxValue};return this.options.rightToLeft&&(f.LEFT=b,f.RIGHT=c,this.options.vertical&&(f.UP=c,f.DOWN=b)),f},onKeyboardEvent:function(a){var c=this[this.tracking],d=a.keyCode||a.which,e={38:"UP",40:"DOWN",37:"LEFT",39:"RIGHT",33:"PAGEUP",34:"PAGEDOWN",36:"HOME",35:"END"},f=this.getKeyActions(c),g=e[d],h=f[g];if(null!=h&&""!==this.tracking){a.preventDefault(),this.firstKeyDown&&(this.firstKeyDown=!1,this.callOnStart());var i=this;b(function(){var a=i.roundStep(i.sanitizeValue(h));if(i.options.draggableRangeOnly){var b,c,d=i.highValue-i.lowValue;"lowValue"===i.tracking?(b=a,c=a+d,c>i.maxValue&&(c=i.maxValue,b=c-d)):(c=a,b=a-d,b=k,h=k>=this.maxPos-e,g){if(0===i.rzsp)return;c=this.getValue("min",k,!0,!1),d=this.getValue("max",k,!0,!1)}else if(h){if(j.rzsp===this.maxPos)return;d=this.getValue("max",k,!0,!0),c=this.getValue("min",k,!0,!0)}else c=this.getValue("min",k,!1),d=this.getValue("max",k,!1);this.positionTrackingBar(c,d)},positionTrackingBar:function(a,b){null!=this.options.minLimit&&athis.options.maxLimit&&(b=this.options.maxLimit,a=b-this.dragging.difference),this.lowValue=a,this.highValue=b,this.applyLowValue(),this.range&&this.applyHighValue(),this.applyModel(),this.updateHandles("lowValue",this.valueToOffset(a)),this.updateHandles("highValue",this.valueToOffset(b))},positionTrackingHandle:function(a){var b=!1;a=this.applyMinMaxLimit(a),this.range&&(this.options.pushRange?(a=this.applyPushRange(a),b=!0):(this.options.noSwitching&&("lowValue"===this.tracking&&a>this.highValue?a=this.applyMinMaxRange(this.highValue):"highValue"===this.tracking&&athis.highValue?(this.lowValue=this.highValue,this.applyLowValue(),this.updateHandles(this.tracking,this.maxH.rzsp),this.updateAriaAttributes(),this.tracking="highValue",this.minH.removeClass("rz-active"),this.maxH.addClass("rz-active"),this.options.keyboardSupport&&this.focusElement(this.maxH),b=!0):"highValue"===this.tracking&&athis.options.maxLimit?this.options.maxLimit:a},applyMinMaxRange:function(a){var b="lowValue"===this.tracking?this.highValue:this.lowValue,c=Math.abs(a-b);return null!=this.options.minRange&&cthis.options.maxRange?"lowValue"===this.tracking?this.highValue-this.options.maxRange:this.lowValue+this.options.maxRange:a},applyPushRange:function(a){var b="lowValue"===this.tracking?this.highValue-a:a-this.lowValue,c=null!==this.options.minRange?this.options.minRange:this.options.step;return c>b&&("lowValue"===this.tracking?(this.highValue=Math.min(a+c,this.maxValue),a=this.highValue-c,this.applyHighValue(),this.updateHandles("highValue",this.valueToOffset(this.highValue))):(this.lowValue=Math.max(a-c,this.minValue),a=this.lowValue+c,this.applyLowValue(),this.updateHandles("lowValue",this.valueToOffset(this.lowValue))),this.updateAriaAttributes()),a},applyModel:function(){this.internalChange=!0,this.scope.$apply(),this.callOnChange(),this.internalChange=!1},callOnStart:function(){if(this.options.onStart){var a=this,b="lowValue"===this.tracking?"min":"max";this.scope.$evalAsync(function(){a.options.onStart(a.options.id,a.scope.rzSliderModel,a.scope.rzSliderHigh,b)})}},callOnChange:function(){if(this.options.onChange){var a=this,b="lowValue"===this.tracking?"min":"max";this.scope.$evalAsync(function(){a.options.onChange(a.options.id,a.scope.rzSliderModel,a.scope.rzSliderHigh,b)})}},callOnEnd:function(){if(this.options.onEnd){var a=this,b="lowValue"===this.tracking?"min":"max";this.scope.$evalAsync(function(){a.options.onEnd(a.options.id,a.scope.rzSliderModel,a.scope.rzSliderHigh,b)})}this.scope.$emit("slideEnded")}},h}]).directive("rzslider",["RzSlider",function(a){return{restrict:"AE",replace:!0,scope:{rzSliderModel:"=?",rzSliderHigh:"=?",rzSliderOptions:"&?",rzSliderTplUrl:"@"},templateUrl:function(a,b){return b.rzSliderTplUrl||"rzSliderTpl.html"},link:function(b,c){b.slider=new a(b,c)}}}]);return b.run(["$templateCache",function(a){a.put("rzSliderTpl.html",'
  • {{ t.value }} {{ t.legend }}
')}]),b.name}); \ 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:null,maxRange:null,pushRange:!1,minLimit:null,maxLimit:null,id:null,translate:null,getLegend:null,stepsArray:null,bindIndexForStepsArray:!1,draggableRange:!1,draggableRangeOnly:!1,showSelectionBar:!1,showSelectionBarEnd:!1,showSelectionBarFromValue:null,hidePointerLabels:!1,hideLimitLabels:!1,autoHideLimitLabels:!0,readOnly:!1,disabled:!1,interval:350,showTicks:!1,showTicksValues:!1,ticksArray:null,ticksTooltip:null,ticksValuesTooltip:null,vertical:!1,getSelectionBarColor:null,getTickColor:null,getPointerColor:null,keyboardSupport:!0,scale:1,enforceStep:!0,enforceRange:!1,noSwitching:!1,onlyBindHandles:!1,onStart:null,onChange:null,onEnd:null,rightToLeft:!1,boundPointerLabels:!0,mergeRangeLabelsIfSame:!1,customTemplateScope:null,logScale:!1,customValueToPosition:null,customPositionToValue: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.lowValue=0,this.highValue=0,this.sliderElem=b,this.range=void 0!==this.scope.rzSliderModel&&void 0!==this.scope.rzSliderHigh,this.dragging={active:!1,value:0,difference:0,position: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.intermediateTicks=!1,this.initHasRun=!1,this.firstKeyDown=!1,this.internalChange=!1,this.cmbLabelShown=!1,this.currentFocusElement=null,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.syncLowValue(),this.range&&this.syncHighValue(),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.syncLowValue(),e.range&&e.syncHighValue(),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),e.currentFocusElement=null})},findStepIndex:function(b){for(var c=0,d=0;d0&&0===b.rzsd)&&(f=!0,b.rzsv=e),g||b.html(e),this.scope[c+"Label"]=e,f&&this.getDimension(b)},setMinAndMax:function(){if(this.step=+this.options.step,this.precision=+this.options.precision,this.minValue=this.options.floor,this.options.logScale&&0===this.minValue)throw Error("Can't use floor=0 with logarithmic scale");this.options.enforceStep&&(this.lowValue=this.roundStep(this.lowValue),this.range&&(this.highValue=this.roundStep(this.highValue))),null!=this.options.ceil?this.maxValue=this.options.ceil:this.maxValue=this.options.ceil=this.range?this.highValue:this.lowValue,this.options.enforceRange&&(this.lowValue=this.sanitizeValue(this.lowValue),this.range&&(this.highValue=this.sanitizeValue(this.highValue))),this.applyLowValue(),this.range&&this.applyHighValue(),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,this.options.id,"model"),"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,this.options.id,"high"),"aria-valuemin":this.minValue,"aria-valuemax":this.maxValue})},calcViewDimensions:function(){var a=this.getDimension(this.minH);if(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();var c=this;b(function(){c.updateTicksScale()})}},updateTicksScale:function(){if(this.options.showTicks){var a=this.options.ticksArray||this.getTicksArray(),b=this.options.vertical?"translateY":"translateX",c=this;this.options.rightToLeft&&a.reverse(),this.scope.ticks=a.map(function(a){var d=c.valueToPosition(a);c.options.vertical&&(d=c.maxPos-d);var e={selected:c.isTickSelected(a),style:{transform:b+"("+d+"px)"}};if(e.selected&&c.options.getSelectionBarColor&&(e.style["background-color"]=c.getSelectionBarColor()),!e.selected&&c.options.getTickColor&&(e.style["background-color"]=c.getTickColor(a)),c.options.ticksTooltip&&(e.tooltip=c.options.ticksTooltip(a),e.tooltipPlacement=c.options.vertical?"right":"top"),c.options.showTicksValues&&(e.value=c.getDisplayValue(a,"tick-value"),c.options.ticksValuesTooltip&&(e.valueTooltip=c.options.ticksValuesTooltip(a),e.valueTooltipPlacement=c.options.vertical?"right":"top")),c.getLegend){var f=c.getLegend(a,c.options.id);f&&(e.legend=f)}return e})}},getTicksArray:function(){var a=this.step,b=[];this.intermediateTicks&&(a=this.options.showTicks);for(var c=this.minValue;c<=this.maxValue;c+=a)b.push(c);return b},isTickSelected:function(a){if(!this.range)if(null!==this.options.showSelectionBarFromValue){var b=this.options.showSelectionBarFromValue;if(this.lowValue>b&&a>=b&&a<=this.lowValue)return!0;if(this.lowValue=a&&a>=this.lowValue)return!0}else if(this.options.showSelectionBarEnd){if(a>=this.lowValue)return!0}else if(this.options.showSelectionBar&&a<=this.lowValue)return!0;return this.range&&a>=this.lowValue&&a<=this.highValue?!0:!1},updateFloorLab:function(){this.translateFn(this.minValue,this.flrLab,"floor"),this.getDimension(this.flrLab);var a=this.options.rightToLeft?this.barDimension-this.flrLab.rzsd:0;this.setPosition(this.flrLab,a)},updateCeilLab:function(){this.translateFn(this.maxValue,this.ceilLab,"ceil"),this.getDimension(this.ceilLab);var a=this.options.rightToLeft?0:this.barDimension-this.ceilLab.rzsd;this.setPosition(this.ceilLab,a)},updateHandles:function(a,b){"lowValue"===a?this.updateLowHandle(b):this.updateHighHandle(b),this.updateSelectionBar(),this.updateTicksScale(),this.range&&this.updateCmbLabel()},getHandleLabelPos:function(a,b){var c=this[a].rzsd,d=b-c/2+this.handleHalfDim,e=this.barDimension-c;return this.options.boundPointerLabels?this.options.rightToLeft&&"minLab"===a||!this.options.rightToLeft&&"maxLab"===a?Math.min(d,e):Math.min(Math.max(d,0),e):d},updateLowHandle:function(a){if(this.setPosition(this.minH,a),this.translateFn(this.lowValue,this.minLab,"model"),this.setPosition(this.minLab,this.getHandleLabelPos("minLab",a)),this.options.getPointerColor){var b=this.getPointerColor("min");this.scope.minPointerStyle={backgroundColor:b}}this.options.autoHideLimitLabels&&this.shFloorCeil()},updateHighHandle:function(a){if(this.setPosition(this.maxH,a),this.translateFn(this.highValue,this.maxLab,"high"),this.setPosition(this.maxLab,this.getHandleLabelPos("maxLab",a)),this.options.getPointerColor){var b=this.getPointerColor("max");this.scope.maxPointerStyle={backgroundColor:b}}this.options.autoHideLimitLabels&&this.shFloorCeil()},shFloorCeil:function(){if(!this.options.hidePointerLabels){var a=!1,b=!1,c=this.options.rightToLeft,d=this.flrLab.rzsp,e=this.flrLab.rzsd,f=this.minLab.rzsp,g=this.minLab.rzsd,h=this.maxLab.rzsp,i=this.maxLab.rzsd,j=this.cmbLab.rzsp,k=this.cmbLab.rzsd,l=this.ceilLab.rzsp,m=this.handleHalfDim,n=c?f+g>=d-e-5:d+e+5>=f,o=c?l+m+10>=f-g:f+g>=l-m-10,p=c?l+10>=h-i:h+i>=l-10,q=c?j>=d-e-m:d+e+m>=j,r=c?l+10>=j-k:j+k>=l-10;if(n?(a=!0,this.hideEl(this.flrLab)):(a=!1,this.showEl(this.flrLab)),o?(b=!0,this.hideEl(this.ceilLab)):(b=!1,this.showEl(this.ceilLab)),this.range){var s=this.cmbLabelShown?r:p,t=this.cmbLabelShown?q:n;s?this.hideEl(this.ceilLab):b||this.showEl(this.ceilLab),t?this.hideEl(this.flrLab):a||this.showEl(this.flrLab)}}},updateSelectionBar:function(){var a=0,b=0,c=this.options.rightToLeft?!this.options.showSelectionBarEnd:this.options.showSelectionBarEnd,d=this.options.rightToLeft?this.maxH.rzsp+this.handleHalfDim:this.minH.rzsp+this.handleHalfDim;if(this.range)b=Math.abs(this.maxH.rzsp-this.minH.rzsp),a=d;else if(null!==this.options.showSelectionBarFromValue){var e=this.options.showSelectionBarFromValue,f=this.valueToPosition(e),g=this.options.rightToLeft?this.lowValue<=e:this.lowValue>e;g?(b=this.minH.rzsp-f,a=f+this.handleHalfDim):(b=f-this.minH.rzsp,a=this.minH.rzsp+this.handleHalfDim)}else c?(b=Math.abs(this.maxPos-this.minH.rzsp)+this.handleHalfDim,a=this.minH.rzsp+this.handleHalfDim):(b=Math.abs(this.maxH.rzsp-this.minH.rzsp)+this.handleHalfDim,a=0);if(this.setDimension(this.selBar,b),this.setPosition(this.selBar,a),this.options.getSelectionBarColor){var h=this.getSelectionBarColor();this.scope.barStyle={backgroundColor:h}}},getSelectionBarColor:function(){return this.range?this.options.getSelectionBarColor(this.scope.rzSliderModel,this.scope.rzSliderHigh):this.options.getSelectionBarColor(this.scope.rzSliderModel)},getPointerColor:function(a){return"max"===a?this.options.getPointerColor(this.scope.rzSliderHigh,a):this.options.getPointerColor(this.scope.rzSliderModel,a)},getTickColor:function(a){return this.options.getTickColor(a)},updateCmbLabel:function(){var a=null;if(a=this.options.rightToLeft?this.minLab.rzsp-this.minLab.rzsd-10<=this.maxLab.rzsp:this.minLab.rzsp+this.minLab.rzsd+10>=this.maxLab.rzsp){var b=this.getDisplayValue(this.lowValue,"model"),c=this.getDisplayValue(this.highValue,"high"),d="";d=this.options.mergeRangeLabelsIfSame&&b===c?b:this.options.rightToLeft?c+" - "+b:b+" - "+c,this.translateFn(d,this.cmbLab,"cmb",!1);var e=this.options.boundPointerLabels?Math.min(Math.max(this.selBar.rzsp+this.selBar.rzsd/2-this.cmbLab.rzsd/2,0),this.barDimension-this.cmbLab.rzsd):this.selBar.rzsp+this.selBar.rzsd/2-this.cmbLab.rzsd/2;this.setPosition(this.cmbLab,e),this.cmbLabelShown=!0,this.hideEl(this.minLab),this.hideEl(this.maxLab),this.showEl(this.cmbLab)}else this.cmbLabelShown=!1,this.showEl(this.maxLab),this.showEl(this.minLab),this.hideEl(this.cmbLab)},getDisplayValue:function(a,b){return this.options.stepsArray&&!this.options.bindIndexForStepsArray&&(a=this.getStepValue(a)),this.customTrFn(a,this.options.id,b)},roundStep:function(a,b){var c=b?b:this.step,d=parseFloat((a-this.minValue)/c).toPrecision(12);d=Math.round(+d)*c;var e=(this.minValue+d).toFixed(this.precision);return+e},hideEl:function(a){return a.css({visibility:"hidden"})},showEl:function(a){return a.rzAlwaysHide?a:a.css({visibility:"visible"})},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},sanitizeValue:function(a){return Math.min(Math.max(a,this.minValue),this.maxValue)},valueToPosition:function(a){var b=this.linearValueToPosition;this.options.customValueToPosition?b=this.options.customValueToPosition:this.options.logScale&&(b=this.logValueToPosition),a=this.sanitizeValue(a);var c=b(a,this.minValue,this.maxValue)||0;return this.options.rightToLeft&&(c=1-c),c*this.maxPos},linearValueToPosition:function(a,b,c){var d=c-b;return(a-b)/d},logValueToPosition:function(a,b,c){a=Math.log(a),b=Math.log(b),c=Math.log(c);var d=c-b;return(a-b)/d},positionToValue:function(a){var b=a/this.maxPos;this.options.rightToLeft&&(b=1-b);var c=this.linearPositionToValue;return this.options.customPositionToValue?c=this.options.customPositionToValue:this.options.logScale&&(c=this.logPositionToValue),c(b,this.minValue,this.maxValue)||0},linearPositionToValue:function(a,b,c){return a*(c-b)+b},logPositionToValue:function(a,b,c){b=Math.log(b),c=Math.log(c);var d=a*(c-b)+b;return Math.exp(d)},getEventXY:function(a){var b=this.options.vertical?"clientY":"clientX";return void 0!==a[b]?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:this.options.rightToLeft?b>this.minH.rzsp?this.minH:this.maxH:b=f?e=h:f>=this.maxPos?e=g:(e=this.positionToValue(f),e=d&&a.isNumber(this.options.showTicks)?this.roundStep(e,this.options.showTicks):this.roundStep(e)),this.positionTrackingHandle(e)},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.callOnEnd()},onTickClick:function(a,b){this.onMove(a,b,!0)},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.on("keyup",a.bind(this,this.onKeyUp)),this.firstKeyDown=!0,b.addClass("rz-active"),this.currentFocusElement={pointer:b,ref:c}},onKeyUp:function(){this.firstKeyDown=!0,this.callOnEnd()},onPointerBlur:function(a){a.off("keydown"),a.off("keyup"),this.tracking="",a.removeClass("rz-active"),this.currentFocusElement=null},getKeyActions:function(a){var b=a+this.step,c=a-this.step,d=a+this.valueRange/10,e=a-this.valueRange/10,f={UP:b,DOWN:c,LEFT:c,RIGHT:b,PAGEUP:d,PAGEDOWN:e,HOME:this.minValue,END:this.maxValue};return this.options.rightToLeft&&(f.LEFT=b,f.RIGHT=c,this.options.vertical&&(f.UP=c,f.DOWN=b)),f},onKeyboardEvent:function(a){var c=this[this.tracking],d=a.keyCode||a.which,e={38:"UP",40:"DOWN",37:"LEFT",39:"RIGHT",33:"PAGEUP",34:"PAGEDOWN",36:"HOME",35:"END"},f=this.getKeyActions(c),g=e[d],h=f[g];if(null!=h&&""!==this.tracking){a.preventDefault(),this.firstKeyDown&&(this.firstKeyDown=!1,this.callOnStart());var i=this;b(function(){var a=i.roundStep(i.sanitizeValue(h));if(i.options.draggableRangeOnly){var b,c,d=i.highValue-i.lowValue;"lowValue"===i.tracking?(b=a,c=a+d,c>i.maxValue&&(c=i.maxValue,b=c-d)):(c=a,b=a-d,b=k,h=k>=this.maxPos-e,g){if(0===i.rzsp)return;c=this.getValue("min",k,!0,!1),d=this.getValue("max",k,!0,!1)}else if(h){if(j.rzsp===this.maxPos)return;d=this.getValue("max",k,!0,!0),c=this.getValue("min",k,!0,!0)}else c=this.getValue("min",k,!1),d=this.getValue("max",k,!1);this.positionTrackingBar(c,d)},positionTrackingBar:function(a,b){null!=this.options.minLimit&&athis.options.maxLimit&&(b=this.options.maxLimit,a=b-this.dragging.difference),this.lowValue=a,this.highValue=b,this.applyLowValue(),this.range&&this.applyHighValue(),this.applyModel(),this.updateHandles("lowValue",this.valueToPosition(a)),this.updateHandles("highValue",this.valueToPosition(b))},positionTrackingHandle:function(a){var b=!1;a=this.applyMinMaxLimit(a),this.range&&(this.options.pushRange?(a=this.applyPushRange(a),b=!0):(this.options.noSwitching&&("lowValue"===this.tracking&&a>this.highValue?a=this.applyMinMaxRange(this.highValue):"highValue"===this.tracking&&athis.highValue?(this.lowValue=this.highValue,this.applyLowValue(),this.updateHandles(this.tracking,this.maxH.rzsp),this.updateAriaAttributes(),this.tracking="highValue",this.minH.removeClass("rz-active"),this.maxH.addClass("rz-active"),this.options.keyboardSupport&&this.focusElement(this.maxH),b=!0):"highValue"===this.tracking&&athis.options.maxLimit?this.options.maxLimit:a},applyMinMaxRange:function(a){var b="lowValue"===this.tracking?this.highValue:this.lowValue,c=Math.abs(a-b);return null!=this.options.minRange&&cthis.options.maxRange?"lowValue"===this.tracking?this.highValue-this.options.maxRange:this.lowValue+this.options.maxRange:a},applyPushRange:function(a){var b="lowValue"===this.tracking?this.highValue-a:a-this.lowValue,c=null!==this.options.minRange?this.options.minRange:this.options.step;return c>b&&("lowValue"===this.tracking?(this.highValue=Math.min(a+c,this.maxValue),a=this.highValue-c,this.applyHighValue(),this.updateHandles("highValue",this.valueToPosition(this.highValue))):(this.lowValue=Math.max(a-c,this.minValue),a=this.lowValue+c,this.applyLowValue(),this.updateHandles("lowValue",this.valueToPosition(this.lowValue))),this.updateAriaAttributes()),a},applyModel:function(){this.internalChange=!0,this.scope.$apply(),this.callOnChange(),this.internalChange=!1},callOnStart:function(){if(this.options.onStart){var a=this,b="lowValue"===this.tracking?"min":"max";this.scope.$evalAsync(function(){a.options.onStart(a.options.id,a.scope.rzSliderModel,a.scope.rzSliderHigh,b)})}},callOnChange:function(){if(this.options.onChange){var a=this,b="lowValue"===this.tracking?"min":"max";this.scope.$evalAsync(function(){a.options.onChange(a.options.id,a.scope.rzSliderModel,a.scope.rzSliderHigh,b)})}},callOnEnd:function(){if(this.options.onEnd){var a=this,b="lowValue"===this.tracking?"min":"max";this.scope.$evalAsync(function(){a.options.onEnd(a.options.id,a.scope.rzSliderModel,a.scope.rzSliderHigh,b)})}this.scope.$emit("slideEnded")}},h}]).directive("rzslider",["RzSlider",function(a){return{restrict:"AE",replace:!0,scope:{rzSliderModel:"=?",rzSliderHigh:"=?",rzSliderOptions:"&?",rzSliderTplUrl:"@"},templateUrl:function(a,b){return b.rzSliderTplUrl||"rzSliderTpl.html"},link:function(b,c){b.slider=new a(b,c)}}}]);return b.run(["$templateCache",function(a){a.put("rzSliderTpl.html",'
  • {{ t.value }} {{ t.legend }}
')}]),b.name}); \ No newline at end of file diff --git a/karma.conf.js b/karma.conf.js index f89ca40..952482e 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -8,7 +8,11 @@ module.exports = function (config) { // testing framework to use (jasmine/mocha/qunit/...) frameworks: ['mocha', 'sinon', 'chai'], - reporters: ['dots', 'coverage'], + reporters: ['mocha', 'coverage'], + + mochaReporter: { + showDiff: true + }, // list of files / patterns to load in the browser files: [ diff --git a/package.json b/package.json index cbdf902..9d9f9e7 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "devDependencies": { "angular": "1.4.7", "angular-mocks": "1.4.8", - "chai": "^3.4.1", + "chai": "^3.5.0", "codecov.io": "^0.1.6", "commitizen": "^2.4.6", "cz-conventional-changelog": "^1.1.5", @@ -43,10 +43,11 @@ "karma-chrome-launcher": "^0.2.2", "karma-coverage": "^0.5.3", "karma-mocha": "^0.2.1", + "karma-mocha-reporter": "^2.2.0", "karma-ng-html2js-preprocessor": "^0.2.0", "karma-phantomjs-launcher": "^1.0.2", "karma-sinon": "^1.0.4", - "mocha": "^2.3.4", + "mocha": "^3.1.2", "phantomjs": "^1.9.19", "recess": "~1.1.9", "sinon": "^1.17.2" diff --git a/src/rzslider.js b/src/rzslider.js index 7146514..1784479 100644 --- a/src/rzslider.js +++ b/src/rzslider.js @@ -66,7 +66,6 @@ getTickColor: null, getPointerColor: null, keyboardSupport: true, - logScale: false, scale: 1, enforceStep: true, enforceRange: false, @@ -78,7 +77,10 @@ rightToLeft: false, boundPointerLabels: true, mergeRangeLabelsIfSame: false, - customTemplateScope: null + customTemplateScope: null, + logScale: false, + customValueToPosition: null, + customPositionToValue: null }; var globalOptions = {}; @@ -202,7 +204,7 @@ active: false, value: 0, difference: 0, - offset: 0, + position: 0, lowLimit: 0, highLimit: 0 }; @@ -503,7 +505,7 @@ if (this.range) this.syncHighValue(); this.setMinAndMax(); - this.updateLowHandle(this.valueToOffset(this.lowValue)); + this.updateLowHandle(this.valueToPosition(this.lowValue)); this.updateSelectionBar(); this.updateTicksScale(); this.updateAriaAttributes(); @@ -519,7 +521,7 @@ this.syncLowValue(); this.syncHighValue(); this.setMinAndMax(); - this.updateHighHandle(this.valueToOffset(this.highValue)); + this.updateHighHandle(this.valueToPosition(this.highValue)); this.updateSelectionBar(); this.updateTicksScale(); this.updateCmbLabel(); @@ -674,7 +676,7 @@ }, this); - // Initialize offset cache properties + // Initialize position cache properties this.selBar.rzsp = 0; this.minH.rzsp = 0; this.maxH.rzsp = 0; @@ -768,14 +770,14 @@ * @returns {undefined} */ initHandles: function() { - this.updateLowHandle(this.valueToOffset(this.lowValue)); + this.updateLowHandle(this.valueToPosition(this.lowValue)); /* the order here is important since the selection bar should be updated after the high handle but before the combined label */ if (this.range) - this.updateHighHandle(this.valueToOffset(this.highValue)); + this.updateHighHandle(this.valueToPosition(this.highValue)); this.updateSelectionBar(); if (this.range) this.updateCmbLabel(); @@ -838,7 +840,7 @@ this.minValue = this.options.floor; if (this.options.logScale && this.minValue === 0) - throw new Error("Can't use floor=0 with logarithmic scale"); + throw Error("Can't use floor=0 with logarithmic scale"); if (this.options.enforceStep) { this.lowValue = this.roundStep(this.lowValue); @@ -953,19 +955,19 @@ translate = this.options.vertical ? 'translateY' : 'translateX', self = this; - if(this.options.rightToLeft) + if (this.options.rightToLeft) ticksArray.reverse(); - this.scope.ticks = ticksArray.map(function(value){ - var offset = self.valueToOffset(value); + this.scope.ticks = ticksArray.map(function(value) { + var position = self.valueToPosition(value); if (self.options.vertical) - offset = self.maxPos - offset; + position = self.maxPos - position; var tick = { selected: self.isTickSelected(value), style: { - transform: translate + '(' + offset + 'px)' + transform: translate + '(' + position + 'px)' } }; if (tick.selected && self.options.getSelectionBarColor) { @@ -1054,13 +1056,13 @@ * Update slider handles and label positions * * @param {string} which - * @param {number} newOffset + * @param {number} newPos */ - updateHandles: function(which, newOffset) { + updateHandles: function(which, newPos) { if (which === 'lowValue') - this.updateLowHandle(newOffset); + this.updateLowHandle(newPos); else - this.updateHighHandle(newOffset); + this.updateHighHandle(newPos); this.updateSelectionBar(); this.updateTicksScale(); @@ -1072,13 +1074,13 @@ * Helper function to work out the position for handle labels depending on RTL or not * * @param {string} labelName maxLab or minLab - * @param newOffset + * @param newPos * * @returns {number} */ - getHandleLabelPos: function(labelName, newOffset) { + getHandleLabelPos: function(labelName, newPos) { var labelRzsd = this[labelName].rzsd, - nearHandlePos = newOffset - labelRzsd / 2 + this.handleHalfDim, + nearHandlePos = newPos - labelRzsd / 2 + this.handleHalfDim, endOfBarPos = this.barDimension - labelRzsd; if (!this.options.boundPointerLabels) @@ -1094,13 +1096,13 @@ /** * Update low slider handle position and label * - * @param {number} newOffset + * @param {number} newPos * @returns {undefined} */ - updateLowHandle: function(newOffset) { - this.setPosition(this.minH, newOffset); + updateLowHandle: function(newPos) { + this.setPosition(this.minH, newPos); this.translateFn(this.lowValue, this.minLab, 'model'); - this.setPosition(this.minLab, this.getHandleLabelPos('minLab', newOffset)); + this.setPosition(this.minLab, this.getHandleLabelPos('minLab', newPos)); if (this.options.getPointerColor) { var pointercolor = this.getPointerColor('min'); @@ -1117,13 +1119,13 @@ /** * Update high slider handle position and label * - * @param {number} newOffset + * @param {number} newPos * @returns {undefined} */ - updateHighHandle: function(newOffset) { - this.setPosition(this.maxH, newOffset); + updateHighHandle: function(newPos) { + this.setPosition(this.maxH, newPos); this.translateFn(this.highValue, this.maxLab, 'high'); - this.setPosition(this.maxLab, this.getHandleLabelPos('maxLab', newOffset)); + this.setPosition(this.maxLab, this.getHandleLabelPos('maxLab', newPos)); if (this.options.getPointerColor) { var pointercolor = this.getPointerColor('max'); @@ -1221,7 +1223,7 @@ else { if (this.options.showSelectionBarFromValue !== null) { var center = this.options.showSelectionBarFromValue, - centerPosition = this.valueToOffset(center), + centerPosition = this.valueToPosition(center), isModelGreaterThanCenter = this.options.rightToLeft ? this.lowValue <= center : this.lowValue > center; if (isModelGreaterThanCenter) { dimension = this.minH.rzsp - centerPosition; @@ -1381,7 +1383,7 @@ }, /** - * Set element left/top offset depending on whether slider is horizontal or vertical + * Set element left/top position depending on whether slider is horizontal or vertical * * @param {jqLite} elem The jqLite wrapped DOM element * @param {number} pos @@ -1426,56 +1428,78 @@ }, /** - * Translate value to pixel offset + * Returns a value that is within slider range * * @param {number} val * @returns {number} */ - valueToOffset: function(val) { - var sanitizedValue = this.sanitizeValue(val), - minValue = this.options.logScale ? Math.log(this.minValue) : this.minValue, - maxValue = this.options.logScale ? Math.log(this.maxValue) : this.maxValue, - range = maxValue - minValue; - - if (this.options.logScale) - sanitizedValue = Math.log(sanitizedValue); - - if (this.options.rightToLeft) - return (maxValue - sanitizedValue) * this.maxPos / range || 0; - return (sanitizedValue - minValue) * this.maxPos / range || 0; + sanitizeValue: function(val) { + return Math.min(Math.max(val, this.minValue), this.maxValue); }, /** - * Returns a value that is within slider range + * Translate value to pixel position * * @param {number} val * @returns {number} */ - sanitizeValue: function(val) { - return Math.min(Math.max(val, this.minValue), this.maxValue); + valueToPosition: function(val) { + var fn = this.linearValueToPosition; + if (this.options.customValueToPosition) + fn = this.options.customValueToPosition; + else if (this.options.logScale) + fn = this.logValueToPosition; + + val = this.sanitizeValue(val); + var percent = fn(val, this.minValue, this.maxValue) || 0; + if(this.options.rightToLeft) + percent = 1 - percent; + return percent * this.maxPos; + }, + + linearValueToPosition: function(val, minVal, maxVal) { + var range = maxVal - minVal; + return (val - minVal) / range; + }, + + logValueToPosition: function(val, minVal, maxVal) { + val = Math.log(val); + minVal = Math.log(minVal); + maxVal = Math.log(maxVal); + var range = maxVal - minVal; + return (val - minVal) / range; }, /** - * Translate offset to model value + * Translate position to model value * - * @param {number} offset + * @param {number} position * @returns {number} */ - offsetToValue: function(offset) { - var minValue = this.options.logScale ? Math.log(this.minValue) : this.minValue, - maxValue = this.options.logScale ? Math.log(this.maxValue) : this.maxValue, - range = maxValue - minValue, - value = 0; - if (this.options.rightToLeft) - value = (1 - offset / this.maxPos) * range + minValue; - else - value = offset / this.maxPos * range + minValue; + positionToValue: function(position) { + var percent = position / this.maxPos; + if(this.options.rightToLeft) + percent = 1 - percent; + var fn = this.linearPositionToValue; + if (this.options.customPositionToValue) + fn = this.options.customPositionToValue; + else if (this.options.logScale) + fn = this.logPositionToValue; + return fn(percent, this.minValue, this.maxValue) || 0; + }, - return this.options.logScale ? Math.exp(value) : value; + linearPositionToValue: function(percent, minVal, maxVal) { + return percent * (maxVal - minVal) + minVal; }, - // Events + logPositionToValue: function(percent, minVal, maxVal) { + minVal = Math.log(minVal); + maxVal = Math.log(maxVal); + var value = percent * (maxVal - minVal) + minVal; + return Math.exp(value); + }, + // Events /** * Get the X-coordinate or Y-coordinate of an event * @@ -1543,19 +1567,19 @@ if (!this.range) { return this.minH; } - var offset = this.getEventPosition(event), - distanceMin = Math.abs(offset - this.minH.rzsp), - distanceMax = Math.abs(offset - this.maxH.rzsp); + var position = this.getEventPosition(event), + distanceMin = Math.abs(position - this.minH.rzsp), + distanceMax = Math.abs(position - this.maxH.rzsp); if (distanceMin < distanceMax) return this.minH; else if (distanceMin > distanceMax) return this.maxH; else if (!this.options.rightToLeft) //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; + return position < this.minH.rzsp ? this.minH : this.maxH; else //reverse in rtl - return offset > this.minH.rzsp ? this.minH : this.maxH; + return position > this.minH.rzsp ? this.minH : this.maxH; }, /** @@ -1696,17 +1720,17 @@ * @returns {undefined} */ onMove: function(pointer, event, fromTick) { - var newOffset = this.getEventPosition(event), + var newPos = this.getEventPosition(event), newValue, ceilValue = this.options.rightToLeft ? this.minValue : this.maxValue, flrValue = this.options.rightToLeft ? this.maxValue : this.minValue; - if (newOffset <= 0) { + if (newPos <= 0) { newValue = flrValue; - } else if (newOffset >= this.maxPos) { + } else if (newPos >= this.maxPos) { newValue = ceilValue; } else { - newValue = this.offsetToValue(newOffset); + newValue = this.positionToValue(newPos); if (fromTick && angular.isNumber(this.options.showTicks)) newValue = this.roundStep(newValue, this.options.showTicks); else @@ -1868,13 +1892,13 @@ * @returns {undefined} */ onDragStart: function(pointer, ref, event) { - var offset = this.getEventPosition(event); + var position = this.getEventPosition(event); this.dragging = { active: true, - value: this.offsetToValue(offset), + value: this.positionToValue(position), difference: this.highValue - this.lowValue, - lowLimit: this.options.rightToLeft ? this.minH.rzsp - offset : offset - this.minH.rzsp, - highLimit: this.options.rightToLeft ? offset - this.maxH.rzsp : this.maxH.rzsp - offset + lowLimit: this.options.rightToLeft ? this.minH.rzsp - position : position - this.minH.rzsp, + highLimit: this.options.rightToLeft ? position - this.maxH.rzsp : this.maxH.rzsp - position }; this.onStart(pointer, ref, event); @@ -1883,16 +1907,16 @@ /** * getValue helper function * - * gets max or min value depending on whether the newOffset is outOfBounds above or below the bar and rightToLeft + * gets max or min value depending on whether the newPos is outOfBounds above or below the bar and rightToLeft * * @param {string} type 'max' || 'min' The value we are calculating - * @param {number} newOffset The new offset - * @param {boolean} outOfBounds Is the new offset above or below the max/min? - * @param {boolean} isAbove Is the new offset above the bar if out of bounds? + * @param {number} newPos The new position + * @param {boolean} outOfBounds Is the new position above or below the max/min? + * @param {boolean} isAbove Is the new position above the bar if out of bounds? * * @returns {number} */ - getValue: function(type, newOffset, outOfBounds, isAbove) { + getValue: function(type, newPos, outOfBounds, isAbove) { var isRTL = this.options.rightToLeft, value = null; @@ -1904,7 +1928,7 @@ value = isRTL ? this.maxValue - this.dragging.difference : this.minValue; } } else { - value = isRTL ? this.offsetToValue(newOffset + this.dragging.lowLimit) : this.offsetToValue(newOffset - this.dragging.lowLimit) + value = isRTL ? this.positionToValue(newPos + this.dragging.lowLimit) : this.positionToValue(newPos - this.dragging.lowLimit) } } else { if (outOfBounds) { @@ -1915,9 +1939,9 @@ } } else { if (isRTL) { - value = this.offsetToValue(newOffset + this.dragging.lowLimit) + this.dragging.difference + value = this.positionToValue(newPos + this.dragging.lowLimit) + this.dragging.difference } else { - value = this.offsetToValue(newOffset - this.dragging.lowLimit) + this.dragging.difference; + value = this.positionToValue(newPos - this.dragging.lowLimit) + this.dragging.difference; } } } @@ -1934,7 +1958,7 @@ * @returns {undefined} */ onDragMove: function(pointer, event) { - var newOffset = this.getEventPosition(event), + var newPos = this.getEventPosition(event), newMinValue, newMaxValue, ceilLimit, flrLimit, isUnderFlrLimit, isOverCeilLimit, @@ -1951,28 +1975,28 @@ flrH = this.minH; ceilH = this.maxH; } - isUnderFlrLimit = newOffset <= flrLimit; - isOverCeilLimit = newOffset >= this.maxPos - ceilLimit; + isUnderFlrLimit = newPos <= flrLimit; + isOverCeilLimit = newPos >= this.maxPos - ceilLimit; if (isUnderFlrLimit) { if (flrH.rzsp === 0) return; - newMinValue = this.getValue('min', newOffset, true, false); - newMaxValue = this.getValue('max', newOffset, true, false); + newMinValue = this.getValue('min', newPos, true, false); + newMaxValue = this.getValue('max', newPos, true, false); } else if (isOverCeilLimit) { if (ceilH.rzsp === this.maxPos) return; - newMaxValue = this.getValue('max', newOffset, true, true); - newMinValue = this.getValue('min', newOffset, true, true); + newMaxValue = this.getValue('max', newPos, true, true); + newMinValue = this.getValue('min', newPos, true, true); } else { - newMinValue = this.getValue('min', newOffset, false); - newMaxValue = this.getValue('max', newOffset, false); + newMinValue = this.getValue('min', newPos, false); + newMaxValue = this.getValue('max', newPos, false); } this.positionTrackingBar(newMinValue, newMaxValue); }, /** - * Set the new value and offset for the entire bar + * Set the new value and position for the entire bar * * @param {number} newMinValue the new minimum value * @param {number} newMaxValue the new maximum value @@ -1994,12 +2018,12 @@ if (this.range) this.applyHighValue(); this.applyModel(); - this.updateHandles('lowValue', this.valueToOffset(newMinValue)); - this.updateHandles('highValue', this.valueToOffset(newMaxValue)); + this.updateHandles('lowValue', this.valueToPosition(newMinValue)); + this.updateHandles('highValue', this.valueToPosition(newMaxValue)); }, /** - * Set the new value and offset to the current tracking handle + * Set the new value and position to the current tracking handle * * @param {number} newValue new model value */ @@ -2054,7 +2078,7 @@ this.applyLowValue(); else this.applyHighValue(); - this.updateHandles(this.tracking, this.valueToOffset(newValue)); + this.updateHandles(this.tracking, this.valueToPosition(newValue)); this.updateAriaAttributes(); valueChanged = true; } @@ -2101,13 +2125,13 @@ this.highValue = Math.min(newValue + range, this.maxValue); newValue = this.highValue - range; this.applyHighValue(); - this.updateHandles('highValue', this.valueToOffset(this.highValue)); + this.updateHandles('highValue', this.valueToPosition(this.highValue)); } else { this.lowValue = Math.max(newValue - range, this.minValue); newValue = this.lowValue + range; this.applyLowValue(); - this.updateHandles('lowValue', this.valueToOffset(this.lowValue)); + this.updateHandles('lowValue', this.valueToPosition(this.lowValue)); } this.updateAriaAttributes(); } @@ -2222,7 +2246,7 @@ /** * @name jqLite * - * @property {number|undefined} rzsp rzslider label position offset + * @property {number|undefined} rzsp rzslider label position position * @property {number|undefined} rzsd rzslider element dimension * @property {string|undefined} rzsv rzslider label value/text * @property {Function} css diff --git a/tests/specs/helper-functions-test.js b/tests/specs/helper-functions-test.js index 353b325..77cc084 100644 --- a/tests/specs/helper-functions-test.js +++ b/tests/specs/helper-functions-test.js @@ -199,23 +199,23 @@ expect(el.css('height')).to.equal('12px'); }); - it('should have a valid valueToOffset for positive sliders', function() { + it('should have a valid valueToPosition for positive sliders', function() { helper.slider.maxPos = 1000; - expect(helper.slider.valueToOffset(0)).to.equal(0); - expect(helper.slider.valueToOffset(50)).to.equal(500); - expect(helper.slider.valueToOffset(100)).to.equal(1000); + expect(helper.slider.valueToPosition(0)).to.equal(0); + expect(helper.slider.valueToPosition(50)).to.equal(500); + expect(helper.slider.valueToPosition(100)).to.equal(1000); }); - it('should have a valid valueToOffset for negative sliders', function() { + it('should have a valid valueToPosition for negative sliders', function() { helper.scope.slider.options.floor = -100; helper.scope.slider.options.ceil = 0; helper.scope.slider.value = -50; helper.scope.$digest(); helper.slider.maxPos = 1000; - expect(helper.slider.valueToOffset(0)).to.equal(1000); - expect(helper.slider.valueToOffset(-50)).to.equal(500); - expect(helper.slider.valueToOffset(-100)).to.equal(0); + expect(helper.slider.valueToPosition(0)).to.equal(1000); + expect(helper.slider.valueToPosition(-50)).to.equal(500); + expect(helper.slider.valueToPosition(-100)).to.equal(0); }); it('should have a valid sanitizeValue', function() { @@ -228,23 +228,23 @@ expect(helper.slider.sanitizeValue(110)).to.equal(100); }); - it('should have a valid offsetToValue for positive sliders', function() { + it('should have a valid positionToValue for positive sliders', function() { helper.slider.maxPos = 1000; - expect(helper.slider.offsetToValue(0)).to.equal(0); - expect(helper.slider.offsetToValue(1000)).to.equal(100); - expect(helper.slider.offsetToValue(500)).to.equal(50); + expect(helper.slider.positionToValue(0)).to.equal(0); + expect(helper.slider.positionToValue(1000)).to.equal(100); + expect(helper.slider.positionToValue(500)).to.equal(50); }); - it('should have a valid offsetToValue for for negative sliders', function() { + it('should have a valid positionToValue for for negative sliders', function() { helper.scope.slider.options.floor = -100; helper.scope.slider.options.ceil = 0; helper.scope.slider.value = -50; helper.scope.$digest(); helper.slider.maxPos = 1000; - expect(helper.slider.offsetToValue(0)).to.equal(-100); - expect(helper.slider.offsetToValue(1000)).to.equal(0); - expect(helper.slider.offsetToValue(500)).to.equal(-50); + expect(helper.slider.positionToValue(0)).to.equal(-100); + expect(helper.slider.positionToValue(1000)).to.equal(0); + expect(helper.slider.positionToValue(500)).to.equal(-50); }); it('should have a valid getEventXY for horizontal sliders on desktop browsers', function() { @@ -668,42 +668,42 @@ helper.createSlider(sliderConf); }); - it('should have a valid valueToOffset for positive sliders', function() { + it('should have a valid valueToPosition for positive sliders', function() { helper.slider.maxPos = 1000; - expect(helper.slider.valueToOffset(0)).to.equal(1000); - expect(helper.slider.valueToOffset(50)).to.equal(500); - expect(helper.slider.valueToOffset(100)).to.equal(0); + expect(helper.slider.valueToPosition(0)).to.equal(1000); + expect(helper.slider.valueToPosition(50)).to.equal(500); + expect(helper.slider.valueToPosition(100)).to.equal(0); }); - it('should have a valid valueToOffset for negative sliders', function() { + it('should have a valid valueToPosition for negative sliders', function() { helper.scope.slider.options.floor = -100; helper.scope.slider.options.ceil = 0; helper.scope.slider.value = -50; helper.scope.$digest(); helper.slider.maxPos = 1000; - expect(helper.slider.valueToOffset(0)).to.equal(0); - expect(helper.slider.valueToOffset(-50)).to.equal(500); - expect(helper.slider.valueToOffset(-100)).to.equal(1000); + expect(helper.slider.valueToPosition(0)).to.equal(0); + expect(helper.slider.valueToPosition(-50)).to.equal(500); + expect(helper.slider.valueToPosition(-100)).to.equal(1000); }); - it('should have a valid offsetToValue for positive sliders', function() { + it('should have a valid positionToValue for positive sliders', function() { helper.slider.maxPos = 1000; - expect(helper.slider.offsetToValue(0)).to.equal(100); - expect(helper.slider.offsetToValue(1000)).to.equal(0); - expect(helper.slider.offsetToValue(500)).to.equal(50); + expect(helper.slider.positionToValue(0)).to.equal(100); + expect(helper.slider.positionToValue(1000)).to.equal(0); + expect(helper.slider.positionToValue(500)).to.equal(50); }); - it('should have a valid offsetToValue for for negative sliders', function() { + it('should have a valid positionToValue for for negative sliders', function() { helper.scope.slider.options.floor = -100; helper.scope.slider.options.ceil = 0; helper.scope.slider.value = -50; helper.scope.$digest(); helper.slider.maxPos = 1000; - expect(helper.slider.offsetToValue(0)).to.equal(0); - expect(helper.slider.offsetToValue(1000)).to.equal(-100); - expect(helper.slider.offsetToValue(500)).to.equal(-50); + expect(helper.slider.positionToValue(0)).to.equal(0); + expect(helper.slider.positionToValue(1000)).to.equal(-100); + expect(helper.slider.positionToValue(500)).to.equal(-50); }); }); }); diff --git a/tests/specs/helper.js b/tests/specs/helper.js index cb1f9cf..e7e6adc 100644 --- a/tests/specs/helper.js +++ b/tests/specs/helper.js @@ -123,7 +123,7 @@ }; h.getMousePosition = function(value) { - return h.slider.valueToOffset(value) + h.slider.handleHalfDim + h.slider.sliderElem.rzsp; + return h.slider.valueToPosition(value) + h.slider.handleHalfDim + h.slider.sliderElem.rzsp; }; h.moveMouseToValue = function(value) { diff --git a/tests/specs/mouse-controls/draggable-range-slider-horizontal-test.js b/tests/specs/mouse-controls/draggable-range-slider-horizontal-test.js index 6747417..2e459cb 100644 --- a/tests/specs/mouse-controls/draggable-range-slider-horizontal-test.js +++ b/tests/specs/mouse-controls/draggable-range-slider-horizontal-test.js @@ -84,9 +84,9 @@ sinon.spy(helper.slider, 'focusElement'); var expectedValue = 10, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - var event = helper.fireMousedown(helper.slider.fullBar, offset); + var event = helper.fireMousedown(helper.slider.fullBar, position); expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -103,9 +103,9 @@ sinon.spy(helper.slider, 'focusElement'); var expectedValue = 90, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - var event = helper.fireMousedown(helper.slider.fullBar, offset); + var event = helper.fireMousedown(helper.slider.fullBar, position); expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('highValue'); @@ -124,8 +124,8 @@ helper.fireMousedown(helper.slider.selBar, 0); var moveValue = 10, - offset = helper.slider.valueToOffset(moveValue); - helper.fireMousemove(offset); + position = helper.slider.valueToPosition(moveValue); + helper.fireMousemove(position); expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.max).to.equal(70); @@ -187,14 +187,14 @@ it('should a working positionTrackingBar', function() { var newMin = 50, newMax = 90, - minOffset = helper.slider.valueToOffset(newMin), - maxOffset = helper.slider.valueToOffset(newMax); - helper.slider.positionTrackingBar(newMin, newMax, minOffset, maxOffset); + minposition = helper.slider.valueToPosition(newMin), + maxposition = helper.slider.valueToPosition(newMax); + helper.slider.positionTrackingBar(newMin, newMax, minposition, maxposition); expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.max).to.equal(90); - expect(helper.slider.minH.css('left')).to.equal(minOffset + 'px'); - expect(helper.slider.maxH.css('left')).to.equal(maxOffset + 'px'); + expect(helper.slider.minH.css('left')).to.equal(minposition + 'px'); + expect(helper.slider.maxH.css('left')).to.equal(maxposition + 'px'); }); it('should respect minLimit option', function() { @@ -262,8 +262,8 @@ sinon.spy(helper.slider, 'callOnChange'); var event = helper.fireMousedown(helper.slider.minH, 0); var expectedValue = 50, - offset = helper.getMousePosition(expectedValue); - helper.fireMousemove(offset); + position = helper.getMousePosition(expectedValue); + helper.fireMousemove(position); expect(helper.scope.slider.min).to.equal(expectedValue); helper.slider.positionTrackingHandle.called.should.be.true; helper.slider.callOnChange.called.should.be.true; @@ -274,8 +274,8 @@ sinon.spy(helper.slider, 'callOnChange'); var event = helper.fireMousedown(helper.slider.maxH, 0); var expectedValue = 50, - offset = helper.getMousePosition(expectedValue); - helper.fireMousemove(offset); + position = helper.getMousePosition(expectedValue); + helper.fireMousemove(position); expect(helper.scope.slider.max).to.equal(expectedValue); helper.slider.positionTrackingHandle.called.should.be.true; helper.slider.callOnChange.called.should.be.true; @@ -284,8 +284,8 @@ it('should handle click and drag on minH and switch min/max if needed', function() { var event = helper.fireMousedown(helper.slider.minH, 0); var expectedValue = 80, - offset = helper.getMousePosition(expectedValue); - helper.fireMousemove(offset); + position = helper.getMousePosition(expectedValue); + helper.fireMousemove(position); expect(helper.scope.slider.min).to.equal(60); expect(helper.scope.slider.max).to.equal(80); @@ -294,8 +294,8 @@ it('should handle click and drag on maxH and switch min/max if needed', function() { var event = helper.fireMousedown(helper.slider.maxH, 0); var expectedValue = 20, - offset = helper.getMousePosition(expectedValue); - helper.fireMousemove(offset); + position = helper.getMousePosition(expectedValue); + helper.fireMousemove(position); expect(helper.scope.slider.min).to.equal(20); expect(helper.scope.slider.max).to.equal(40); @@ -308,9 +308,9 @@ sinon.spy(helper.slider, 'focusElement'); var expectedValue = 10, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - var event = helper.fireMousedown(helper.slider.fullBar, offset); + var event = helper.fireMousedown(helper.slider.fullBar, position); expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -327,9 +327,9 @@ sinon.spy(helper.slider, 'focusElement'); var expectedValue = 90, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - var event = helper.fireMousedown(helper.slider.fullBar, offset); + var event = helper.fireMousedown(helper.slider.fullBar, position); expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('highValue'); @@ -348,8 +348,8 @@ helper.fireMousedown(helper.slider.selBar, 0); var moveValue = 10, - offset = helper.slider.maxPos - helper.slider.valueToOffset(moveValue); - helper.fireMousemove(offset); + position = helper.slider.maxPos - helper.slider.valueToPosition(moveValue); + helper.fireMousemove(position); expect(helper.scope.slider.min).to.equal(30); expect(helper.scope.slider.max).to.equal(50); @@ -411,14 +411,14 @@ it('should a working positionTrackingBar', function() { var newMin = 50, newMax = 90, - minOffset = helper.slider.valueToOffset(newMin), - maxOffset = helper.slider.valueToOffset(newMax); - helper.slider.positionTrackingBar(newMin, newMax, minOffset, maxOffset); + minposition = helper.slider.valueToPosition(newMin), + maxposition = helper.slider.valueToPosition(newMax); + helper.slider.positionTrackingBar(newMin, newMax, minposition, maxposition); expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.max).to.equal(90); - expect(helper.slider.minH.css('left')).to.equal(minOffset + 'px'); - expect(helper.slider.maxH.css('left')).to.equal(maxOffset + 'px'); + expect(helper.slider.minH.css('left')).to.equal(minposition + 'px'); + expect(helper.slider.maxH.css('left')).to.equal(maxposition + 'px'); }); }); }()); diff --git a/tests/specs/mouse-controls/draggableOnly-range-slider-horizontal-test.js b/tests/specs/mouse-controls/draggableOnly-range-slider-horizontal-test.js index 846827a..2e02108 100644 --- a/tests/specs/mouse-controls/draggableOnly-range-slider-horizontal-test.js +++ b/tests/specs/mouse-controls/draggableOnly-range-slider-horizontal-test.js @@ -43,8 +43,8 @@ var event = helper.fireMousedown(helper.slider.minH, 0); var moveValue = 10, - offset = helper.slider.valueToOffset(moveValue); - helper.fireMousemove(offset); + position = helper.slider.valueToPosition(moveValue); + helper.fireMousemove(position); expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.max).to.equal(70); @@ -57,8 +57,8 @@ sinon.spy(helper.slider, 'callOnChange'); var event = helper.fireMousedown(helper.slider.maxH, 0); var moveValue = 10, - offset = helper.slider.valueToOffset(moveValue); - helper.fireMousemove(offset); + position = helper.slider.valueToPosition(moveValue); + helper.fireMousemove(position); expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.max).to.equal(70); helper.slider.positionTrackingBar.called.should.be.true; @@ -69,9 +69,9 @@ sinon.spy(helper.slider, 'callOnStart'); var moveValue = 10, - offset = helper.slider.valueToOffset(moveValue); + position = helper.slider.valueToPosition(moveValue); - var event = helper.fireMousedown(helper.slider.fullBar, offset); + var event = helper.fireMousedown(helper.slider.fullBar, position); expect(helper.scope.slider.min).to.equal(40); expect(helper.scope.slider.max).to.equal(60); @@ -88,8 +88,8 @@ helper.fireMousedown(helper.slider.selBar, 0); var moveValue = 10, - offset = helper.slider.valueToOffset(moveValue); - helper.fireMousemove(offset); + position = helper.slider.valueToPosition(moveValue); + helper.fireMousemove(position); expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.max).to.equal(70); @@ -207,8 +207,8 @@ var event = helper.fireMousedown(helper.slider.minH, 0); var moveValue = 10, - offset = helper.slider.valueToOffset(moveValue); - helper.fireMousemove(offset); + position = helper.slider.valueToPosition(moveValue); + helper.fireMousemove(position); expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.max).to.equal(70); @@ -221,8 +221,8 @@ sinon.spy(helper.slider, 'callOnChange'); var event = helper.fireMousedown(helper.slider.maxH, 0); var moveValue = 10, - offset = helper.slider.valueToOffset(moveValue); - helper.fireMousemove(offset); + position = helper.slider.valueToPosition(moveValue); + helper.fireMousemove(position); expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.max).to.equal(70); helper.slider.positionTrackingBar.called.should.be.true; @@ -233,9 +233,9 @@ sinon.spy(helper.slider, 'callOnStart'); var moveValue = 10, - offset = helper.slider.valueToOffset(moveValue); + position = helper.slider.valueToPosition(moveValue); - var event = helper.fireMousedown(helper.slider.fullBar, offset); + var event = helper.fireMousedown(helper.slider.fullBar, position); expect(helper.scope.slider.min).to.equal(40); expect(helper.scope.slider.max).to.equal(60); @@ -252,8 +252,8 @@ helper.fireMousedown(helper.slider.selBar, 0); var moveValue = 10, - offset = helper.slider.valueToOffset(moveValue); - helper.fireMousemove(offset); + position = helper.slider.valueToPosition(moveValue); + helper.fireMousemove(position); expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.max).to.equal(70); diff --git a/tests/specs/mouse-controls/minMaxRange-noSwitching-range-slider-horizontal-test.js b/tests/specs/mouse-controls/minMaxRange-noSwitching-range-slider-horizontal-test.js index db7cd5f..58bd1e4 100644 --- a/tests/specs/mouse-controls/minMaxRange-noSwitching-range-slider-horizontal-test.js +++ b/tests/specs/mouse-controls/minMaxRange-noSwitching-range-slider-horizontal-test.js @@ -163,16 +163,16 @@ it('should not modify any value if new range would be smaller than minRange when moving minH', function() { helper.fireMousedown(helper.slider.minH, 0); var expectedValue = 50, - offset = helper.getMousePosition(expectedValue); - helper.fireMousemove(-offset); + position = helper.getMousePosition(expectedValue); + helper.fireMousemove(-position); expect(helper.scope.slider.min).to.equal(45); }); it('should not modify any value if new range would be smaller than minRange when moving maxH', function() { helper.fireMousedown(helper.slider.maxH, 0); var expectedValue = 50, - offset = helper.slider.maxPos - helper.getMousePosition(expectedValue); - helper.fireMousemove(offset); + position = helper.slider.maxPos - helper.getMousePosition(expectedValue); + helper.fireMousemove(position); expect(helper.scope.slider.max).to.equal(55); }); @@ -193,8 +193,8 @@ it('should not switch min/max when moving minH even if the range is large enough', function() { helper.fireMousedown(helper.slider.minH, 0); var expectedValue = 80, - offset = helper.getMousePosition(expectedValue); - helper.fireMousemove(-offset); + position = helper.getMousePosition(expectedValue); + helper.fireMousemove(-position); expect(helper.scope.slider.min).to.equal(45); expect(helper.scope.slider.max).to.equal(55); }); diff --git a/tests/specs/mouse-controls/noSwitching-range-slider-horizontal-test.js b/tests/specs/mouse-controls/noSwitching-range-slider-horizontal-test.js index 76c7f58..013e6e0 100644 --- a/tests/specs/mouse-controls/noSwitching-range-slider-horizontal-test.js +++ b/tests/specs/mouse-controls/noSwitching-range-slider-horizontal-test.js @@ -56,9 +56,9 @@ helper.scope.$digest(); var expectedValue = 30, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - helper.fireMousedown(helper.slider.fullBar, offset); + helper.fireMousedown(helper.slider.fullBar, position); expect(helper.scope.slider.min).to.equal(30); expect(helper.scope.slider.max).to.equal(50); @@ -69,9 +69,9 @@ helper.scope.$digest(); var expectedValue = 70, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - helper.fireMousedown(helper.slider.fullBar, offset); + helper.fireMousedown(helper.slider.fullBar, position); expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.max).to.equal(70); @@ -134,9 +134,9 @@ helper.scope.$digest(); var expectedValue = 30, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - helper.fireMousedown(helper.slider.fullBar, offset); + helper.fireMousedown(helper.slider.fullBar, position); expect(helper.scope.slider.min).to.equal(30); expect(helper.scope.slider.max).to.equal(50); @@ -147,9 +147,9 @@ helper.scope.$digest(); var expectedValue = 70, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - helper.fireMousedown(helper.slider.fullBar, offset); + helper.fireMousedown(helper.slider.fullBar, position); expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.max).to.equal(70); diff --git a/tests/specs/mouse-controls/range-slider-horizontal-test.js b/tests/specs/mouse-controls/range-slider-horizontal-test.js index e5918b4..fa3f4da 100644 --- a/tests/specs/mouse-controls/range-slider-horizontal-test.js +++ b/tests/specs/mouse-controls/range-slider-horizontal-test.js @@ -197,9 +197,9 @@ sinon.spy(helper.slider, 'focusElement'); var expectedValue = 10, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - var event = helper.fireMousedown(helper.slider.fullBar, offset); + var event = helper.fireMousedown(helper.slider.fullBar, position); expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -216,9 +216,9 @@ sinon.spy(helper.slider, 'focusElement'); var expectedValue = 90, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - var event = helper.fireMousedown(helper.slider.fullBar, offset); + var event = helper.fireMousedown(helper.slider.fullBar, position); expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('highValue'); @@ -235,9 +235,9 @@ sinon.spy(helper.slider, 'focusElement'); var expectedValue = 10, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - var event = helper.fireMousedown(helper.slider.selBar, offset); + var event = helper.fireMousedown(helper.slider.selBar, position); expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -254,9 +254,9 @@ sinon.spy(helper.slider, 'focusElement'); var expectedValue = 90, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - var event = helper.fireMousedown(helper.slider.selBar, offset); + var event = helper.fireMousedown(helper.slider.selBar, position); expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('highValue'); @@ -464,9 +464,9 @@ sinon.spy(helper.slider, 'focusElement'); var expectedValue = 10, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - var event = helper.fireMousedown(helper.slider.fullBar, offset); + var event = helper.fireMousedown(helper.slider.fullBar, position); expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -483,9 +483,9 @@ sinon.spy(helper.slider, 'focusElement'); var expectedValue = 90, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - var event = helper.fireMousedown(helper.slider.fullBar, offset); + var event = helper.fireMousedown(helper.slider.fullBar, position); expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('highValue'); @@ -502,9 +502,9 @@ sinon.spy(helper.slider, 'focusElement'); var expectedValue = 10, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - var event = helper.fireMousedown(helper.slider.selBar, offset); + var event = helper.fireMousedown(helper.slider.selBar, position); expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -521,9 +521,9 @@ sinon.spy(helper.slider, 'focusElement'); var expectedValue = 90, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - var event = helper.fireMousedown(helper.slider.selBar, offset); + var event = helper.fireMousedown(helper.slider.selBar, position); expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('highValue'); diff --git a/tests/specs/mouse-controls/range-slider-vertical-test.js b/tests/specs/mouse-controls/range-slider-vertical-test.js index 2560662..d279ed8 100644 --- a/tests/specs/mouse-controls/range-slider-vertical-test.js +++ b/tests/specs/mouse-controls/range-slider-vertical-test.js @@ -112,8 +112,8 @@ sinon.spy(helper.slider, 'callOnChange'); var event = helper.fireMousedown(helper.slider.minH, 0, true); var expectedValue = 50, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; - helper.fireMousemove(offset, true); + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; + helper.fireMousemove(position, true); expect(helper.scope.slider.min).to.equal(expectedValue); helper.slider.positionTrackingHandle.called.should.be.true; helper.slider.callOnChange.called.should.be.true; @@ -124,8 +124,8 @@ sinon.spy(helper.slider, 'callOnChange'); var event = helper.fireMousedown(helper.slider.maxH, 0, true); var expectedValue = 50, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; - helper.fireMousemove(offset, true); + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; + helper.fireMousemove(position, true); expect(helper.scope.slider.max).to.equal(expectedValue); helper.slider.positionTrackingHandle.called.should.be.true; helper.slider.callOnChange.called.should.be.true; @@ -138,8 +138,8 @@ var event = helper.fireMousedown(helper.slider.minH, 0, true); var expectedValue = 80, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; - helper.fireMousemove(offset, true); + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; + helper.fireMousemove(position, true); expect(helper.scope.slider.min).to.equal(60); expect(helper.scope.slider.max).to.equal(80); @@ -152,8 +152,8 @@ var event = helper.fireMousedown(helper.slider.maxH, 0, true); var expectedValue = 20, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; - helper.fireMousemove(offset, true); + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; + helper.fireMousemove(position, true); expect(helper.scope.slider.min).to.equal(20); expect(helper.scope.slider.max).to.equal(40); @@ -166,9 +166,9 @@ sinon.spy(helper.slider, 'focusElement'); var expectedValue = 10, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; - var event = helper.fireMousedown(helper.slider.fullBar, offset, true); + var event = helper.fireMousedown(helper.slider.fullBar, position, true); expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -185,9 +185,9 @@ sinon.spy(helper.slider, 'focusElement'); var expectedValue = 90, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; - var event = helper.fireMousedown(helper.slider.fullBar, offset, true); + var event = helper.fireMousedown(helper.slider.fullBar, position, true); expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('highValue'); @@ -204,9 +204,9 @@ sinon.spy(helper.slider, 'focusElement'); var expectedValue = 10, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; - var event = helper.fireMousedown(helper.slider.selBar, offset, true); + var event = helper.fireMousedown(helper.slider.selBar, position, true); expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -223,9 +223,9 @@ sinon.spy(helper.slider, 'focusElement'); var expectedValue = 90, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; - var event = helper.fireMousedown(helper.slider.selBar, offset, true); + var event = helper.fireMousedown(helper.slider.selBar, position, true); expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('highValue'); @@ -348,8 +348,8 @@ sinon.spy(helper.slider, 'callOnChange'); var event = helper.fireMousedown(helper.slider.minH, 0, true); var expectedValue = 50, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; - helper.fireMousemove(offset, true); + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; + helper.fireMousemove(position, true); expect(helper.scope.slider.min).to.equal(expectedValue); helper.slider.positionTrackingHandle.called.should.be.true; helper.slider.callOnChange.called.should.be.true; @@ -360,8 +360,8 @@ sinon.spy(helper.slider, 'callOnChange'); var event = helper.fireMousedown(helper.slider.maxH, 0, true); var expectedValue = 50, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; - helper.fireMousemove(offset, true); + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; + helper.fireMousemove(position, true); expect(helper.scope.slider.max).to.equal(expectedValue); helper.slider.positionTrackingHandle.called.should.be.true; helper.slider.callOnChange.called.should.be.true; @@ -374,8 +374,8 @@ var event = helper.fireMousedown(helper.slider.minH, 0, true); var expectedValue = 80, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; - helper.fireMousemove(offset, true); + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; + helper.fireMousemove(position, true); expect(helper.scope.slider.min).to.equal(60); expect(helper.scope.slider.max).to.equal(80); @@ -388,8 +388,8 @@ var event = helper.fireMousedown(helper.slider.maxH, 0, true); var expectedValue = 20, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; - helper.fireMousemove(offset, true); + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; + helper.fireMousemove(position, true); expect(helper.scope.slider.min).to.equal(20); expect(helper.scope.slider.max).to.equal(40); @@ -402,9 +402,9 @@ sinon.spy(helper.slider, 'focusElement'); var expectedValue = 10, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; - var event = helper.fireMousedown(helper.slider.fullBar, offset, true); + var event = helper.fireMousedown(helper.slider.fullBar, position, true); expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -421,9 +421,9 @@ sinon.spy(helper.slider, 'focusElement'); var expectedValue = 90, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; - var event = helper.fireMousedown(helper.slider.fullBar, offset, true); + var event = helper.fireMousedown(helper.slider.fullBar, position, true); expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('highValue'); @@ -440,9 +440,9 @@ sinon.spy(helper.slider, 'focusElement'); var expectedValue = 10, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; - var event = helper.fireMousedown(helper.slider.selBar, offset, true); + var event = helper.fireMousedown(helper.slider.selBar, position, true); expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -459,9 +459,9 @@ sinon.spy(helper.slider, 'focusElement'); var expectedValue = 90, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; - var event = helper.fireMousedown(helper.slider.selBar, offset, true); + var event = helper.fireMousedown(helper.slider.selBar, position, true); expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('highValue'); diff --git a/tests/specs/mouse-controls/single-slider-horizontal-test.js b/tests/specs/mouse-controls/single-slider-horizontal-test.js index db774a8..2996e7d 100644 --- a/tests/specs/mouse-controls/single-slider-horizontal-test.js +++ b/tests/specs/mouse-controls/single-slider-horizontal-test.js @@ -75,8 +75,8 @@ sinon.spy(helper.slider, 'callOnChange'); var event = helper.fireMousedown(helper.slider.minH, 0); var expectedValue = 50, - offset = helper.getMousePosition(expectedValue); - helper.fireMousemove(offset); + position = helper.getMousePosition(expectedValue); + helper.fireMousemove(position); expect(helper.scope.slider.value).to.equal(expectedValue); helper.slider.positionTrackingHandle.called.should.be.true; helper.slider.callOnChange.called.should.be.true; @@ -136,9 +136,9 @@ sinon.spy(helper.slider, 'callOnChange'); var expectedValue = 12, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - helper.fireMousedown(helper.slider.fullBar, offset); + helper.fireMousedown(helper.slider.fullBar, position); expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -153,9 +153,9 @@ sinon.spy(helper.slider, 'callOnChange'); var expectedValue = 12, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - var event = helper.fireMousedown(helper.slider.selBar, offset); + var event = helper.fireMousedown(helper.slider.selBar, position); expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -173,9 +173,9 @@ sinon.spy(helper.slider, 'callOnChange'); var expectedValue = 10, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - helper.fireMousedown(helper.slider.ticks, offset); + helper.fireMousedown(helper.slider.ticks, position); expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -193,9 +193,9 @@ sinon.spy(helper.slider, 'callOnChange'); var expectedValue = 10, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - helper.fireMousedown(helper.slider.ticks, offset); + helper.fireMousedown(helper.slider.ticks, position); expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -280,8 +280,8 @@ sinon.spy(helper.slider, 'callOnChange'); var event = helper.fireMousedown(helper.slider.minH, 0); var expectedValue = 50, - offset = helper.getMousePosition(expectedValue); - helper.fireMousemove(offset); + position = helper.getMousePosition(expectedValue); + helper.fireMousemove(position); expect(helper.scope.slider.value).to.equal(expectedValue); helper.slider.positionTrackingHandle.called.should.be.true; helper.slider.callOnChange.called.should.be.true; @@ -340,9 +340,9 @@ sinon.spy(helper.slider, 'callOnChange'); var expectedValue = 12, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - helper.fireMousedown(helper.slider.fullBar, offset); + helper.fireMousedown(helper.slider.fullBar, position); expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -357,9 +357,9 @@ sinon.spy(helper.slider, 'callOnChange'); var expectedValue = 12, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - var event = helper.fireMousedown(helper.slider.selBar, offset); + var event = helper.fireMousedown(helper.slider.selBar, position); expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -377,9 +377,9 @@ sinon.spy(helper.slider, 'callOnChange'); var expectedValue = 10, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - helper.fireMousedown(helper.slider.ticks, offset); + helper.fireMousedown(helper.slider.ticks, position); expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -397,9 +397,9 @@ sinon.spy(helper.slider, 'callOnChange'); var expectedValue = 10, - offset = helper.getMousePosition(expectedValue); + position = helper.getMousePosition(expectedValue); - helper.fireMousedown(helper.slider.ticks, offset); + helper.fireMousedown(helper.slider.ticks, position); expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); diff --git a/tests/specs/mouse-controls/single-slider-vertical-test.js b/tests/specs/mouse-controls/single-slider-vertical-test.js index a7c132c..3bc083a 100644 --- a/tests/specs/mouse-controls/single-slider-vertical-test.js +++ b/tests/specs/mouse-controls/single-slider-vertical-test.js @@ -77,9 +77,9 @@ helper.fireMousedown(helper.slider.minH, 0, true); var expectedValue = 50, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; - helper.fireMousemove(offset, true); + helper.fireMousemove(position, true); expect(helper.scope.slider.value).to.equal(expectedValue); helper.slider.positionTrackingHandle.called.should.be.true; helper.slider.callOnChange.called.should.be.true; @@ -139,9 +139,9 @@ sinon.spy(helper.slider, 'callOnChange'); var expectedValue = 50, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; - var event = helper.fireMousedown(helper.slider.fullBar, offset, true); + var event = helper.fireMousedown(helper.slider.fullBar, position, true); expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -156,9 +156,9 @@ sinon.spy(helper.slider, 'callOnChange'); var expectedValue = 12, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; - helper.fireMousedown(helper.slider.selBar, offset, true); + helper.fireMousedown(helper.slider.selBar, position, true); expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -176,9 +176,9 @@ sinon.spy(helper.slider, 'callOnChange'); var expectedValue = 10, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; - helper.fireMousedown(helper.slider.ticks, offset, true); + helper.fireMousedown(helper.slider.ticks, position, true); expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -196,9 +196,9 @@ sinon.spy(helper.slider, 'callOnChange'); var expectedValue = 10, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; - helper.fireMousedown(helper.slider.ticks, offset, true); + helper.fireMousedown(helper.slider.ticks, position, true); expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -285,9 +285,9 @@ helper.fireMousedown(helper.slider.minH, 0, true); var expectedValue = 50, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; - helper.fireMousemove(offset, true); + helper.fireMousemove(position, true); expect(helper.scope.slider.value).to.equal(expectedValue); helper.slider.positionTrackingHandle.called.should.be.true; helper.slider.callOnChange.called.should.be.true; @@ -347,9 +347,9 @@ sinon.spy(helper.slider, 'callOnChange'); var expectedValue = 50, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; - var event = helper.fireMousedown(helper.slider.fullBar, offset, true); + var event = helper.fireMousedown(helper.slider.fullBar, position, true); expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -364,9 +364,9 @@ sinon.spy(helper.slider, 'callOnChange'); var expectedValue = 12, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; - helper.fireMousedown(helper.slider.selBar, offset, true); + helper.fireMousedown(helper.slider.selBar, position, true); expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -384,9 +384,9 @@ sinon.spy(helper.slider, 'callOnChange'); var expectedValue = 10, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; - helper.fireMousedown(helper.slider.ticks, offset, true); + helper.fireMousedown(helper.slider.ticks, position, true); expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); @@ -404,9 +404,9 @@ sinon.spy(helper.slider, 'callOnChange'); var expectedValue = 10, - offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; + position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim; - helper.fireMousedown(helper.slider.ticks, offset, true); + helper.fireMousedown(helper.slider.ticks, position, true); expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.slider.tracking).to.equal('lowValue'); diff --git a/tests/specs/options-handling-test.js b/tests/specs/options-handling-test.js index 18adf04..7e41286 100644 --- a/tests/specs/options-handling-test.js +++ b/tests/specs/options-handling-test.js @@ -223,7 +223,7 @@ {value: 'C', 'foo': 'barC'} ]; helper.scope.slider.options.translate = function(value, sliderId, label) { - return 'value: '+ value + return 'value: ' + value }; helper.scope.$digest(); expect(helper.slider.options.step).to.equal(1); @@ -312,7 +312,7 @@ } }; helper.createSlider(sliderConf); - var expectedDimension = helper.slider.valueToOffset(2) + helper.slider.handleHalfDim; + var expectedDimension = helper.slider.valueToPosition(2) + helper.slider.handleHalfDim; expect(helper.slider.selBar.css('width')).to.equal(expectedDimension + 'px'); expect(helper.slider.selBar.css('left')).to.equal('0px'); }); @@ -327,9 +327,11 @@ } }; helper.createSlider(sliderConf); - var expectedDimension = helper.slider.valueToOffset(8) + helper.slider.handleHalfDim, - expectedPosition = helper.slider.valueToOffset(2) + helper.slider.handleHalfDim; - expect(helper.slider.selBar.css('width')).to.equal(expectedDimension + 'px'); + var expectedDimension = Math.floor(helper.slider.valueToPosition(8) + helper.slider.handleHalfDim), + actualDimension = Math.floor(helper.slider.selBar[0].getBoundingClientRect().width); + expect(actualDimension).to.equal(expectedDimension); + + var expectedPosition = helper.slider.valueToPosition(2) + helper.slider.handleHalfDim; expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px'); }); @@ -343,8 +345,8 @@ } }; helper.createSlider(sliderConf); - var expectedDimension = helper.slider.valueToOffset(5), - expectedPosition = helper.slider.valueToOffset(10) + helper.slider.handleHalfDim; + var expectedDimension = helper.slider.valueToPosition(5), + expectedPosition = helper.slider.valueToPosition(10) + helper.slider.handleHalfDim; expect(helper.slider.selBar.css('width')).to.equal(expectedDimension + 'px'); expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px'); }); @@ -359,9 +361,11 @@ } }; helper.createSlider(sliderConf); - var expectedDimension = helper.slider.valueToOffset(7), - expectedPosition = helper.slider.valueToOffset(3) + helper.slider.handleHalfDim; - expect(helper.slider.selBar.css('width')).to.equal(expectedDimension + 'px'); + var expectedDimension = Math.floor(helper.slider.valueToPosition(7)), + actualDimension = Math.floor(helper.slider.selBar[0].getBoundingClientRect().width); + expect(actualDimension).to.equal(expectedDimension); + + var expectedPosition = helper.slider.valueToPosition(3) + helper.slider.handleHalfDim; expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px'); }); @@ -463,9 +467,12 @@ } }; helper.createRangeSlider(sliderConf); - var expectedDimension = helper.slider.valueToOffset(6), - expectedPosition = helper.slider.valueToOffset(2) + helper.slider.handleHalfDim; - expect(helper.slider.selBar.css('width')).to.equal(expectedDimension + 'px'); + + var expectedDimension = Math.floor(helper.slider.valueToPosition(6)), + actualDimension = Math.floor(helper.slider.selBar[0].getBoundingClientRect().width); + expect(actualDimension).to.equal(expectedDimension); + + var expectedPosition = helper.slider.valueToPosition(2) + helper.slider.handleHalfDim; expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px'); }); @@ -1073,10 +1080,10 @@ } }; helper.createSlider(sliderConf); - var expectedDimension = Math.floor(helper.slider.valueToOffset(8) + helper.slider.handleHalfDim), + var expectedDimension = Math.floor(helper.slider.valueToPosition(8) + helper.slider.handleHalfDim), actualDimension = Math.floor(helper.slider.selBar[0].getBoundingClientRect().width); expect(actualDimension).to.equal(expectedDimension); - expect(helper.slider.selBar.css('left')).to.equal(helper.slider.valueToOffset(2) + helper.slider.handleHalfDim + 'px'); + expect(helper.slider.selBar.css('left')).to.equal(helper.slider.valueToPosition(2) + helper.slider.handleHalfDim + 'px'); }); it('should set the correct dimension/position for selection bar for single slider with showSelectionBarEnd=true', function() { @@ -1090,8 +1097,9 @@ } }; helper.createSlider(sliderConf); - var expectedDimension = helper.slider.valueToOffset(2) + helper.slider.handleHalfDim; - expect(helper.slider.selBar.css('width')).to.equal(expectedDimension + 'px'); + var expectedDimension = Math.floor(helper.slider.valueToPosition(2) + helper.slider.handleHalfDim), + actualDimension = Math.floor(helper.slider.selBar[0].getBoundingClientRect().width); + expect(actualDimension).to.equal(expectedDimension); expect(helper.slider.selBar.css('left')).to.equal('0px'); }); @@ -1106,8 +1114,8 @@ } }; helper.createSlider(sliderConf); - var expectedDimension = helper.slider.valueToOffset(15), - expectedPosition = helper.slider.valueToOffset(15) + helper.slider.handleHalfDim; + var expectedDimension = helper.slider.valueToPosition(15), + expectedPosition = helper.slider.valueToPosition(15) + helper.slider.handleHalfDim; expect(helper.slider.selBar.css('width')).to.equal(expectedDimension + 'px'); expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px'); }); @@ -1123,9 +1131,9 @@ } }; helper.createSlider(sliderConf); - var expectedDimension = Math.floor(helper.slider.valueToOffset(13)), + var expectedDimension = Math.floor(helper.slider.valueToPosition(13)), actualDimension = Math.floor(helper.slider.selBar[0].getBoundingClientRect().width), - expectedPosition = helper.slider.valueToOffset(10) + helper.slider.handleHalfDim; + expectedPosition = helper.slider.valueToPosition(10) + helper.slider.handleHalfDim; expect(actualDimension).to.equal(expectedDimension); expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px'); }); @@ -1164,9 +1172,12 @@ rightToLeft: true }; helper.createRangeSlider(sliderConf); - var expectedDimension = helper.slider.valueToOffset(6), - expectedPosition = helper.slider.valueToOffset(2) + helper.slider.handleHalfDim; - expect(helper.slider.selBar.css('width')).to.equal(expectedDimension + 'px'); + + var expectedDimension = Math.floor(helper.slider.valueToPosition(6)), + actualDimension = Math.floor(helper.slider.selBar[0].getBoundingClientRect().width); + expect(actualDimension).to.equal(expectedDimension); + + var expectedPosition = helper.slider.valueToPosition(2) + helper.slider.handleHalfDim; expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px'); }); diff --git a/tests/specs/scale-test.js b/tests/specs/scale-test.js new file mode 100644 index 0000000..a409a5a --- /dev/null +++ b/tests/specs/scale-test.js @@ -0,0 +1,158 @@ +(function() { + "use strict"; + + describe('Scale test - ', function() { + var helper, + RzSliderOptions, + $rootScope, + $timeout; + + beforeEach(module('test-helper')); + + beforeEach(inject(function(TestHelper, _RzSliderOptions_, _$rootScope_, _$timeout_) { + helper = TestHelper; + RzSliderOptions = _RzSliderOptions_; + $rootScope = _$rootScope_; + $timeout = _$timeout_; + })); + + afterEach(function() { + helper.clean(); + }); + + describe('Linear scale - ', function() { + beforeEach(function() { + var sliderConf = { + value: 10, + options: { + floor: 0, + ceil: 100, + step: 10 + } + }; + helper.createSlider(sliderConf); + }); + + it('should have a correct linearValueToPosition', function() { + var actual = helper.slider.linearValueToPosition(0, 0, 50); + expect(actual).to.equal(0); + actual = helper.slider.linearValueToPosition(25, 0, 50); + expect(actual.toFixed(2)).to.equal('0.50'); + actual = helper.slider.linearValueToPosition(50, 0, 50); + expect(actual).to.equal(1); + }); + + it('should have a correct linearPositionToValue', function() { + var actual = helper.slider.linearPositionToValue(0, 0, 50); + expect(actual).to.equal(0); + actual = helper.slider.linearPositionToValue(0.5, 0, 50); + expect(actual).to.equal(25); + actual = Math.round(helper.slider.linearPositionToValue(1, 0, 50)); + expect(actual).to.equal(50); + }); + }); + + describe('Logarithm scale - ', function() { + beforeEach(function() { + var sliderConf = { + value: 10, + options: { + floor: 1, + ceil: 100, + step: 10, + logScale: true + } + }; + helper.createSlider(sliderConf); + }); + + it('should throw an error if floor is 0', function() { + var testFn = function() { + helper.scope.slider.options.floor = 0; + helper.scope.$digest(); + }; + expect(testFn).to.throw("Can't use floor=0 with logarithmic scale"); + }); + + it('should have a correct logValueToPosition', function() { + var actual = helper.slider.logValueToPosition(1, 1, 50); + expect(actual).to.equal(0); + actual = helper.slider.logValueToPosition(25, 1, 50); + expect(actual.toFixed(2)).to.equal('0.82'); + actual = helper.slider.logValueToPosition(50, 1, 50); + expect(actual).to.equal(1); + }); + + it('should have a correct logPositionToValue', function() { + var actual = helper.slider.logPositionToValue(0, 1, 50); + expect(actual).to.equal(1); + actual = helper.slider.logPositionToValue(0.5, 1, 50); + expect(actual.toFixed(2)).to.equal('7.07'); + actual = Math.round(helper.slider.logPositionToValue(1, 1, 50)); + expect(actual).to.equal(50); + }); + + it('should handle click and drag on minH correctly', function () { + helper.fireMousedown(helper.slider.minH, 0); + var expectedValue = 50, + position = helper.getMousePosition(expectedValue); + helper.fireMousemove(position); + expect(helper.scope.slider.value).to.equal(expectedValue + 1); // + 1 because we start at 1 + }); + }); + + describe('Custom scale (here a x^2 scale)- ', function() { + beforeEach(function() { + var sliderConf = { + value: 50, + options: { + floor: 0, + ceil: 100, + step: 10, + customValueToPosition: function(val, minVal, maxVal) { + val = Math.sqrt(val); + minVal = Math.sqrt(minVal); + maxVal = Math.sqrt(maxVal); + var range = maxVal - minVal; + return (val - minVal) / range; + }, + customPositionToValue: function(percent, minVal, maxVal) { + minVal = Math.sqrt(minVal); + maxVal = Math.sqrt(maxVal); + var value = percent * (maxVal - minVal) + minVal; + return Math.pow(value, 2); + } + } + }; + helper.createSlider(sliderConf); + }); +- + it('should have a correct valueToPosition', function() { + var actual = helper.slider.valueToPosition(0); + expect(actual).to.equal(0); + actual = helper.slider.valueToPosition(25); + expect(actual).to.equal(helper.slider.maxPos / 2); + actual = helper.slider.valueToPosition(100); + expect(actual).to.equal(helper.slider.maxPos); + }); + + it('should have a correct positionToValue', function() { + var actual = helper.slider.positionToValue(0); + expect(actual).to.equal(0); + actual = helper.slider.positionToValue(helper.slider.maxPos / 2); + expect(actual).to.equal(25); + actual = Math.round(helper.slider.positionToValue(helper.slider.maxPos)); + expect(actual).to.equal(100); + }); + + it('should handle click and drag on minH correctly', function () { + helper.fireMousedown(helper.slider.minH, 0); + var expectedValue = 50, + position = helper.getMousePosition(expectedValue); + helper.fireMousemove(position); + expect(helper.scope.slider.value).to.equal(expectedValue); + }); + }); + }); +}()); +