Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
fix(slider): check for invalid discrete step value
Browse files Browse the repository at this point in the history
Closes #3590.
  • Loading branch information
fabiocarneiro authored and ThomasBurleson committed Jul 6, 2015
1 parent 5e3a651 commit 273fff4
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions src/components/slider/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* @param {number=} min The minimum value the user is allowed to pick. Default 0.
* @param {number=} max The maximum value the user is allowed to pick. Default 100.
*/
function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdTheming, $mdGesture, $parse) {
function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdTheming, $mdGesture, $parse, $log) {
return {
scope: {},
require: '?ngModel',
Expand Down Expand Up @@ -185,22 +185,29 @@ function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdThemi
function redrawTicks() {
if (!angular.isDefined(attr.mdDiscrete)) return;

var numSteps = Math.floor( (max - min) / step );
if (!tickCanvas) {
var trackTicksStyle = $window.getComputedStyle(tickContainer[0]);
tickCanvas = angular.element('<canvas style="position:absolute;">');
tickCtx = tickCanvas[0].getContext('2d');
tickCtx.fillStyle = trackTicksStyle.backgroundColor || 'black';
tickContainer.append(tickCanvas);
}
var dimensions = getSliderDimensions();
tickCanvas[0].width = dimensions.width;
tickCanvas[0].height = dimensions.height;

var distance;
for (var i = 0; i <= numSteps; i++) {
distance = Math.floor(dimensions.width * (i / numSteps));
tickCtx.fillRect(distance - 1, 0, 2, dimensions.height);
if (step > 0) {

var numSteps = Math.floor( (max - min) / step );
if (!tickCanvas) {
tickCanvas = angular.element('<canvas style="position:absolute;">');
tickContainer.append(tickCanvas);

var trackTicksStyle = $window.getComputedStyle(tickContainer[0]);
tickCtx = tickCanvas[0].getContext('2d');
tickCtx.fillStyle = trackTicksStyle.backgroundColor || 'black';
}
var dimensions = getSliderDimensions();
tickCanvas[0].width = dimensions.width;
tickCanvas[0].height = dimensions.height;

var distance;
for (var i = 0; i <= numSteps; i++) {
distance = Math.floor(dimensions.width * (i / numSteps));
tickCtx.fillRect(distance - 1, 0, 2, dimensions.height);
}

} else {
$log.error('Slider step value must be greater than zero when in discrete mode');
}
}

Expand Down

0 comments on commit 273fff4

Please sign in to comment.