From 6797e05458d571262dc0f9f4b5a18287f0e8a72e Mon Sep 17 00:00:00 2001 From: Victor Zagorski Date: Wed, 9 Jul 2014 16:35:06 +0800 Subject: [PATCH 1/2] Watch max attribute --- src/progressbar/progressbar.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/progressbar/progressbar.js b/src/progressbar/progressbar.js index 9a6a6355d7..df58e84e7c 100644 --- a/src/progressbar/progressbar.js +++ b/src/progressbar/progressbar.js @@ -10,7 +10,21 @@ angular.module('ui.bootstrap.progressbar', []) animate = angular.isDefined($attrs.animate) ? $scope.$parent.$eval($attrs.animate) : progressConfig.animate; this.bars = []; - $scope.max = angular.isDefined($attrs.max) ? $scope.$parent.$eval($attrs.max) : progressConfig.max; + + this.updateBar = function(bar) { + bar.percent = +(100 * bar.value / $scope.max).toFixed(2); + } + + if (angular.isDefined($attrs.max)) { + $scope.$parent.$watch($attrs.max, function (new_value) { + $scope.max = new_value; + for (i=0; i Date: Wed, 9 Jul 2014 16:54:09 +0800 Subject: [PATCH 2/2] fix: Added test and fixed js syntax --- src/progressbar/progressbar.js | 2 +- src/progressbar/test/progressbar.spec.js | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/progressbar/progressbar.js b/src/progressbar/progressbar.js index df58e84e7c..f2ee42ec84 100644 --- a/src/progressbar/progressbar.js +++ b/src/progressbar/progressbar.js @@ -13,7 +13,7 @@ angular.module('ui.bootstrap.progressbar', []) this.updateBar = function(bar) { bar.percent = +(100 * bar.value / $scope.max).toFixed(2); - } + }; if (angular.isDefined($attrs.max)) { $scope.$parent.$watch($attrs.max, function (new_value) { diff --git a/src/progressbar/test/progressbar.spec.js b/src/progressbar/test/progressbar.spec.js index bae03b6ea5..837e8372f1 100644 --- a/src/progressbar/test/progressbar.spec.js +++ b/src/progressbar/test/progressbar.spec.js @@ -5,8 +5,9 @@ describe('progressbar directive', function () { beforeEach(inject(function(_$compile_, _$rootScope_) { $compile = _$compile_; $rootScope = _$rootScope_; + $rootScope.max = 100; $rootScope.value = 22; - element = $compile('{{value}} %')($rootScope); + element = $compile('{{value}} %')($rootScope); $rootScope.$digest(); })); @@ -65,6 +66,19 @@ describe('progressbar directive', function () { expect(bar.attr('aria-valuetext')).toBe('60%'); }); + it('adjusts the "bar" width and aria when max value changes', function() { + $rootScope.max = 200; + $rootScope.$digest(); + + var bar = getBar(0); + expect(bar.css('width')).toBe('11%'); + + expect(bar.attr('aria-valuemin')).toBe('0'); + expect(bar.attr('aria-valuemax')).toBe('200'); + expect(bar.attr('aria-valuenow')).toBe('22'); + expect(bar.attr('aria-valuetext')).toBe('11%'); + }); + it('allows fractional "bar" width values, rounded to two places', function () { $rootScope.value = 5.625; $rootScope.$digest();