-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.completionmeter.js
29 lines (28 loc) · 1.25 KB
/
jquery.completionmeter.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
/**
* jQuery plugin: Percent Completed Meter
* Created by Nick Hagianis
* Date: 1/28/11
*
* You are free to use, modify, and redistribute any and all parts of this code as you see fit.
* There is no warranty, and I'm not liable if it breaks or breaks any other code in your project.
*/
(function($){
$.fn.percentComplete = function(selector, color, size){
return this.each(function(){
var fieldCount = $(selector).not(":radio").length;
var names = [];
$(selector+":radio").each(function(){
var n = $(this).attr('name');
if(names.indexOf(n) < 0){
names.push(n);
}
});
fieldCount = fieldCount + names.length;
if(fieldCount){
var completeCount = $(selector+"[value!='']").not(":checkbox").not(":radio").length + $(selector+":checked").length;
var percentComplete = Math.round((completeCount / fieldCount) * 100);
$(this).empty().append(percentComplete + "% Complete<br><div><div> </div></div>").children("div").css({"width": size, "border": "1px solid"+color}).children("div").css({"width": percentComplete+"%", "background-color":color});
}
});
};
})(jQuery);