-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathprogress.min.js
1 lines (1 loc) · 1.48 KB
/
progress.min.js
1
var Progress={};Progress.bar=(function(b){if("undefined"===typeof b){console.log('Please give config object, like:\nnew Progress.bar({ id: "progress1", autoRemove: true, removeTimeout: 2000 , backgroundSpeed: 50, type: "discharge", showPercentage: true });');return}b.type=b.type?b.type:"charge";b.id=b.id?b.id:"progress"+Math.floor(Math.random()*9999);var k=j();var d=l();var c=a();var h=[];function j(){var n=document.createElement("div");n.setAttribute("class","outerDiv");n.setAttribute("id",b.id);return n}function l(){var n=document.createElement("span");n.innerHTML=b.type==="charge"?"0%":"100%";return n}function a(){var n=document.createElement("div");n.setAttribute("class","innerDiv");n.style.width=b.type==="charge"?"0":"100%";return n}function e(n){n=n>100?100:n<0?0:n;c.style.width=n+"%";if(b.showPercentage){d.innerHTML=n+"%"}m(n)}function i(n){if(b.showPercentage){k.appendChild(d)}k.appendChild(c);n.appendChild(k);g()}function g(){if(!b.backgroundSpeed){return}var n=0;h.backgroundAnimation=window.setInterval(function(){if(b.backgroundSpeed<0){c.style.backgroundPosition=++n+"px"}else{c.style.backgroundPosition=--n+"px"}},b.backgroundSpeed)}function m(n){if("discharge"===b.type&&(0!==n||true!==b.autoRemove)){return}if("charge"===b.type&&(100!==n||true!==b.autoRemove)){return}!b.removeTimeout?f():window.setTimeout(f,b.removeTimeout)}function f(o){window.clearInterval(h.backgroundAnimation);var n=document.getElementById(b.id);n.parentNode.removeChild(n)}return{update:e,renderTo:i,remove:f}});