Skip to content
Snippets Groups Projects
Commit a31d6613 authored by Krzysztof Bąk's avatar Krzysztof Bąk
Browse files

Improving slider

parent 0ea28bc7
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
......@@ -218,6 +218,7 @@ function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdThemi
angular.isDefined(attr.max) ? attr.$observe('max', updateMax) : updateMax(100);
angular.isDefined(attr.step)? attr.$observe('step', updateStep) : updateStep(1);
angular.isDefined(attr.round)? attr.$observe('round', updateRound) : updateRound(DEFAULT_ROUND);
angular.isDefined(attr.decimals) ? attr.$observe('decimals', updateDecimals) : updateDecimals(0);
// We have to manually stop the $watch on ngDisabled because it exists
// on the parent scope, and won't be automatically destroyed when
......@@ -268,6 +269,7 @@ function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdThemi
var max;
var step;
var round;
var decimals;
function updateMin(value) {
min = parseFloat(value);
element.attr('aria-valuemin', value);
......@@ -288,6 +290,9 @@ function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdThemi
function updateAriaDisabled() {
element.attr('aria-disabled', !!isDisabled());
}
function updateDecimals(value) {
decimals = parseInt(value);
}
// Draw the ticks with canvas.
// The alternative to drawing ticks with canvas is to draw one element for each tick,
......@@ -421,7 +426,7 @@ function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdThemi
scope.modelValue = ngModelCtrl.$viewValue;
element.attr('aria-valuenow', ngModelCtrl.$viewValue);
setSliderPercent(percent);
thumbText.text( ngModelCtrl.$viewValue );
thumbText.text( ngModelCtrl.$viewValue.toFixed(decimals) );
}
function minMaxValidator(value, minValue, maxValue) {
......@@ -548,7 +553,7 @@ function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdThemi
var exactVal = percentToValue( positionToPercent( x ));
var closestVal = minMaxValidator( stepValidator(exactVal) );
setSliderPercent( positionToPercent(x) );
thumbText.text( closestVal );
thumbText.text( closestVal.toFixed(decimals) );
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment