Commit f557cd4d authored by kvindasAB's avatar kvindasAB

Adapting component to render properly on min/max limits changed.

Also adding a force re-render mechanism useful when using tabs.
parent 80e2c59c
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
angular.module('rzModule', []) angular.module('rzModule', [])
.value('throttle', .value('throttle',
/** /**
* throttle * throttle
* *
...@@ -24,7 +24,7 @@ angular.module('rzModule', []) ...@@ -24,7 +24,7 @@ angular.module('rzModule', [])
* @param {ThrottleOptions} options * @param {ThrottleOptions} options
* @returns {Function} * @returns {Function}
*/ */
function throttle(func, wait, options) { function throttle(func, wait, options) {
var getTime = (Date.now || function() { var getTime = (Date.now || function() {
return new Date().getTime(); return new Date().getTime();
}); });
...@@ -55,10 +55,10 @@ function throttle(func, wait, options) { ...@@ -55,10 +55,10 @@ function throttle(func, wait, options) {
} }
return result; return result;
} }
}) })
.factory('Slider', ['$timeout', '$document', 'throttle', function($timeout, $document, throttle) .factory('Slider', ['$timeout', '$document', 'throttle', function($timeout, $document, throttle)
{ {
/** /**
* Slider * Slider
* *
...@@ -192,6 +192,7 @@ function throttle(func, wait, options) { ...@@ -192,6 +192,7 @@ function throttle(func, wait, options) {
*/ */
init: function() init: function()
{ {
//console.log("slider.init...");
var self = this; var self = this;
if(this.scope.rzSliderTranslate) if(this.scope.rzSliderTranslate)
...@@ -212,10 +213,7 @@ function throttle(func, wait, options) { ...@@ -212,10 +213,7 @@ function throttle(func, wait, options) {
self.updateFloorLab(); self.updateFloorLab();
self.initHandles(); self.initHandles();
self.bindEvents(); self.bindEvents();
}); },100);
// Recalculate slider view dimensions
this.scope.$on('reCalcViewDimensions', angular.bind(this, this.calcViewDimensions));
// Recalculate stuff if view port dimensions have changed // Recalculate stuff if view port dimensions have changed
angular.element(window).on('resize', angular.bind(this, this.calcViewDimensions)); angular.element(window).on('resize', angular.bind(this, this.calcViewDimensions));
...@@ -226,7 +224,6 @@ function throttle(func, wait, options) { ...@@ -226,7 +224,6 @@ function throttle(func, wait, options) {
var thrLow = throttle(function() var thrLow = throttle(function()
{ {
self.setMinAndMax();
self.updateLowHandle(self.valueToOffset(self.scope.rzSliderModel)); self.updateLowHandle(self.valueToOffset(self.scope.rzSliderModel));
if(self.range) if(self.range)
...@@ -239,25 +236,57 @@ function throttle(func, wait, options) { ...@@ -239,25 +236,57 @@ function throttle(func, wait, options) {
var thrHigh = throttle(function() var thrHigh = throttle(function()
{ {
self.setMinAndMax();
self.updateHighHandle(self.valueToOffset(self.scope.rzSliderHigh)); self.updateHighHandle(self.valueToOffset(self.scope.rzSliderHigh));
self.updateSelectionBar(); self.updateSelectionBar();
self.updateCmbLabel(); self.updateCmbLabel();
}, 350, { leading: false }); }, 350, { leading: false });
this.scope.$watch('rzSliderModel', function(newValue, oldValue)
{ this.scope.$watch('rzSliderModel', function(newValue, oldValue){
//console.log("sliderModel.changed...");
if(newValue === oldValue) return; if(newValue === oldValue) return;
thrLow(); thrLow();
}); });
this.scope.$watch('rzSliderHigh', function(newValue, oldValue) this.scope.$watch('rzSliderHigh', function(newValue, oldValue){
{ //console.log("sliderHigh.changed...");
if(newValue === oldValue) return;
thrHigh();
});
this.scope.$watch('rzSliderFloor', function(newValue, oldValue){
//console.log("sliderFloor.changed...");
if(newValue === oldValue) return;
self.resetSlider();
});
this.scope.$watch('rzSliderCeil', function(newValue, oldValue){
//console.log("sliderCeil.changed...");
if(newValue === oldValue) return; if(newValue === oldValue) return;
self.resetSlider();
});
this.scope.$watch('rzSliderForceRender', function(newValue, oldValue){
//console.log("rzSliderForceRender.changed...");
self.resetLabelsWidth();
thrLow();
thrHigh(); thrHigh();
self.resetSlider();
}); });
}, },
resetLabelsWidth: function() {
this.minLab.rzsv = undefined;
this.maxLab.rzsv = undefined;
},
resetSlider: function() {
this.setMinAndMax();
this.calcViewDimensions();
this.updateCeilLab();
this.updateFloorLab();
},
/** /**
* Initialize slider handles positions and labels * Initialize slider handles positions and labels
* *
...@@ -311,6 +340,7 @@ function throttle(func, wait, options) { ...@@ -311,6 +340,7 @@ function throttle(func, wait, options) {
*/ */
setMinAndMax: function() setMinAndMax: function()
{ {
//console.log("slider.setMinAndMax...");
if(this.scope.rzSliderFloor) if(this.scope.rzSliderFloor)
{ {
this.minValue = +this.scope.rzSliderFloor; this.minValue = +this.scope.rzSliderFloor;
...@@ -475,6 +505,7 @@ function throttle(func, wait, options) { ...@@ -475,6 +505,7 @@ function throttle(func, wait, options) {
*/ */
updateLowHandle: function(newOffset) updateLowHandle: function(newOffset)
{ {
//console.log("updateLowHandle: hhw: " + this.handleHalfWidth + " mh" + newOffset );
this.setLeft(this.minH, newOffset); this.setLeft(this.minH, newOffset);
this.translateFn(this.scope.rzSliderModel, this.minLab); this.translateFn(this.scope.rzSliderModel, this.minLab);
this.setLeft(this.minLab, newOffset - this.minLab.rzsw / 2 + this.handleHalfWidth); this.setLeft(this.minLab, newOffset - this.minLab.rzsw / 2 + this.handleHalfWidth);
...@@ -684,6 +715,7 @@ function throttle(func, wait, options) { ...@@ -684,6 +715,7 @@ function throttle(func, wait, options) {
*/ */
valueToOffset: function(val) valueToOffset: function(val)
{ {
//console.log("valueToOffset..." + val + " minV: " + this.minValue + " maxL " + this.maxLeft + " vr: " + this.valueRange);
return (val - this.minValue) * this.maxLeft / this.valueRange; return (val - this.minValue) * this.maxLeft / this.valueRange;
}, },
...@@ -844,10 +876,10 @@ function throttle(func, wait, options) { ...@@ -844,10 +876,10 @@ function throttle(func, wait, options) {
}; };
return Slider; return Slider;
}]) }])
.directive('rzslider', ['Slider', function(Slider) .directive('rzslider', ['Slider', function(Slider)
{ {
return { return {
restrict: 'E', restrict: 'E',
scope: { scope: {
...@@ -857,7 +889,8 @@ function throttle(func, wait, options) { ...@@ -857,7 +889,8 @@ function throttle(func, wait, options) {
rzSliderPrecision: '@', rzSliderPrecision: '@',
rzSliderModel: '=?', rzSliderModel: '=?',
rzSliderHigh: '=?', rzSliderHigh: '=?',
rzSliderTranslate: '&' rzSliderTranslate: '&',
rzSliderForceRender: '=?'
}, },
template: '<span class="bar"></span>' + // 0 The slider bar template: '<span class="bar"></span>' + // 0 The slider bar
'<span class="bar selection"></span>' + // 1 Highlight between two handles '<span class="bar selection"></span>' + // 1 Highlight between two handles
...@@ -874,7 +907,7 @@ function throttle(func, wait, options) { ...@@ -874,7 +907,7 @@ function throttle(func, wait, options) {
return new Slider(scope, elem, attr); return new Slider(scope, elem, attr);
} }
}; };
}]); }]);
// IDE assist // IDE assist
......
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