-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress.js
41 lines (34 loc) · 899 Bytes
/
progress.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
/**
* Programmatically control a progress bar.
*
* @constructor
* @param {Element} element DOM element we should render.
* @param {Object} options
* @api public
*/
function Progress(element) {
if (!(this instanceof Progress)) return new Progress(element);
this.parent = element;
this.bar = this.parent.firstChild;
this.set(0);
}
/**
* Set a new percentage that the progress bar should have.
*
* @param {Number} amount The percentage of the progress bar.
* @returns {Progress}
* @api public
*/
Progress.prototype.set = function set(amount) {
if (amount > 100) amount = 100;
if (amount < 0) amount = 0;
if ('value' in this.bar) this.bar.value = amount;
else this.bar.style.width = amount +'%';
this.parent.style.opacity = 100 === amount || 0 === amount ? 0 : 1;
return this;
};
//
// Expose the Progress constructor.
//
module.exports = Progress;