123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- angular.module('ui.bootstrap.progressbar', [])
- .constant('uibProgressConfig', {
- animate: true,
- max: 100
- })
- .controller('UibProgressController', ['$scope', '$attrs', 'uibProgressConfig', function($scope, $attrs, progressConfig) {
- var self = this,
- animate = angular.isDefined($attrs.animate) ? $scope.$parent.$eval($attrs.animate) : progressConfig.animate;
- this.bars = [];
- $scope.max = angular.isDefined($scope.max) ? $scope.max : progressConfig.max;
- this.addBar = function(bar, element, attrs) {
- if (!animate) {
- element.css({'transition': 'none'});
- }
- this.bars.push(bar);
- bar.max = $scope.max;
- bar.title = attrs && angular.isDefined(attrs.title) ? attrs.title : 'progressbar';
- bar.$watch('value', function(value) {
- bar.recalculatePercentage();
- });
- bar.recalculatePercentage = function() {
- var totalPercentage = self.bars.reduce(function(total, bar) {
- bar.percent = +(100 * bar.value / bar.max).toFixed(2);
- return total + bar.percent;
- }, 0);
- if (totalPercentage > 100) {
- bar.percent -= totalPercentage - 100;
- }
- };
- bar.$on('$destroy', function() {
- element = null;
- self.removeBar(bar);
- });
- };
- this.removeBar = function(bar) {
- this.bars.splice(this.bars.indexOf(bar), 1);
- this.bars.forEach(function (bar) {
- bar.recalculatePercentage();
- });
- };
- $scope.$watch('max', function(max) {
- self.bars.forEach(function(bar) {
- bar.max = $scope.max;
- bar.recalculatePercentage();
- });
- });
- }])
- .directive('uibProgress', function() {
- return {
- replace: true,
- transclude: true,
- controller: 'UibProgressController',
- require: 'uibProgress',
- scope: {
- max: '=?'
- },
- templateUrl: 'template/progressbar/progress.html'
- };
- })
- .directive('uibBar', function() {
- return {
- replace: true,
- transclude: true,
- require: '^uibProgress',
- scope: {
- value: '=',
- type: '@'
- },
- templateUrl: 'template/progressbar/bar.html',
- link: function(scope, element, attrs, progressCtrl) {
- progressCtrl.addBar(scope, element, attrs);
- }
- };
- })
- .directive('uibProgressbar', function() {
- return {
- replace: true,
- transclude: true,
- controller: 'UibProgressController',
- scope: {
- value: '=',
- max: '=?',
- type: '@'
- },
- templateUrl: 'template/progressbar/progressbar.html',
- link: function(scope, element, attrs, progressCtrl) {
- progressCtrl.addBar(scope, angular.element(element.children()[0]), {title: attrs.title});
- }
- };
- });
- /* Deprecated progressbar below */
- angular.module('ui.bootstrap.progressbar')
- .value('$progressSuppressWarning', false)
- .controller('ProgressController', ['$scope', '$attrs', 'uibProgressConfig', '$log', '$progressSuppressWarning', function($scope, $attrs, progressConfig, $log, $progressSuppressWarning) {
- if (!$progressSuppressWarning) {
- $log.warn('ProgressController is now deprecated. Use UibProgressController instead.');
- }
- var self = this,
- animate = angular.isDefined($attrs.animate) ? $scope.$parent.$eval($attrs.animate) : progressConfig.animate;
- this.bars = [];
- $scope.max = angular.isDefined($scope.max) ? $scope.max : progressConfig.max;
- this.addBar = function(bar, element, attrs) {
- if (!animate) {
- element.css({'transition': 'none'});
- }
- this.bars.push(bar);
- bar.max = $scope.max;
- bar.title = attrs && angular.isDefined(attrs.title) ? attrs.title : 'progressbar';
- bar.$watch('value', function(value) {
- bar.recalculatePercentage();
- });
- bar.recalculatePercentage = function() {
- bar.percent = +(100 * bar.value / bar.max).toFixed(2);
- var totalPercentage = self.bars.reduce(function(total, bar) {
- return total + bar.percent;
- }, 0);
- if (totalPercentage > 100) {
- bar.percent -= totalPercentage - 100;
- }
- };
- bar.$on('$destroy', function() {
- element = null;
- self.removeBar(bar);
- });
- };
- this.removeBar = function(bar) {
- this.bars.splice(this.bars.indexOf(bar), 1);
- };
- $scope.$watch('max', function(max) {
- self.bars.forEach(function(bar) {
- bar.max = $scope.max;
- bar.recalculatePercentage();
- });
- });
- }])
- .directive('progress', ['$log', '$progressSuppressWarning', function($log, $progressSuppressWarning) {
- return {
- replace: true,
- transclude: true,
- controller: 'ProgressController',
- require: 'progress',
- scope: {
- max: '=?',
- title: '@?'
- },
- templateUrl: 'template/progressbar/progress.html',
- link: function() {
- if (!$progressSuppressWarning) {
- $log.warn('progress is now deprecated. Use uib-progress instead.');
- }
- }
- };
- }])
- .directive('bar', ['$log', '$progressSuppressWarning', function($log, $progressSuppressWarning) {
- return {
- replace: true,
- transclude: true,
- require: '^progress',
- scope: {
- value: '=',
- type: '@'
- },
- templateUrl: 'template/progressbar/bar.html',
- link: function(scope, element, attrs, progressCtrl) {
- if (!$progressSuppressWarning) {
- $log.warn('bar is now deprecated. Use uib-bar instead.');
- }
- progressCtrl.addBar(scope, element);
- }
- };
- }])
- .directive('progressbar', ['$log', '$progressSuppressWarning', function($log, $progressSuppressWarning) {
- return {
- replace: true,
- transclude: true,
- controller: 'ProgressController',
- scope: {
- value: '=',
- max: '=?',
- type: '@'
- },
- templateUrl: 'template/progressbar/progressbar.html',
- link: function(scope, element, attrs, progressCtrl) {
- if (!$progressSuppressWarning) {
- $log.warn('progressbar is now deprecated. Use uib-progressbar instead.');
- }
- progressCtrl.addBar(scope, angular.element(element.children()[0]), {title: attrs.title});
- }
- };
- }]);
|