-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmultiprogressbar.js
51 lines (41 loc) · 1.38 KB
/
multiprogressbar.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
$.fn.progress = function (options)
{
var defaults = { InProgress: 0, Completed: 0 };
var opt = $.extend(defaults, options);
function addScale(container, scaleValue, cssClass)
{
// Ignore scale when value is zero.
if (scaleValue == 0)
return;
// Create scale.
var scale = $('<div/>');
scale.addClass(cssClass);
scale.css("width", scaleValue + "%");
// Set scale text when possible.
// TODO: scale.width() returns width in percents, not in pixels. This may be wrong.
if (scale.width() > 15)
scale.html(scaleValue + "%");
else
scale.html(" ");
// Append scale to container.
container.append(scale);
}
return this.each(function ()
{
var container = $(this);
// Remove any data from container.
container.empty();
// Truncate to 100%
if (opt.Completed > 100) opt.Completed = 100;
if (opt.InProgress > 100) opt.InProgress = 100;
if (opt.Completed + opt.InProgress > 100)
opt.InProgress = 100 - opt.Completed;
// Make container like progress bar.
container.addClass("progress");
addScale(container, opt.Completed, "complete");
addScale(container, opt.InProgress, "inprogress");
// Create corners.
// TODO: 3px should be in CSS
container.corner("3px");
});
};