-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogressBar.js
77 lines (67 loc) · 2.38 KB
/
progressBar.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// Atto ProgressBar (simple progressbar widget)
//
// author: Ryan Corradini
// date: 3 July 2012
// license: MIT
//
define(
["atto/core","require"],
function(atto) {
// make sure the appopriate CSS has been loaded for this widget
var forWidget = "atto-progressbar";
if (!document.querySelector("style[data-for-widget='"+forWidget+"']")) {
require(["text!atto/progressBar.css"], function(rawCss) { atto.addWidgetCss(rawCss, forWidget); });
}
function constructor(rootNode, optionArgs) {
var _root = rootNode || document.createElement('div'),
_bar = document.createElement('span'),
opts = atto.mixinArgs({
min: 0,
max: 100
}, optionArgs),
_min = opts.min,
_max = opts.max,
_val = opts.startingValue || _min;
_setVal(_val);
_root.innerHTML = "";
_root.appendChild(_bar);
// add the appropriate class to the root node
_root.classList.add('aw-progressbar');
function _setVal(newVal) {
var norm = Math.min(_max, Math.max(_min, newVal)) * 100.0,
range = (_max - _min),
percent = 0;
if (range > 0) percent = norm / range;
_val = Math.min(_max, Math.max(_min, newVal));
_bar.style.width = percent + "%";
}
function _setMin(newMin) {
if (newMin < _max) {
_min = newMin;
} else {
_min = newMin;
_max = newMin;
}
}
function _setMax(newMax) {
if (newMax >= _min) {
_max = newMax;
} else {
_min = newMax;
_max = newMax;
}
}
return {
root : _root,
getMin : function() { return _min; },
getMax : function() { return _max; },
getValue : function() { return _val; },
setMin : _setMin,
setMax : _setMax,
setValue : _setVal
} // end of public interface
} // end of constructor
return constructor;
} // end function
);