-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery_simple_progressbar.js
73 lines (62 loc) · 1.96 KB
/
jquery_simple_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
(function ( $ ) {
$.fn.simple_progressbar = function(options) {
var settings = $.extend({
normalColor: "#76E29C",
overflowColor: "#E67373",
backgroundColor: "#EEEEEE",
height: '20px',
width: '200px',
showValue: false,
internalPadding: '1px',
value: undefined,
valueText: undefined,
}, options );
return this.each( function() {
$_this = $(this);
var outer_div, inner_div;
var updating = false;
outer_div = $_this.find('.simple-progressbar-generated-div');
if (outer_div.length == 1) {
inner_div = outer_div.find('div');
updating = true;
} else {
outer_div = $('<div class="simple-progressbar-generated-div">');
inner_div = $('<div>');
}
var value = settings.value;
if (typeof(value) == 'undefined') {
if (updating) {
value = $_this.data('value');
} else {
value = parseFloat($_this.text());
}
}
$_this.data('value', value);
outer_div.css('background-color', settings.backgroundColor);
outer_div.css('padding', settings.internalPadding);
outer_div.css('height', settings.height);
outer_div.css('width', settings.width);
inner_div.css('height', '100%');
inner_div.css('white-space', 'nowrap');
if (value <= 100) {
inner_div.css('background-color', settings.normalColor);
inner_div.css('width', value.toString() + '%');
} else {
inner_div.css('background-color', settings.overflowColor);
inner_div.css('width', '100%');
}
if (settings.showValue) {
if (typeof(settings.valueText) == 'undefined') {
inner_div.html(value.toString() + "%");
} else {
inner_div.html(settings.valueText.toString());
}
} else {
inner_div.html("");
}
outer_div.html(inner_div);
$_this.html(outer_div);
return this;
});
};
}( jQuery ));