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.

10 lines
7.8 KiB

10 years ago
  1. /*
  2. * # Semantic UI
  3. * git://github.com/Semantic-Org/Semantic-UI.git
  4. *
  5. *
  6. * Copyright 2014 Contributors
  7. * Released under the MIT license
  8. * http://opensource.org/licenses/MIT
  9. *
  10. */
  11. !function(e,t,n,r){"use strict";e.fn.progress=function(t){var a,o=e(this),s=o.selector||"",c=("ontouchstart"in n.documentElement,(new Date).getTime()),i=[],l=arguments[0],u="string"==typeof l,g=[].slice.call(arguments,1);return o.each(function(){var n,o=e.isPlainObject(t)?e.extend(!0,{},e.fn.progress.settings,t):e.extend({},e.fn.progress.settings),p=o.className,m=o.metadata,v=o.namespace,d=o.selector,b=o.error,f="module-"+v,h=e(this),x=e(this).find(d.bar),y=e(this).find(d.progress),w=e(this).find(d.label),C=this,A=h.data(f);n={initialize:function(){n.debug("Initializing progress",o),n.read.metadata(),n.set.initials(),n.instantiate()},instantiate:function(){n.verbose("Storing instance of progress",n),A=n,h.data(f,n)},destroy:function(){n.verbose("Destroying previous dropdown for",h),h.removeData(f),A=r},reset:function(){n.set.percent(0)},complete:function(){(n.percent===r||n.percent<100)&&n.set.percent(100)},read:{metadata:function(){h.data(m.percent)&&(n.verbose("Current percent value set from metadata"),n.percent=h.data(m.percent)),h.data(m.total)&&(n.verbose("Total value set from metadata"),n.total=h.data(m.total)),h.data(m.value)&&(n.verbose("Current value set from metadata"),n.value=h.data(m.value))},currentValue:function(){return n.value!==r?n.value:!1}},increment:function(e){var t,r,a,o=n.total||!1;o?(r=n.value||0,e=e||1,a=r+e,t=n.total,n.debug("Incrementing value by",e,r,t),a>t&&(n.debug("Value cannot increment above total",t),a=t),n.set.progress(a)):(r=n.percent||0,e=e||n.get.randomValue(),a=r+e,t=100,n.debug("Incrementing percentage by",e,r),a>t&&(n.debug("Value cannot increment above 100 percent"),a=t),n.set.progress(a))},decrement:function(e){var t,r,a=n.total||!1,o=0;a?(t=n.value||0,e=e||1,r=t-e,n.debug("Decrementing value by",e,t)):(t=n.percent||0,e=e||n.get.randomValue(),r=t-e,n.debug("Decrementing percentage by",e,t)),o>r&&(n.debug("Value cannot decrement below 0"),r=0),n.set.progress(r)},get:{text:function(e){var t=n.value||0,r=n.total||0,a=n.percent||0;return e=e||"",e=e.replace("{value}",t).replace("{total}",r).replace("{percent}",a),n.debug("Adding variables to progress bar text",e),e},randomValue:function(){return n.debug("Generating random increment percentage"),Math.floor(Math.random()*o.random.max+o.random.min)},percent:function(){return n.percent||0},value:function(){return n.value||!1},total:function(){return n.total||!1}},is:{success:function(){return h.hasClass(p.success)},warning:function(){return h.hasClass(p.warning)},error:function(){return h.hasClass(p.error)}},remove:{active:function(){n.verbose("Removing active state"),h.removeClass(p.active)},success:function(){n.verbose("Removing success state"),h.removeClass(p.success)},warning:function(){n.verbose("Removing warning state"),h.removeClass(p.warning)},error:function(){n.verbose("Removing error state"),h.removeClass(p.error)}},set:{barWidth:function(e){e>100&&n.error(b.tooHigh,e),x.css("width",e+"%")},initials:function(){o.value&&(n.verbose("Current value set in settings",o.value),n.value=o.value),o.total&&(n.verbose("Current total set in settings",o.total),n.total=o.total),o.percent&&(n.verbose("Current percent set in settings",o.percent),n.percent=o.percent),n.percent?n.set.percent(n.percent):n.value&&n.set.progress(n.value)},percent:function(t){t="string"==typeof t?+t.replace("%",""):t,t>0&&1>t&&(n.verbose("Module percentage passed as decimal, converting"),t=100*t),t=Math.round(0===o.precision?t:10*t*o.precision/(10*o.precision)),n.percent=t,n.total&&(n.value=Math.round(t/100*n.total)),n.set.barWidth(t),n.set.barLabel(),100===t?!o.autoSuccess||n.is.warning()||n.is.error()?n.remove.active():(n.set.success(),n.debug("Automatically triggering success at 100%")):n.set.active(),e.proxy(o.onChange,C)(t,n.value,n.total)},label:function(e){e=e||"",e&&(e=n.get.text(e),n.debug("Setting label to text",e),w.text(e))},barLabel:function(e){e!==r?y.text(n.get.text(e)):"ratio"==o.label&&n.total?(n.debug("Adding ratio to bar label"),y.text(n.get.text(o.text.ratio))):"percent"==o.label&&(n.debug("Adding percentage to bar label"),y.text(n.get.text(o.te