You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
7.6 KiB
1 lines
7.6 KiB
!function(a,b,c,d){"use strict";a.fn.progress=function(b){var e,f=a(this),g=f.selector||"",h=("ontouchstart"in c.documentElement,(new Date).getTime()),i=[],j=arguments[0],k="string"==typeof j,l=[].slice.call(arguments,1);return f.each(function(){var c,f=a.isPlainObject(b)?a.extend(!0,{},a.fn.progress.settings,b):a.extend({},a.fn.progress.settings),m=f.className,n=f.metadata,o=f.namespace,p=f.selector,q=f.error,r="module-"+o,s=a(this),t=a(this).find(p.bar),u=a(this).find(p.progress),v=a(this).find(p.label),w=this,x=s.data(r);c={initialize:function(){c.debug("Initializing progress",f),c.read.metadata(),c.set.initials(),c.instantiate()},instantiate:function(){c.verbose("Storing instance of progress",c),x=c,s.data(r,c)},destroy:function(){c.verbose("Destroying previous dropdown for",s),s.removeData(r),x=d},reset:function(){c.set.percent(0)},complete:function(){(c.percent===d||c.percent<100)&&c.set.percent(100)},read:{metadata:function(){s.data(n.percent)&&(c.verbose("Current percent value set from metadata"),c.percent=s.data(n.percent)),s.data(n.total)&&(c.verbose("Total value set from metadata"),c.total=s.data(n.total)),s.data(n.value)&&(c.verbose("Current value set from metadata"),c.value=s.data(n.value))},currentValue:function(){return c.value!==d?c.value:!1}},increment:function(a){var b,d,e,f=c.total||!1;f?(d=c.value||0,a=a||1,e=d+a,b=c.total,c.debug("Incrementing value by",a,d,b),e>b&&(c.debug("Value cannot increment above total",b),e=b),c.set.progress(e)):(d=c.percent||0,a=a||c.get.randomValue(),e=d+a,b=100,c.debug("Incrementing percentage by",a,d),e>b&&(c.debug("Value cannot increment above 100 percent"),e=b),c.set.progress(e))},decrement:function(a){var b,d,e=c.total||!1,f=0;e?(b=c.value||0,a=a||1,d=b-a,c.debug("Decrementing value by",a,b)):(b=c.percent||0,a=a||c.get.randomValue(),d=b-a,c.debug("Decrementing percentage by",a,b)),f>d&&(c.debug("Value cannot decrement below 0"),d=0),c.set.progress(d)},get:{text:function(a){var b=c.value||0,d=c.total||0,e=c.percent||0;return a=a||"",a=a.replace("{value}",b).replace("{total}",d).replace("{percent}",e),c.debug("Adding variables to progress bar text",a),a},randomValue:function(){return c.debug("Generating random increment percentage"),Math.floor(Math.random()*f.random.max+f.random.min)},percent:function(){return c.percent||0},value:function(){return c.value||!1},total:function(){return c.total||!1}},is:{success:function(){return s.hasClass(m.success)},warning:function(){return s.hasClass(m.warning)},error:function(){return s.hasClass(m.error)}},remove:{active:function(){c.verbose("Removing active state"),s.removeClass(m.active)},success:function(){c.verbose("Removing success state"),s.removeClass(m.success)},warning:function(){c.verbose("Removing warning state"),s.removeClass(m.warning)},error:function(){c.verbose("Removing error state"),s.removeClass(m.error)}},set:{barWidth:function(a){a>100&&c.error(q.tooHigh,a),t.css("width",a+"%")},initials:function(){f.value&&(c.verbose("Current value set in settings",f.value),c.value=f.value),f.total&&(c.verbose("Current total set in settings",f.total),c.total=f.total),f.percent&&(c.verbose("Current percent set in settings",f.percent),c.percent=f.percent),c.percent?c.set.percent(c.percent):c.value&&c.set.progress(c.value)},percent:function(b){b="string"==typeof b?+b.replace("%",""):b,b>0&&1>b&&(c.verbose("Module percentage passed as decimal, converting"),b=100*b),b=Math.round(0===f.precision?b:10*b*f.precision/(10*f.precision)),c.percent=b,c.total&&(c.value=Math.round(b/100*c.total)),c.set.barWidth(b),c.set.barLabel(),100===b?!f.autoSuccess||c.is.warning()||c.is.error()?c.remove.active():(c.set.success(),c.debug("Automatically triggering success at 100%")):c.set.active(),a.proxy(f.onChange,w)(b,c.value,c.total)},label:function(a){a=a||"",a&&(a=c.get.text(a),c.debug("Setting label to text",a),v.text(a))},barLabel:function(a){a!==d?u.text(c.get.text(a)):"ratio"==f.label&&c.total?(c.debug("Adding ratio to bar label"),u.text(c.get.text(f.text.ratio))):"percent"==f.label&&(c.debug("Adding percentage to bar label"),u.text(c.get.text(f.text.percent)))},active:function(a){a=a||f.text.active,c.debug("Setting active state"),f.showActivity&&s.addClass(m.active),c.remove.warning(),c.remove.error(),c.remove.success(),a&&c.set.label(a)},success:function(a){a=a||f.text.success,c.debug("Setting success state"),s.addClass(m.success),c.remove.active(),c.remove.warning(),c.remove.error(),c.complete(),a&&c.set.label(a)},warning:function(a){a=a||f.text.warning,c.debug("Setting warning state"),s.addClass(m.warning),c.remove.active(),c.remove.success(),c.remove.error(),c.complete(),a&&c.set.label(a)},error:function(a){a=a||f.text.error,c.debug("Setting error state"),s.addClass(m.error),c.remove.active(),c.remove.success(),c.remove.warning(),c.complete(),a&&c.set.label(a)},total:function(a){c.total=a},progress:function(a){var b,d="string"==typeof a?""!==a.replace(/[^\d.]/g,"")?+a.replace(/[^\d.]/g,""):!1:a;d||c.error(q.nonNumeric),c.total?(c.value=d,b=d/c.total*100,c.debug("Calculating percent complete from total",b),c.set.percent(b)):(b=d,c.debug("Setting value to exact percentage value",b),c.set.percent(b))}},setting:function(b,e){if(c.debug("Changing setting",b,e),a.isPlainObject(b))a.extend(!0,f,b);else{if(e===d)return f[b];f[b]=e}},internal:function(b,e){if(a.isPlainObject(b))a.extend(!0,c,b);else{if(e===d)return c[b];c[b]=e}},debug:function(){f.debug&&(f.performance?c.performance.log(arguments):(c.debug=Function.prototype.bind.call(console.info,console,f.name+":"),c.debug.apply(console,arguments)))},verbose:function(){f.verbose&&f.debug&&(f.performance?c.performance.log(arguments):(c.verbose=Function.prototype.bind.call(console.info,console,f.name+":"),c.verbose.apply(console,arguments)))},error:function(){c.error=Function.prototype.bind.call(console.error,console,f.name+":"),c.error.apply(console,arguments)},performance:{log:function(a){var b,d,e;f.performance&&(b=(new Date).getTime(),e=h||b,d=b-e,h=b,i.push({Name:a[0],Arguments:[].slice.call(a,1)||"",Element:w,"Execution Time":d})),clearTimeout(c.performance.timer),c.performance.timer=setTimeout(c.performance.display,100)},display:function(){var b=f.name+":",e=0;h=!1,clearTimeout(c.performance.timer),a.each(i,function(a,b){e+=b["Execution Time"]}),b+=" "+e+"ms",g&&(b+=" '"+g+"'"),(console.group!==d||console.table!==d)&&i.length>0&&(console.groupCollapsed(b),console.table?console.table(i):a.each(i,function(a,b){console.log(b.Name+": "+b["Execution Time"]+"ms")}),console.groupEnd()),i=[]}},invoke:function(b,f,g){var h,i,j,k=x;return f=f||l,g=w||g,"string"==typeof b&&k!==d&&(b=b.split(/[\. ]/),h=b.length-1,a.each(b,function(e,f){var g=e!=h?f+b[e+1].charAt(0).toUpperCase()+b[e+1].slice(1):b;if(a.isPlainObject(k[g])&&e!=h)k=k[g];else{if(k[g]!==d)return i=k[g],!1;if(!a.isPlainObject(k[f])||e==h)return k[f]!==d?(i=k[f],!1):(c.error(q.method,b),!1);k=k[f]}})),a.isFunction(i)?j=i.apply(g,f):i!==d&&(j=i),a.isArray(e)?e.push(j):e!==d?e=[e,j]:j!==d&&(e=j),i}},k?(x===d&&c.initialize(),c.invoke(j)):(x!==d&&c.destroy(),c.initialize())}),e!==d?e:this},a.fn.progress.settings={name:"Progress",namespace:"progress",debug:!1,verbose:!0,performance:!0,random:{min:2,max:5},autoSuccess:!0,showActivity:!0,label:"percent",precision:1,percent:!1,total:!1,value:!1,onChange:function(){},error:{method:"The method you called is not defined.",nonNumeric:"Progress value is non numeric"},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);
|