Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngprogress",
"version": "1.0.7",
"version": "1.0.8",
"main": [
"build/ngProgress.js",
"ngProgress.css"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
18 changes: 18 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion src/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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];

Expand Down Expand Up @@ -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) {
Expand Down
21 changes: 18 additions & 3 deletions tests/ngProgressProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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'));
})
});

});