diff --git a/bower.json b/bower.json index e2500cc..840cffc 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "ngprogress", - "version": "1.0.7", + "version": "1.0.8", "main": [ "build/ngProgress.js", "ngProgress.css" diff --git a/package.json b/package.json index 40e8c28..dd74762 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ngProgress", - "version": "1.0.7", + "version": "1.0.8", "description": "slim, site-wide progressbar for AngularJS", "main": "ngProgress.js", "repository": { diff --git a/readme.md b/readme.md index 922c188..bf76acb 100644 --- a/readme.md +++ b/readme.md @@ -99,6 +99,24 @@ ngProgress.complete(); ngProgress.setParent(document.getElementById('container')); ``` +* **getIncrement** - Returns the 'step' between each tick of the progress bar. + +```javascript +ngProgress.getIncrement(); +``` + +* **setIncrement** - Sets the 'step' between each tick of the progress bar. A smaller increment means the progress bar will take more iterations to reach 100% + +```javascript +ngProgress.setIncrement(0.05); +``` + +* **resetIncrement** - Resets the 'step' between each tick of the progress bar to the default value + +```javascript +ngProgress.resetIncrement(); +``` + * **getDomElement** - Gets the DOM element which visizualizes the progress bar. It is wrapped as a jqlite element - https://docs.angularjs.org/api/ng/function/angular.element ```javascript diff --git a/src/provider.js b/src/provider.js index dc36b3c..1b1c07b 100644 --- a/src/provider.js +++ b/src/provider.js @@ -3,10 +3,13 @@ angular.module('ngProgress.provider', ['ngProgress.directive']) .provider('ngProgress', function () { 'use strict'; //Default values for provider + var DEFAULT_INCREMENT = 0.15; + this.autoStyle = true; this.count = 0; this.height = '2px'; this.color = 'firebrick'; + this.increment = DEFAULT_INCREMENT; this.$get = ['$document', '$window', @@ -16,6 +19,7 @@ angular.module('ngProgress.provider', ['ngProgress.directive']) var count = this.count, height = this.height, color = this.color, + increment = this.increment, $scope = $rootScope, parent = $document.find('body')[0]; @@ -53,11 +57,23 @@ angular.module('ngProgress.provider', ['ngProgress.directive']) self.hide(); } else { var remaining = 100 - count; - count = count + (0.15 * Math.pow(1 - Math.sqrt(remaining), 2)); + count = count + (increment * Math.pow(1 - Math.sqrt(remaining), 2)); self.updateCount(count); } }, 200); }, + // Returns the increment used by the progress bar + getIncrement: function(){ + return increment; + }, + // Sets the increment of the progress bar + setIncrement: function(new_increment){ + increment = new_increment; + }, + // Resets the increment to the default value + resetIncrement: function () { + increment = DEFAULT_INCREMENT; + }, updateCount: function (new_count) { $scope.count = new_count; if(!$scope.$$phase) { diff --git a/tests/ngProgressProviderSpec.js b/tests/ngProgressProviderSpec.js index 1121d59..6143a71 100644 --- a/tests/ngProgressProviderSpec.js +++ b/tests/ngProgressProviderSpec.js @@ -140,7 +140,22 @@ describe('How the provider should work', function () { waits(200); runs(function () { expect([6, this.progressbar.status()]).toEqual([6, 100]); }); }); - + + it('allow the progress bar to have a default increment of 0.15', function () { + expect(this.progressbar.getIncrement()).toBe(0.15); + }); + + it('allow you to change the increment of the progress bar', function () { + this.progressbar.setIncrement(0.25); + expect(this.progressbar.getIncrement()).toBe(0.25); + }); + + it('allow you to reset the increment of the progress bar', function () { + this.progressbar.setIncrement(0.25); + this.progressbar.resetIncrement(); + expect(this.progressbar.getIncrement()).toBe(0.15); + }); + it('allow you to change the parent of the progressbar', function () { var domElement = this.progressbar.getDomElement()[0]; expect(domElement.parentNode).toEqual(document.body); @@ -149,13 +164,13 @@ describe('How the provider should work', function () { document.body.appendChild(div); this.progressbar.setParent(div); expect(domElement.parentNode).toEqual(div); - }) + }); it('throws exception when invalid parent is set', function () { var that = this; expect(function () { that.progressbar.setParent(null); }).toThrow(new Error('Provide a valid parent of type HTMLElement')); - }) + }); }); \ No newline at end of file