jacoborus / nanobar

Very lightweight progress bars. No jQuery
http://nanobar.jacoborus.codes
MIT License
2.84k stars 266 forks source link

Simple increase method #21

Closed chrsr closed 10 years ago

chrsr commented 10 years ago

I recently used nanobar on a project and found the need to increase it's width by a percentage rather than just moving it to a specific value. To do this I created a simple increase method that just adds the increase on to the existing width.

Example usage:

nanobar.increase(10);

This pull request includes the code and updated demo + docs.

jacoborus commented 10 years ago

Hi Chris, thanks for the PR, but I want to keep nanobar as a one method function, as minimal as possible.

You can extend nanobar prototype:

var Nanobar = require( 'nanobar' ),
    nanobar;

Nanobar.prototype.increase = function (p) {
    p = p + this.bars[0].width;
    p = p > 100 ? 100 : p;
    this.go( p );
};

nanobar = new Nanobar();
nanobar.increase( 20 );
chrsr commented 10 years ago

No dramas - that's pretty much how I extended it on my project.