1 line
12 KiB
JavaScript
1 line
12 KiB
JavaScript
|
!function(e,t,n,r){"use strict";t=void 0!==t&&t.Math==Math?t:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();void 0!==t&&t.Math==Math||("undefined"!=typeof self&&self.Math==Math?self:Function("return this")());e.fn.progress=function(t){var r,a=e(this),o=a.selector||"",i=(new Date).getTime(),s=[],l=arguments[0],c="string"==typeof l,u=[].slice.call(arguments,1);return a.each(function(){var a,d,v=e.isPlainObject(t)?e.extend(!0,{},e.fn.progress.settings,t):e.extend({},e.fn.progress.settings),g=v.className,p=v.metadata,f=v.namespace,m=v.selector,b=v.error,h="."+f,x="module-"+f,w=e(this),y=e(this).find(m.bar),V=e(this).find(m.progress),C=e(this).find(m.label),E=this,P=w.data(x),T=!1;d={initialize:function(){d.debug("Initializing progress bar",v),d.set.duration(),d.set.transitionEvent(),d.read.metadata(),d.read.settings(),d.instantiate()},instantiate:function(){d.verbose("Storing instance of progress",d),P=d,w.data(x,d)},destroy:function(){d.verbose("Destroying previous progress for",w),clearInterval(P.interval),d.remove.state(),w.removeData(x),P=void 0},reset:function(){d.remove.nextValue(),d.update.progress(0)},complete:function(){(void 0===d.percent||d.percent<100)&&(d.remove.progressPoll(),d.set.percent(100))},read:{metadata:function(){var e={percent:w.data(p.percent),total:w.data(p.total),value:w.data(p.value)};e.percent&&(d.debug("Current percent value set from metadata",e.percent),d.set.percent(e.percent)),e.total&&(d.debug("Total value set from metadata",e.total),d.set.total(e.total)),e.value&&(d.debug("Current value set from metadata",e.value),d.set.value(e.value),d.set.progress(e.value))},settings:function(){!1!==v.total&&(d.debug("Current total set in settings",v.total),d.set.total(v.total)),!1!==v.value&&(d.debug("Current value set in settings",v.value),d.set.value(v.value),d.set.progress(d.value)),!1!==v.percent&&(d.debug("Current percent set in settings",v.percent),d.set.percent(v.percent))}},bind:{transitionEnd:function(e){var t=d.get.transitionEnd();y.one(t+h,function(t){clearTimeout(d.failSafeTimer),e.call(this,t)}),d.failSafeTimer=setTimeout(function(){y.triggerHandler(t)},v.duration+v.failSafeDelay),d.verbose("Adding fail safe timer",d.timer)}},increment:function(e){var t,n;d.has.total()?(t=d.get.value(),e=e||1,n=t+e):(t=d.get.percent(),e=e||d.get.randomValue(),n=t+e,100,d.debug("Incrementing percentage by",t,n)),n=d.get.normalizedValue(n),d.set.progress(n)},decrement:function(e){var t,n,r=d.get.total();r?(t=d.get.value(),e=e||1,n=t-e,d.debug("Decrementing value by",e,t)):(t=d.get.percent(),e=e||d.get.randomValue(),n=t-e,d.debug("Decrementing percentage by",e,t)),n=d.get.normalizedValue(n),d.set.progress(n)},has:{progressPoll:function(){return d.progressPoll},total:function(){return!1!==d.get.total()}},get:{text:function(e){var t=d.value||0,n=d.total||0,r=T?d.get.displayPercent():d.percent||0,a=d.total>0?n-t:100-r;return e=e||"",e=e.replace("{value}",t).replace("{total}",n).replace("{left}",a).replace("{percent}",r),d.verbose("Adding variables to progress bar text",e),e},normalizedValue:function(e){if(e<0)return d.debug("Value cannot decrement below 0"),0;if(d.has.total()){if(e>d.total)return d.debug("Value cannot increment above total",d.total),d.total}else if(e>100)return d.debug("Value cannot increment above 100 percent"),100;return e},updateInterval:function(){return"auto"==v.updateInterval?v.duration:v.updateInterval},randomValue:function(){return d.debug("Generating random increment percentage"),Math.floor(Math.random()*v.random.max+v.random.min)},numericValue:function(e){return"string"==typeof e?""!==e.replace(/[^\d.]/g,"")&&+e.replace(/[^\d.]/g,""):e},transitionEnd:function(){var e,t=n.createElement("element"),r={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(e in r)if(void 0!==t.style[e])return r[e]},displayPercent:function(){var e=y.width(),t=w.width(),n=parseInt(y.css("min-width"),10),r=e>n?e/t*100:d.percent;return v.precision>0?Math.round(r*(10*v.precision))/(10*v.precision):Math.round(r)},
|