Commit 3ea789d6 authored by Rafal Zajac's avatar Rafal Zajac

Renames, documentation, cleanup

parent d190fd0e
/*! angularjs-slider - v0.0.1 - (c) Rafal Zajac <rzajac@gmail.com>, https://github.com/rzajac/angularjs-slider.git - 2013-12-11 */ /*! angularjs-slider - v0.0.1 - (c) Rafal Zajac <rzajac@gmail.com>, https://github.com/rzajac/angularjs-slider.git - 2013-12-11 */
angular.module("rzModule",[]).factory("Slider",["$timeout","$document",function(a,b){var c=function(a,b,c){this.scope=a,this.attributes=c,this.element=b,this.range=void 0===c.rzSliderModel&&void 0!==c.rzSliderLow&&void 0!==c.rzSliderHigh,this.refLow=this.range?"rzSliderLow":"rzSliderModel",this.refHigh="rzSliderHigh",this.barWidth=0,this.ptrHalfWidth=0,this.minOffset=0,this.maxOffset=0,this.minValue=0,this.maxValue=0,this.valueRange=0,this.offsetRange=0,this.precision=0,this.step=0,this.tracking="",this.fullBar=null,this.selBar=null,this.minPtr=null,this.maxPtr=null,this.selBub=null,this.flrBub=null,this.ceilBub=null,this.lowBub=null,this.highBub=null,this.cmbBub=null,this.init()};return c.prototype={init:function(){var b=this;void 0===this.attributes.rzSliderTranslate&&(this.scope.rzSliderTranslate=function(a){return a.value}),this.setMinAndMax(),this.valueRange=this.maxValue-this.minValue,this.precision=void 0===this.scope.rzSliderPrecision?0:+this.scope.rzSliderPrecision,this.step=void 0===this.scope.rzSliderStep?1:+this.scope.rzSliderStep,this.cacheElemHandles(),this.calcViewDimensions(),a(function(){b.setPointers(),b.adjustLabels(),b.bindToInputEvents()}),angular.element(window).on("resize",angular.bind(this,this.calcViewDimensions)),this.scope.$watch(this.refLow,function(){b.setPointers(),b.adjustLabels()}),this.range&&this.scope.$watch(this.refHigh,function(){b.setPointers(),b.adjustLabels()}),void 0!==this.scope.rzSliderFloor&&this.scope.$watch("rzSliderFloor",function(){b.setMinAndMax(),b.setPointers(),b.adjustLabels()}),void 0!==this.scope.rzSliderCeil&&this.scope.$watch("rzSliderCeil",function(){b.setMinAndMax(),b.setPointers(),b.adjustLabels()})},setMinAndMax:function(){this.minValue=void 0===this.scope.rzSliderFloor?0:+this.scope.rzSliderFloor,this.maxValue=void 0===this.scope.rzSliderCeil?this.range?this.scope[this.refHigh]:this.scope[this.refLow]:+this.scope.rzSliderCeil},cacheElemHandles:function(){angular.forEach(this.element.children(),function(a,b){var c=angular.element(a);switch(b){case 0:this.fullBar=c;break;case 1:this.selBar=c;break;case 2:this.minPtr=c;break;case 3:this.maxPtr=c;break;case 4:this.selBub=c;break;case 5:this.flrBub=c;break;case 6:this.ceilBub=c;break;case 7:this.lowBub=c;break;case 8:this.highBub=c;break;case 9:this.cmbBub=c}},this),this.range||(this.cmbBub.remove(),this.highBub.remove(),this.maxPtr.remove(),this.selBar.remove(),this.selBub.remove())},calcViewDimensions:function(){var a=this.offsetWidth(this.minPtr);this.ptrHalfWidth=a/2,this.barWidth=this.offsetWidth(this.fullBar),this.minOffset=0,this.maxOffset=this.barWidth-a,this.offsetRange=this.maxOffset-this.minOffset},setPointers:function(){var a,b,c,d,e,f;this.setLeft(this.ceilBub,this.barWidth-this.offsetWidth(this.ceilBub)),b=this.percentValue(this.scope[this.refLow]),c=this.setLeft(this.minPtr,this.percentToOffset(b)),this.setLeft(this.lowBub,c-this.halfOffsetWidth(this.lowBub)+this.ptrHalfWidth),this.range&&(a=this.percentValue(this.scope[this.refHigh]),d=this.setLeft(this.maxPtr,this.percentToOffset(a)),this.setLeft(this.highBub,d-this.halfOffsetWidth(this.highBub)+this.ptrHalfWidth),e=this.setLeft(this.selBar,c+this.ptrHalfWidth),f=this.percentToOffset(a-b),this.selBar.css({width:f+"px"}),this.setLeft(this.cmbBub,e+f/2-this.halfOffsetWidth(this.cmbBub)+1),this.setLeft(this.selBub,e+f/2-this.halfOffsetWidth(this.selBub)+1),this.scope.rzSliderDiff=this.roundStep(this.scope[this.refHigh]-this.scope[this.refLow]))},adjustLabels:function(){var a=this.highBub;this.fitToBar(this.lowBub),this.range&&(this.fitToBar(this.highBub),this.fitToBar(this.selBub),this.gap(this.lowBub,this.highBub)<10?(this.hideEl(this.lowBub),this.hideEl(this.highBub),this.fitToBar(this.cmbBub),this.showEl(this.cmbBub),a=this.cmbBub):(this.showEl(this.lowBub),this.showEl(this.highBub),this.hideEl(this.cmbBub),a=this.highBub)),this.gap(this.flrBub,this.lowBub)<5?this.hideEl(this.flrBub):this.range?this.gap(this.flrBub,a)<5?this.hideEl(this.flrBub):this.showEl(this.flrBub):this.showEl(this.flrBub),this.gap(this.lowBub,this.ceilBub)<5?this.hideEl(this.ceilBub):this.range?this.gap(a,this.ceilBub)<5?this.hideEl(this.ceilBub):this.showEl(this.ceilBub):this.showEl(this.ceilBub)},roundStep:function(a){var b=this.step,c=Math.pow(10,this.precision),d=(a-this.minValue)%b,e=d>b/2?a+b-d:a-d;return+(e*c/c).toFixed(this.precision)},hideEl:function(a){return a.css({opacity:0})},showEl:function(a){return a.css({opacity:1})},offsetLeft:function(a){return a[0].offsetLeft},offsetWidth:function(a){return a[0].offsetWidth},halfOffsetWidth:function(a){return a[0].offsetWidth/2},setLeft:function(a,b){return a.css({left:b+"px"}),b},fitToBar:function(a){this.setLeft(a,Math.min(Math.max(0,this.offsetLeft(a)),this.barWidth-this.offsetWidth(a)))},gap:function(a,b){return this.offsetLeft(b)-this.offsetLeft(a)-this.offsetWidth(a)},percentValue:function(a){return(a-this.minValue)/this.valueRange*100},percentOffset:function(a){return(a-this.minOffset)/this.offsetRange*100},percentToOffset:function(a){return a*this.offsetRange/100},bindToInputEvents:function(){this.minPtr.on("mousedown",angular.bind(this,this.onStart,this.minPtr,this.refLow)),this.range&&this.maxPtr.on("mousedown",angular.bind(this,this.onStart,this.maxPtr,this.refHigh)),this.minPtr.on("touchstart",angular.bind(this,this.onStart,this.minPtr,this.refLow)),this.range&&this.maxPtr.on("touchstart",angular.bind(this,this.onStart,this.maxPtr,this.refHigh))},onStart:function(a,c,d){""===this.tracking&&(this.tracking=c,a.addClass("active"),d.stopPropagation(),d.preventDefault(),d.touches?(b.on("touchmove",angular.bind(this,this.onMove)),b.on("touchend",angular.bind(this,this.onEnd,a))):(b.on("mousemove",angular.bind(this,this.onMove)),b.on("mouseup",angular.bind(this,this.onEnd,a))))},onMove:function(a){var b,c,d,e=a.clientX||a.touches[0].clientX;b=e-this.element[0].getBoundingClientRect().left-this.ptrHalfWidth,b=Math.max(Math.min(b,this.maxOffset),this.minOffset),c=this.percentOffset(b),d=this.minValue+this.valueRange*c/100,this.range&&(this.tracking===this.refLow&&d>=this.scope[this.refHigh]?(this.tracking=this.refHigh,this.minPtr.removeClass("active"),this.maxPtr.addClass("active")):d<=this.scope[this.refLow]&&(this.tracking=this.refLow,this.maxPtr.removeClass("active"),this.minPtr.addClass("active"))),this.scope[this.tracking]=this.roundStep(d),this.setPointers(),this.adjustLabels(),this.scope.$apply()},onEnd:function(a,c){a.removeClass("active"),c.touches?(b.unbind("touchmove"),b.unbind("touchend")):(b.unbind("mousemove"),b.unbind("mouseup")),this.tracking=""}},c}]).directive("rzslider",["Slider",function(a){return{restrict:"E",scope:{rzSliderFloor:"=?",rzSliderCeil:"=?",rzSliderStep:"@",rzSliderPrecision:"@",rzSliderModel:"=?",rzSliderLow:"=?",rzSliderHigh:"=?",rzSliderTranslate:"&"},template:'<span class="bar"></span><span class="bar selection"></span><span class="pointer"></span><span class="pointer"></span><span class="bubble selection"></span><span class="bubble limit" ng-bind="rzSliderTranslate({value: rzSliderFloor})"></span><span class="bubble limit" ng-bind="rzSliderTranslate({value: rzSliderCeil})" class="bubble limit"></span><span class="bubble"></span><span class="bubble"></span><span class="bubble"></span>',compile:function(b,c){var d=b.children(),e=void 0===c.rzSliderModel&&void 0!==c.rzSliderLow&&void 0!==c.rzSliderHigh,f=e?"rzSliderLow":"rzSliderModel",g="rzSliderHigh";return c.rzSliderTranslate&&c.$set("rzSliderTranslate",""+c.rzSliderTranslate+"(value)"),angular.element(d[4]).attr("ng-bind","rzSliderTranslate({value: rzSliderDiff})"),angular.element(d[7]).attr("ng-bind","rzSliderTranslate({value: "+f+"})"),angular.element(d[8]).attr("ng-bind","rzSliderTranslate({value: "+g+"})"),angular.element(d[9]).attr("ng-bind-html","rzSliderTranslate({value: "+f+'}) + " - " + rzSliderTranslate({value: '+g+"})"),{post:function(b,c,d){return new a(b,c,d)}}}}}]); angular.module("rzModule",[]).factory("Slider",["$timeout","$document",function(a,b){var c=function(a,b,c){this.scope=a,this.attributes=c,this.element=b,this.range=void 0===c.rzSliderModel&&void 0!==c.rzSliderLow&&void 0!==c.rzSliderHigh,this.refLow=this.range?"rzSliderLow":"rzSliderModel",this.refHigh="rzSliderHigh",this.barWidth=0,this.ptrHalfWidth=0,this.minOffset=0,this.maxOffset=0,this.minValue=0,this.maxValue=0,this.valueRange=0,this.offsetRange=0,this.precision=0,this.step=0,this.tracking="",this.fullBar=null,this.selBar=null,this.minPtr=null,this.maxPtr=null,this.selLab=null,this.flrLab=null,this.ceilLab=null,this.lowLab=null,this.highLab=null,this.cmbLab=null,this.init()};return c.prototype={init:function(){var b=this;void 0===this.attributes.rzSliderTranslate&&(this.scope.rzSliderTranslate=function(a){return a.value}),this.setMinAndMax(),this.valueRange=this.maxValue-this.minValue,this.precision=void 0===this.scope.rzSliderPrecision?0:+this.scope.rzSliderPrecision,this.step=void 0===this.scope.rzSliderStep?1:+this.scope.rzSliderStep,this.cacheElemHandles(),this.calcViewDimensions(),a(function(){b.setPointers(),b.adjustLabels(),b.bindToInputEvents()}),angular.element(window).on("resize",angular.bind(this,this.calcViewDimensions)),this.scope.$watch(this.refLow,function(){b.setPointers(),b.adjustLabels()}),this.range&&this.scope.$watch(this.refHigh,function(){b.setPointers(),b.adjustLabels()}),void 0!==this.scope.rzSliderFloor&&this.scope.$watch("rzSliderFloor",function(){b.setMinAndMax(),b.setPointers(),b.adjustLabels()}),void 0!==this.scope.rzSliderCeil&&this.scope.$watch("rzSliderCeil",function(){b.setMinAndMax(),b.setPointers(),b.adjustLabels()})},setMinAndMax:function(){this.minValue=void 0===this.scope.rzSliderFloor?0:+this.scope.rzSliderFloor,this.maxValue=void 0===this.scope.rzSliderCeil?this.range?this.scope[this.refHigh]:this.scope[this.refLow]:+this.scope.rzSliderCeil},cacheElemHandles:function(){angular.forEach(this.element.children(),function(a,b){var c=angular.element(a);switch(b){case 0:this.fullBar=c;break;case 1:this.selBar=c;break;case 2:this.minPtr=c;break;case 3:this.maxPtr=c;break;case 4:this.selLab=c;break;case 5:this.flrLab=c;break;case 6:this.ceilLab=c;break;case 7:this.lowLab=c;break;case 8:this.highLab=c;break;case 9:this.cmbLab=c}},this),this.range||(this.cmbLab.remove(),this.highLab.remove(),this.maxPtr.remove(),this.selBar.remove(),this.selLab.remove())},calcViewDimensions:function(){var a=this.offsetWidth(this.minPtr);this.ptrHalfWidth=a/2,this.barWidth=this.offsetWidth(this.fullBar),this.minOffset=0,this.maxOffset=this.barWidth-a,this.offsetRange=this.maxOffset-this.minOffset},setPointers:function(){var a,b,c,d,e,f;this.setLeft(this.ceilLab,this.barWidth-this.offsetWidth(this.ceilLab)),b=this.percentValue(this.scope[this.refLow]),c=this.setLeft(this.minPtr,this.percentToOffset(b)),this.setLeft(this.lowLab,c-this.halfOffsetWidth(this.lowLab)+this.ptrHalfWidth),this.range&&(a=this.percentValue(this.scope[this.refHigh]),d=this.setLeft(this.maxPtr,this.percentToOffset(a)),this.setLeft(this.highLab,d-this.halfOffsetWidth(this.highLab)+this.ptrHalfWidth),e=this.setLeft(this.selBar,c+this.ptrHalfWidth),f=this.percentToOffset(a-b),this.selBar.css({width:f+"px"}),this.setLeft(this.cmbLab,e+f/2-this.halfOffsetWidth(this.cmbLab)+1),this.setLeft(this.selLab,e+f/2-this.halfOffsetWidth(this.selLab)+1),this.scope.rzSliderDiff=this.roundStep(this.scope[this.refHigh]-this.scope[this.refLow]))},adjustLabels:function(){var a=this.highLab;this.fitToBar(this.lowLab),this.range&&(this.fitToBar(this.highLab),this.fitToBar(this.selLab),this.gap(this.lowLab,this.highLab)<10?(this.hideEl(this.lowLab),this.hideEl(this.highLab),this.fitToBar(this.cmbLab),this.showEl(this.cmbLab),a=this.cmbLab):(this.showEl(this.lowLab),this.showEl(this.highLab),this.hideEl(this.cmbLab),a=this.highLab)),this.gap(this.flrLab,this.lowLab)<5?this.hideEl(this.flrLab):this.range?this.gap(this.flrLab,a)<5?this.hideEl(this.flrLab):this.showEl(this.flrLab):this.showEl(this.flrLab),this.gap(this.lowLab,this.ceilLab)<5?this.hideEl(this.ceilLab):this.range?this.gap(a,this.ceilLab)<5?this.hideEl(this.ceilLab):this.showEl(this.ceilLab):this.showEl(this.ceilLab)},roundStep:function(a){var b=this.step,c=Math.pow(10,this.precision),d=(a-this.minValue)%b,e=d>b/2?a+b-d:a-d;return+(e*c/c).toFixed(this.precision)},hideEl:function(a){return a.css({opacity:0})},showEl:function(a){return a.css({opacity:1})},offsetLeft:function(a){return a[0].offsetLeft},offsetWidth:function(a){return a[0].offsetWidth},halfOffsetWidth:function(a){return a[0].offsetWidth/2},setLeft:function(a,b){return a.css({left:b+"px"}),b},fitToBar:function(a){this.setLeft(a,Math.min(Math.max(0,this.offsetLeft(a)),this.barWidth-this.offsetWidth(a)))},gap:function(a,b){return this.offsetLeft(b)-this.offsetLeft(a)-this.offsetWidth(a)},percentValue:function(a){return(a-this.minValue)/this.valueRange*100},percentOffset:function(a){return(a-this.minOffset)/this.offsetRange*100},percentToOffset:function(a){return a*this.offsetRange/100},bindToInputEvents:function(){this.minPtr.on("mousedown",angular.bind(this,this.onStart,this.minPtr,this.refLow)),this.range&&this.maxPtr.on("mousedown",angular.bind(this,this.onStart,this.maxPtr,this.refHigh)),this.minPtr.on("touchstart",angular.bind(this,this.onStart,this.minPtr,this.refLow)),this.range&&this.maxPtr.on("touchstart",angular.bind(this,this.onStart,this.maxPtr,this.refHigh))},onStart:function(a,c,d){""===this.tracking&&(this.tracking=c,a.addClass("active"),d.stopPropagation(),d.preventDefault(),d.touches?(b.on("touchmove",angular.bind(this,this.onMove)),b.on("touchend",angular.bind(this,this.onEnd,a))):(b.on("mousemove",angular.bind(this,this.onMove)),b.on("mouseup",angular.bind(this,this.onEnd,a))))},onMove:function(a){var b,c,d,e=a.clientX||a.touches[0].clientX;b=e-this.element[0].getBoundingClientRect().left-this.ptrHalfWidth,b=Math.max(Math.min(b,this.maxOffset),this.minOffset),c=this.percentOffset(b),d=this.minValue+this.valueRange*c/100,this.range&&(this.tracking===this.refLow&&d>=this.scope[this.refHigh]?(this.tracking=this.refHigh,this.minPtr.removeClass("active"),this.maxPtr.addClass("active")):d<=this.scope[this.refLow]&&(this.tracking=this.refLow,this.maxPtr.removeClass("active"),this.minPtr.addClass("active"))),this.scope[this.tracking]=this.roundStep(d),this.setPointers(),this.adjustLabels(),this.scope.$apply()},onEnd:function(a,c){a.removeClass("active"),c.touches?(b.unbind("touchmove"),b.unbind("touchend")):(b.unbind("mousemove"),b.unbind("mouseup")),this.tracking=""}},c}]).directive("rzslider",["Slider",function(a){return{restrict:"E",scope:{rzSliderFloor:"=?",rzSliderCeil:"=?",rzSliderStep:"@",rzSliderPrecision:"@",rzSliderModel:"=?",rzSliderLow:"=?",rzSliderHigh:"=?",rzSliderTranslate:"&"},template:'<span class="bar"></span><span class="bar selection"></span><span class="pointer"></span><span class="pointer"></span><span class="bubble selection"></span><span class="bubble limit" ng-bind="rzSliderTranslate({value: rzSliderFloor})"></span><span class="bubble limit" ng-bind="rzSliderTranslate({value: rzSliderCeil})" class="bubble limit"></span><span class="bubble"></span><span class="bubble"></span><span class="bubble"></span>',compile:function(b,c){var d=b.children(),e=void 0===c.rzSliderModel&&void 0!==c.rzSliderLow&&void 0!==c.rzSliderHigh,f=e?"rzSliderLow":"rzSliderModel",g="rzSliderHigh";return c.rzSliderTranslate&&c.$set("rzSliderTranslate",""+c.rzSliderTranslate+"(value)"),angular.element(d[4]).attr("ng-bind","rzSliderTranslate({value: rzSliderDiff})"),angular.element(d[7]).attr("ng-bind","rzSliderTranslate({value: "+f+"})"),angular.element(d[8]).attr("ng-bind","rzSliderTranslate({value: "+g+"})"),angular.element(d[9]).attr("ng-bind-html","rzSliderTranslate({value: "+f+'}) + " - " + rzSliderTranslate({value: '+g+"})"),{post:function(b,c,d){return new a(b,c,d)}}}}}]);
\ No newline at end of file
...@@ -87,14 +87,14 @@ function throttle(func, wait, options) { ...@@ -87,14 +87,14 @@ function throttle(func, wait, options) {
this.range = (attributes.rzSliderModel === undefined) && ((attributes.rzSliderLow !== undefined) && (attributes.rzSliderHigh !== undefined)); this.range = (attributes.rzSliderModel === undefined) && ((attributes.rzSliderLow !== undefined) && (attributes.rzSliderHigh !== undefined));
/** /**
* Name of the low value * Name of the low value model
* *
* @type {string} * @type {string}
*/ */
this.refLow = this.range ? 'rzSliderLow' : 'rzSliderModel'; this.refLow = this.range ? 'rzSliderLow' : 'rzSliderModel';
/** /**
* Name of the high value * Name of the high value model
* *
* @type {string} * @type {string}
*/ */
...@@ -129,14 +129,14 @@ function throttle(func, wait, options) { ...@@ -129,14 +129,14 @@ function throttle(func, wait, options) {
this.maxOffset = 0; this.maxOffset = 0;
/** /**
* Minimum value (floor) * Minimum value (floor) of the model
* *
* @type {number} * @type {number}
*/ */
this.minValue = 0; this.minValue = 0;
/** /**
* Maximum value (ceiling) * Maximum value (ceiling) of the model
* *
* @type {number} * @type {number}
*/ */
...@@ -196,12 +196,12 @@ function throttle(func, wait, options) { ...@@ -196,12 +196,12 @@ function throttle(func, wait, options) {
this.selBar = null; // Highlight between two handles this.selBar = null; // Highlight between two handles
this.minPtr = null; // Left slider handle this.minPtr = null; // Left slider handle
this.maxPtr = null; // Right slider handle this.maxPtr = null; // Right slider handle
this.selBub = null; // Range bubble this.selLab = null; // Range label
this.flrBub = null; // Floor label this.flrLab = null; // Floor label
this.ceilBub = null; // Ceiling label this.ceilLab = null; // Ceiling label
this.lowBub = null; // Label above the low value this.lowLab = null; // Label above the low value
this.highBub = null; // Label above the high value this.highLab = null; // Label above the high value
this.cmbBub = null; // Combined label this.cmbLab = null; // Combined label
// Initialize slider // Initialize slider
this.init(); this.init();
...@@ -322,12 +322,12 @@ function throttle(func, wait, options) { ...@@ -322,12 +322,12 @@ function throttle(func, wait, options) {
case 1: this.selBar = _elem; break; case 1: this.selBar = _elem; break;
case 2: this.minPtr = _elem; break; case 2: this.minPtr = _elem; break;
case 3: this.maxPtr = _elem; break; case 3: this.maxPtr = _elem; break;
case 4: this.selBub = _elem; break; case 4: this.selLab = _elem; break;
case 5: this.flrBub = _elem; break; case 5: this.flrLab = _elem; break;
case 6: this.ceilBub = _elem; break; case 6: this.ceilLab = _elem; break;
case 7: this.lowBub = _elem; break; case 7: this.lowLab = _elem; break;
case 8: this.highBub = _elem; break; case 8: this.highLab = _elem; break;
case 9: this.cmbBub = _elem; break; case 9: this.cmbLab = _elem; break;
} }
}, this); }, this);
...@@ -335,11 +335,11 @@ function throttle(func, wait, options) { ...@@ -335,11 +335,11 @@ function throttle(func, wait, options) {
// Remove stuff not needed in single slider // Remove stuff not needed in single slider
if( ! this.range) if( ! this.range)
{ {
this.cmbBub.remove(); this.cmbLab.remove();
this.highBub.remove(); this.highLab.remove();
this.maxPtr.remove(); this.maxPtr.remove();
this.selBar.remove(); this.selBar.remove();
this.selBub.remove(); this.selLab.remove();
} }
}, },
...@@ -357,44 +357,7 @@ function throttle(func, wait, options) { ...@@ -357,44 +357,7 @@ function throttle(func, wait, options) {
this.minOffset = 0; this.minOffset = 0;
this.maxOffset = this.barWidth - pointerWidth; this.maxOffset = this.barWidth - pointerWidth;
this.offsetRange = this.maxOffset - this.minOffset; this.offsetRange = this.maxOffset - this.minOffset;
this.setLeft(this.ceilBub, this.barWidth - this.offsetWidth(this.ceilBub)); this.setLeft(this.ceilLab, this.barWidth - this.offsetWidth(this.ceilLab));
},
/**
* Set positions of slider handles, labels and selection bar
*
* @returns {undefined}
*/
setPointers: function()
{
var minPtrOL, maxPtrOL, selBarOL, selBarWidth;
this.lowValOffsetPerc = this.percentValue(this.scope[this.refLow]);
// Set low value slider handle position
minPtrOL = this.setLeft(this.minPtr, this.percentToOffset(this.lowValOffsetPerc));
// Set low value label position
this.setLeft(this.lowBub, minPtrOL - this.halfOffsetWidth(this.lowBub) + this.ptrHalfWidth);
if (this.range)
{
this.highValOffsetPerc = this.percentValue(this.scope[this.refHigh]);
// Set high value slider handle position
maxPtrOL = this.setLeft(this.maxPtr, this.percentToOffset(this.highValOffsetPerc));
// Set high value slider handle label position
this.setLeft(this.highBub, maxPtrOL - (this.halfOffsetWidth(this.highBub)) + this.ptrHalfWidth);
// Set selection bar position
selBarOL = this.setLeft(this.selBar, minPtrOL + this.ptrHalfWidth);
selBarWidth = this.percentToOffset(this.highValOffsetPerc - this.lowValOffsetPerc);
this.selBar.css({width: selBarWidth + 'px'});
// Set combined label position
this.setLeft(this.cmbBub, selBarOL + selBarWidth / 2 - this.halfOffsetWidth(this.cmbBub) + 1);
// Set range label position
this.setLeft(this.selBub, selBarOL + selBarWidth / 2 - this.halfOffsetWidth(this.selBub) + 1);
this.scope.rzSliderDiff = this.roundStep(this.scope[this.refHigh] - this.scope[this.refLow]);
}
}, },
/** /**
...@@ -438,7 +401,7 @@ function throttle(func, wait, options) { ...@@ -438,7 +401,7 @@ function throttle(func, wait, options) {
minPtrOL = this.setLeft(this.minPtr, this.percentToOffset(this.lowValOffsetPerc)); minPtrOL = this.setLeft(this.minPtr, this.percentToOffset(this.lowValOffsetPerc));
// Set low value label position // Set low value label position
this.setLeft(this.lowBub, minPtrOL - this.halfOffsetWidth(this.lowBub) + this.ptrHalfWidth); this.setLeft(this.lowLab, minPtrOL - this.halfOffsetWidth(this.lowLab) + this.ptrHalfWidth);
}, },
/** /**
...@@ -454,7 +417,7 @@ function throttle(func, wait, options) { ...@@ -454,7 +417,7 @@ function throttle(func, wait, options) {
// Set high value slider handle position // Set high value slider handle position
maxPtrOL = this.setLeft(this.maxPtr, this.percentToOffset(this.highValOffsetPerc)); maxPtrOL = this.setLeft(this.maxPtr, this.percentToOffset(this.highValOffsetPerc));
// Set high value slider handle label position // Set high value slider handle label position
this.setLeft(this.highBub, maxPtrOL - (this.halfOffsetWidth(this.highBub)) + this.ptrHalfWidth); this.setLeft(this.highLab, maxPtrOL - (this.halfOffsetWidth(this.highLab)) + this.ptrHalfWidth);
}, },
/** /**
...@@ -470,10 +433,10 @@ function throttle(func, wait, options) { ...@@ -470,10 +433,10 @@ function throttle(func, wait, options) {
this.selBar.css({width: selBarWidth + 'px'}); this.selBar.css({width: selBarWidth + 'px'});
// Set combined label position // Set combined label position
this.setLeft(this.cmbBub, selBarOL + selBarWidth / 2 - this.halfOffsetWidth(this.cmbBub) + 1); this.setLeft(this.cmbLab, selBarOL + selBarWidth / 2 - this.halfOffsetWidth(this.cmbLab) + 1);
// Set range label position // Set range label position
this.setLeft(this.selBub, selBarOL + selBarWidth / 2 - this.halfOffsetWidth(this.selBub) + 1); this.setLeft(this.selLab, selBarOL + selBarWidth / 2 - this.halfOffsetWidth(this.selLab) + 1);
this.scope.rzSliderDiff = this.roundStep(this.scope[this.refHigh] - this.scope[this.refLow]); this.scope.rzSliderDiff = this.roundStep(this.scope[this.refHigh] - this.scope[this.refLow]);
}, },
...@@ -482,80 +445,86 @@ function throttle(func, wait, options) { ...@@ -482,80 +445,86 @@ function throttle(func, wait, options) {
* *
* @returns {undefined} * @returns {undefined}
*/ */
adjustLabels: function () adjustLabels: function (origin)
{ {
// console.log('al', this.scope.$id + ' ' + arguments[0]); // console.log('al', this.scope.$id + ' ' + arguments[0]);
var bubToAdjust = this.highBub; var bubToAdjust = this.highLab;
this.fitToBar(this.lowBub); this.fitToBar(this.lowLab);
if (this.range) if (this.range)
{ {
this.fitToBar(this.highBub); this.fitToBar(this.highLab);
this.fitToBar(this.selBub); this.fitToBar(this.selLab);
if (this.gap(this.lowBub, this.highBub) < 10) if (this.gap(this.lowLab, this.highLab) < 10)
{ {
this.hideEl(this.lowBub); this.hideEl(this.lowLab);
this.hideEl(this.highBub); this.hideEl(this.highLab);
this.fitToBar(this.cmbBub); this.fitToBar(this.cmbLab);
this.showEl(this.cmbBub); this.showEl(this.cmbLab);
bubToAdjust = this.cmbBub; bubToAdjust = this.cmbLab;
} }
else else
{ {
this.showEl(this.lowBub); this.showEl(this.lowLab);
this.showEl(this.highBub); this.showEl(this.highLab);
this.hideEl(this.cmbBub); this.hideEl(this.cmbLab);
bubToAdjust = this.highBub; bubToAdjust = this.highLab;
} }
} }
if (this.gap(this.flrBub, this.lowBub) < 5) if (this.gap(this.flrLab, this.lowLab) < 5)
{ {
this.hideEl(this.flrBub); this.hideEl(this.flrLab);
} }
else else
{ {
if (this.range) if (this.range)
{ {
if (this.gap(this.flrBub, bubToAdjust) < 5) if (this.gap(this.flrLab, bubToAdjust) < 5)
{ {
this.hideEl(this.flrBub); this.hideEl(this.flrLab);
} }
else else
{ {
this.showEl(this.flrBub); this.showEl(this.flrLab);
} }
} }
else else
{ {
this.showEl(this.flrBub); this.showEl(this.flrLab);
} }
} }
if (this.gap(this.lowBub, this.ceilBub) < 5) if (this.gap(this.lowLab, this.ceilLab) < 5)
{ {
this.hideEl(this.ceilBub); this.hideEl(this.ceilLab);
} }
else else
{ {
if (this.range) if (this.range)
{ {
if (this.gap(bubToAdjust, this.ceilBub) < 5) if (this.gap(bubToAdjust, this.ceilLab) < 5)
{ {
this.hideEl(this.ceilBub); this.hideEl(this.ceilLab);
} }
else else
{ {
this.showEl(this.ceilBub); this.showEl(this.ceilLab);
} }
} }
else else
{ {
this.showEl(this.ceilBub); this.showEl(this.ceilLab);
} }
} }
// TODO:
if(arguments[0] === 'timeout')
{
Slider.prototype.adjustLabels = throttle(Slider.prototype.adjustLabels, 350);
}
}, },
/** /**
...@@ -824,8 +793,6 @@ function throttle(func, wait, options) { ...@@ -824,8 +793,6 @@ function throttle(func, wait, options) {
} }
}; };
Slider.prototype.adjustLabels = throttle(Slider.prototype.adjustLabels, 350);
return Slider; return Slider;
}]) }])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment