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.

0 lines
7.6 KiB

10 years ago
  1. !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},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