progressbar.js
1.08 KB
/*
license: MIT-style
*/
Fx.ProgressBar=function(e,k){var g,h,c,j,a,l={onComplete:function(){},text:null,html5:true},f=function(n,m){g=jQuery.noConflict();g.extend(l,m);var q,p=g(n).attr("class"),r=g(n).attr("id"),o;q=g(n).get(0);h=l.html5&&b();if(h){o=g("<progress></progress>",{value:10,max:100,"class":p,id:r});g(q).replaceWith(o);q=o}else{o=g("<div>",{id:r,"class":p,"class":"progress progress-striped",role:"progressbar","aria-valuenow":"0","aria-valuemin":"0","aria-valuemax":"100"}).html(g("<div>",{"class":"bar"})).get(0);g(q).replaceWith(o);q=o}j=g(q);i(0)},b=function(){return"value" in document.createElement("progress")},d=function(){a=true;if(h){j.removeAttr("value")}else{j.find(".bar").css("width","100%").addClass("active");j.removeAttr("aria-valuenow").attr("title","")}},i=function(n){var m=g(l.text);if(n>=100){n=100}c=n;if(h){j.val(n)}else{j.find(".bar").css("width",n+"%");j.removeAttr("aria-valuenow").attr("title",Math.round(n)+"%")}if(m.length){m.text(Math.round(n)+"%")}if(n>=100){l.onComplete("complete")}return this};f(e,k);return{set:i,setIndeterminate:d,element:j.get(0)}};