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)},percent:function(){return d.percent||0},value:function(){return d.nextValue||d.value||0},total:function(){return d.total||!1}},create:{progressPoll:function(){d.progressPoll=setTimeout(function(){d.update.toNextValue(),d.remove.progressPoll()},d.get.updateInterval())}},is:{complete:function(){return d.is.success()||d.is.warning()||d.is.error()},success:function(){return w.hasClass(g.success)},warning:function(){return w.hasClass(g.warning)},error:function(){return w.hasClass(g.error)},active:function(){return w.hasClass(g.active)},visible:function(){return w.is(":visible")}},remove:{progressPoll:function(){d.verbose("Removing progress poll timer"),d.progressPoll&&(clearTimeout(d.progressPoll),delete d.progressPoll)},nextValue:function(){d.verbose("Removing progress value stored for next update"),delete d.nextValue},state:function(){d.verbose("Removing stored state"),delete d.total,delete d.percent,delete d.value},active:function(){d.verbose("Removing active state"),w.removeClass(g.active)},success:function(){d.verbose("Removing success state"),w.removeClass(g.success)},warning:function(){d.verbose("Removing warning state"),w.removeClass(g.warning)},error:function(){d.verbose("Removing error state"),w.removeClass(g.error)}},set:{barWidth:function(e){e>100?d.error(b.tooHigh,e):e<0?d.error(b.tooLow,e):(y.css("width",e+"%"),w.attr("data-percent",parseInt(e,10)))},duration:function(e){e=e||v.duration,e="number"==typeof e?e+"ms":e,d.verbose("Setting progress bar transition duration",e),y.css({"transition-duration":e})},percent:function(e){e="string"==typeof e?+e.replace("%",""):e,e=v.precision>0?Math.round(e*(10*v.precision))/(10*v.precision):Math.round(e),d.percent=e,d.has.total()||(d.value=v.precision>0?Math.round(e/100*d.total*(10*v.precision))/(10*v.precision):Math.round(e/100*d.total*10)/10,v.limitValues&&(d.value=d.value>100?100:d.value<0?0:d.value)),d.set.barWidth(e),d.set.labelInterval(),d.set.labels(),v.onChange.call(E,e,d.value,d.total)},labelInterval:function(){var t=function(){d.verbose("Bar finished animating, removing continuous label updates"),clearInterval(d.interval),T=!1,d.set.labels()};clearInterval(d.interval),d.bind.transitionEnd(t),T=!0,d.interval=setInterval(function(){e.contains(n.documentElement,E)||(clearInterval(d.interval),T=!1),d.set.labels()},v.framerate)},labels:function(){d.verbose("Setting both bar progress and outer label text"),d.set.barLabel(),d.set.state()},label:function(e){(e=e||"")&&(e=d.get.text(e),d.verbose("Setting label to text",e),C.text(e))},state:function(e){e=void 0!==e?e:d.percent,100===e?v.autoSuccess&&!(d.is.warning()||d.is.error()||d.is.success())?(d.set.success(),d.debug("Automatically triggering success at 100%")):(d.verbose("Reached 100% removing active state"),d.remove.active(),d.remove.progressPoll()):e>0?(d.verbose("Adjusting active progress bar label",e),d.set.active()):(d.remove.active(),d.set.label(v.text.active))},barLabel:function(e){void 0!==e?V.text(d.get.text(e)):"ratio"==v.label&&d.total?(d.verbose("Adding ratio to bar label"),V.text(d.get.text(v.text.ratio))):"percent"==v.label&&(d.verbose("Adding percentage to bar label"),V.text(d.get.text(v.text.percent)))},active:function(e){e=e||v.text.active,d.debug("Setting active state"),v.showActivity&&!d.is.active()&&w.addClass(g.active),d.remove.warning(),d.remove.error(),d.remove.success(),e=v.onLabelUpdate("active",e,d.value,d.total),e&&d.set.label(e),d.bind.transitionEnd(function(){v.onActive.call(E,d.value,d.total)})},success:function(e){e=e||v.text.success||v.text.active,d.debug("Setting success state"),w.addClass(g.success),d.remove.active(),d.remove.warning(),d.remove.error(),d.complete(),v.text.success?(e=v.onLabelUpdate("success",e,d.value,d.total),d.set.label(e)):(e=v.onLabelUpdate("active",e,d.value,d.total),d.set.label(e)),d.bind.transitionEnd(function(){v.onSuccess.call(E,d.total)})},warning:function(e){e=e||v.text.warning,d.debug("Setting warning state"),w.addClass(g.warning),d.remove.active(),d.remove.success(),d.remove.error(),d.complete(),e=v.onLabelUpdate("warning",e,d.value,d.total),e&&d.set.label(e),d.bind.transitionEnd(function(){v.onWarning.call(E,d.value,d.total)})},error:function(e){e=e||v.text.error,d.debug("Setting error state"),w.addClass(g.error),d.remove.active(),d.remove.success(),d.remove.warning(),d.complete(),e=v.onLabelUpdate("error",e,d.value,d.total),e&&d.set.label(e),d.bind.transitionEnd(function(){v.onError.call(E,d.value,d.total)})},transitionEvent:function(){a=d.get.transitionEnd()},total:function(e){d.total=e},value:function(e){d.value=e},progress:function(e){d.has.progressPoll()?(d.debug("Updated within interval, setting next update to use new value",e),d.set.nextValue(e)):(d.debug("First update in progress update interval, immediately updating",e),d.update.progress(e),d.create.progressPoll())},nextValue:function(e){d.nextValue=e}},update:{toNextValue:function(){var e=d.nextValue;e&&(d.debug("Update interval complete using last updated value",e),d.update.progress(e),d.remove.nextValue())},progress:function(e){var t;e=d.get.numericValue(e),!1===e&&d.error(b.nonNumeric,e),e=d.get.normalizedValue(e),d.has.total()?(d.set.value(e),t=e/d.total*100,d.debug("Calculating percent complete from total",t),d.set.percent(t)):(t=e,d.debug("Setting value to exact percentage value",t),d.set.percent(t))}},setting:function(t,n){if(d.debug("Changing setting",t,n),e.isPlainObject(t))e.extend(!0,v,t);else{if(void 0===n)return v[t];e.isPlainObject(v[t])?e.extend(!0,v[t],n):v[t]=n}},internal:function(t,n){if(e.isPlainObject(t))e.extend(!0,d,t);else{if(void 0===n)return d[t];d[t]=n}},debug:function(){!v.silent&&v.debug&&(v.performance?d.performance.log(arguments):(d.debug=Function.prototype.bind.call(console.info,console,v.name+":"),d.debug.apply(console,arguments)))},verbose:function(){!v.silent&&v.verbose&&v.debug&&(v.performance?d.performance.log(arguments):(d.verbose=Function.prototype.bind.call(console.info,console,v.name+":"),d.verbose.apply(console,arguments)))},error:function(){v.silent||(d.error=Function.prototype.bind.call(console.error,console,v.name+":"),d.error.apply(console,arguments))},performance:{log:function(e){var t,n,r;v.performance&&(t=(new Date).getTime(),r=i||t,n=t-r,i=t,s.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:E,"Execution Time":n})),clearTimeout(d.performance.timer),d.performance.timer=setTimeout(d.performance.display,500)},display:function(){var t=v.name+":",n=0;i=!1,clearTimeout(d.performance.timer),e.each(s,function(e,t){n+=t["Execution Time"]}),t+=" "+n+"ms",o&&(t+=" '"+o+"'"),(void 0!==console.group||void 0!==console.table)&&s.length>0&&(console.groupCollapsed(t),console.table?console.table(s):e.each(s,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),s=[]}},invoke:function(t,n,a){var o,i,s,l=P;return n=n||u,a=E||a,"string"==typeof t&&void 0!==l&&(t=t.split(/[\. ]/),o=t.length-1,e.each(t,function(n,r){var a=n!=o?r+t[n+1].charAt(0).toUpperCase()+t[n+1].slice(1):t;if(e.isPlainObject(l[a])&&n!=o)l=l[a];else{if(void 0!==l[a])return i=l[a],!1;if(!e.isPlainObject(l[r])||n==o)return void 0!==l[r]?(i=l[r],!1):(d.error(b.method,t),!1);l=l[r]}})),e.isFunction(i)?s=i.apply(a,n):void 0!==i&&(s=i),e.isArray(r)?r.push(s):void 0!==r?r=[r,s]:void 0!==s&&(r=s),i}},c?(void 0===P&&d.initialize(),d.invoke(l)):(void 0!==P&&P.invoke("destroy"),d.initialize())}),void 0!==r?r:this},e.fn.progress.settings={name:"Progress",namespace:"progress",silent:!1,debug:!1,verbose:!1,performance:!0,random:{min:2,max:5},duration:300,updateInterval:"auto",autoSuccess:!0,showActivity:!0,limitValues:!0,label:"percent",precision:0,framerate:1e3/30,percent:!1,total:!1,value:!1,failSafeDelay:100,onLabelUpdate:function(e,t,n,r){return t},onChange:function(e,t,n){},onSuccess:function(e){},onActive:function(e,t){},onError:function(e,t){},onWarning:function(e,t){},error:{method:"The method you called is not defined.",nonNumeric:"Progress value is non numeric",tooHigh:"Value specified is above 100%",tooLow:"Value specified is below 0%"},regExp:{variable:/\{\$*[A-z0-9]+\}/g},metadata:{percent:"percent",total:"total",value:"value"},selector:{bar:"> .bar",label:"> .label",progress:".bar > .progress"},text:{active:!1,error:!1,success:!1,warning:!1,percent:"{percent}%",ratio:"{value} of {total}"},className:{active:"active",error:"error",success:"success",warning:"warning"}}}(jQuery,window,document); |