wishthis/node_modules/fomantic-ui/dist/components/progress.min.js
2022-06-16 13:46:53 +02:00

11 lines
No EOL
14 KiB
JavaScript

/*
* # Fomantic UI - 2.9.0-beta.294+786baef
* https://github.com/fomantic/Fomantic-UI
* http://fomantic-ui.com/
*
* Copyright 2022 Contributors
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/
!function(E,e,T,P){"use strict";E.isFunction=E.isFunction||function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},e=void 0!==e&&e.Math==Math?e:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),E.fn.progress=function(m){var b,e=E(this),h=e.selector||"",x=(new Date).getTime(),y=[],w=m,A="string"==typeof w,V=[].slice.call(arguments,1);return e.each(function(){var i=E.isPlainObject(m)?E.extend(!0,{},E.fn.progress.settings,m):E.extend({},E.fn.progress.settings),n=i.className,t=i.metadata,e=i.namespace,r=i.selector,s=i.error,a="."+e,o="module-"+e,c=E(this),u=E(this).find(r.bar),l=E(this).find(r.progress),p=E(this).find(r.label),d=this,g=c.data(o),v=!1,f={helper:{sum:function(e){return Array.isArray(e)?e.reduce(function(e,t){return e+Number(t)},0):0},derivePrecision:function(e,t){for(var n=0,r=1,a=e/t;n<10&&!(1<(a*=r));)r=Math.pow(10,n++);return r},forceArray:function(e){return Array.isArray(e)?e:isNaN(e)?"string"==typeof e?e.split(","):[]:[e]}},initialize:function(){f.set.duration(),f.set.transitionEvent(),f.debug(d),f.read.metadata(),f.read.settings(),f.instantiate()},instantiate:function(){f.verbose("Storing instance of progress",f),g=f,c.data(o,f)},destroy:function(){f.verbose("Destroying previous progress for",c),clearInterval(g.interval),f.remove.state(),c.removeData(o),g=P},reset:function(){f.remove.nextValue(),f.update.progress(0)},complete:function(e){(f.percent===P||f.percent<100)&&(f.remove.progressPoll(),!0!==e&&f.set.percent(100))},read:{metadata:function(){var e={percent:f.helper.forceArray(c.data(t.percent)),total:c.data(t.total),value:f.helper.forceArray(c.data(t.value))};e.total!==P&&(f.debug("Total value set from metadata",e.total),f.set.total(e.total)),0<e.value.length&&(f.debug("Current value set from metadata",e.value),f.set.value(e.value),f.set.progress(e.value)),0<e.percent.length&&(f.debug("Current percent value set from metadata",e.percent),f.set.percent(e.percent))},settings:function(){!1!==i.total&&(f.debug("Current total set in settings",i.total),f.set.total(i.total)),!1!==i.value&&(f.debug("Current value set in settings",i.value),f.set.value(i.value),f.set.progress(f.value)),!1!==i.percent&&(f.debug("Current percent set in settings",i.percent),f.set.percent(i.percent))}},bind:{transitionEnd:function(t){var e=f.get.transitionEnd();u.one(e+a,function(e){clearTimeout(f.failSafeTimer),t.call(this,e)}),f.failSafeTimer=setTimeout(function(){u.triggerHandler(e)},i.duration+i.failSafeDelay),f.verbose("Adding fail safe timer",f.timer)}},increment:function(e){var t;e=f.has.total()?(t=f.get.value(),e||1):(t=f.get.percent(),e||f.get.randomValue()),f.debug("Incrementing percentage by",t,t=t+e,e),t=f.get.normalizedValue(t),f.set.progress(t)},decrement:function(e){var t,n;f.get.total()?(n=(t=f.get.value())-(e=e||1),f.debug("Decrementing value by",e,t)):(n=(t=f.get.percent())-(e=e||f.get.randomValue()),f.debug("Decrementing percentage by",e,t)),n=f.get.normalizedValue(n),f.set.progress(n)},has:{progressPoll:function(){return f.progressPoll},total:function(){return!1!==f.get.total()}},get:{text:function(e,t){var t=t||0,n=f.get.value(t),r=f.get.total(),a=v?f.get.displayPercent(t):f.get.percent(t),o=!1!==r?Math.max(0,r-n):100-a;return e=(e=e||"").replace("{value}",n).replace("{total}",r||0).replace("{left}",o).replace("{percent}",a).replace("{bar}",i.text.bars[t]||""),f.verbose("Adding variables to progress bar text",e),e},normalizedValue:function(e){if(e<0)return f.debug("Value cannot decrement below 0"),0;if(f.has.total()){if(e>f.total)return f.debug("Value cannot increment above total",f.total),f.total}else if(100<e)return f.debug("Value cannot increment above 100 percent"),100;return e},updateInterval:function(){return"auto"==i.updateInterval?i.duration:i.updateInterval},randomValue:function(){return f.debug("Generating random increment percentage"),Math.floor(Math.random()*i.random.max+i.random.min)},numericValue:function(e){return"string"==typeof e?""!==e.replace(/[^\d.]/g,"")&&+e.replace(/[^\d.]/g,""):e},transitionEnd:function(){var e,t=T.createElement("element"),n={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(e in n)if(t.style[e]!==P)return n[e]},displayPercent:function(e){var e=E(u[e]),t=e.width(),n=c.width(),e=parseInt(e.css("min-width"),10)<t?t/n*100:f.percent;return 0<i.precision?Math.round(e*(10*i.precision))/(10*i.precision):Math.round(e)},percent:function(e){return f.percent&&f.percent[e||0]||0},value:function(e){return f.nextValue||f.value&&f.value[e||0]||0},total:function(){return f.total!==P&&f.total}},create:{progressPoll:function(){f.progressPoll=setTimeout(function(){f.update.toNextValue(),f.remove.progressPoll()},f.get.updateInterval())}},is:{complete:function(){return f.is.success()||f.is.warning()||f.is.error()},success:function(){return c.hasClass(n.success)},warning:function(){return c.hasClass(n.warning)},error:function(){return c.hasClass(n.error)},active:function(){return c.hasClass(n.active)},visible:function(){return c.is(":visible")}},remove:{progressPoll:function(){f.verbose("Removing progress poll timer"),f.progressPoll&&(clearTimeout(f.progressPoll),delete f.progressPoll)},nextValue:function(){f.verbose("Removing progress value stored for next update"),delete f.nextValue},state:function(){f.verbose("Removing stored state"),delete f.total,delete f.percent,delete f.value},active:function(){f.verbose("Removing active state"),c.removeClass(n.active)},success:function(){f.verbose("Removing success state"),c.removeClass(n.success)},warning:function(){f.verbose("Removing warning state"),c.removeClass(n.warning)},error:function(){f.verbose("Removing error state"),c.removeClass(n.error)}},set:{barWidth:function(e){f.debug("set bar width with ",e),e=f.helper.forceArray(e);var a=-1,o=-1,i=f.helper.sum(e),s=u.length,l=1<s,t=e.map(function(e,t){var n=t===s-1&&0===i,r=E(u[t]);return 0===e&&l&&!n?r.css("display","none"):(l&&n&&r.css("background","transparent"),-1==a&&(a=t),o=t,r.css({display:"block",width:e+"%"})),parseFloat(e)});e.forEach(function(e,t){E(u[t]).css({borderTopLeftRadius:t==a?"":0,borderBottomLeftRadius:t==a?"":0,borderTopRightRadius:t==o?"":0,borderBottomRightRadius:t==o?"":0})}),c.attr("data-percent",t)},duration:function(e){e=e||i.duration,f.verbose("Setting progress bar transition duration",e="number"==typeof e?e+"ms":e),u.css({"transition-duration":e})},percent:function(e){e=f.helper.forceArray(e).map(function(e){return e="string"==typeof e?+e.replace("%",""):e,i.limitValues?Math.max(0,Math.min(100,e)):e});var t,n=f.has.total(),r=f.helper.sum(e),a=1<e.length&&n,o=f.helper.sum(f.helper.forceArray(f.value));a&&o>f.total?f.error(s.sumExceedsTotal,o,f.total):!a&&100<r?f.error(s.tooHigh,r):r<0?f.error(s.tooLow,r):(t=0<i.precision?i.precision:a?f.helper.derivePrecision(Math.min.apply(null,f.value),f.total):0,o=e.map(function(e){return 0<t?Math.round(e*(10*t))/(10*t):Math.round(e)}),f.percent=o,n&&(f.value=e.map(function(e){return 0<t?Math.round(e/100*f.total*(10*t))/(10*t):Math.round(e/100*f.total*10)/10})),f.set.barWidth(e),f.set.labelInterval()),i.onChange.call(d,e,f.value,f.total)},labelInterval:function(){clearInterval(f.interval),f.bind.transitionEnd(function(){f.verbose("Bar finished animating, removing continuous label updates"),clearInterval(f.interval),v=!1,f.set.labels()}),v=!0,f.interval=setInterval(function(){E.contains(T.documentElement,d)||(clearInterval(f.interval),v=!1),f.set.labels()},i.framerate)},labels:function(){f.verbose("Setting both bar progress and outer label text"),f.set.barLabel(),f.set.state()},label:function(e){(e=e||"")&&(e=f.get.text(e),f.verbose("Setting label to text",e),p.text(e))},state:function(e){100===(e=e!==P?e:f.helper.sum(f.percent))?i.autoSuccess&&1===u.length&&!(f.is.warning()||f.is.error()||f.is.success())?(f.set.success(),f.debug("Automatically triggering success at 100%")):(f.verbose("Reached 100% removing active state"),f.remove.active(),f.remove.progressPoll()):0<e?(f.verbose("Adjusting active progress bar label",e),f.set.active()):(f.remove.active(),f.remove.warning(),f.remove.error(),f.remove.success(),f.set.label(i.text.active))},barLabel:function(n){l.map(function(e,t){t=E(t);n!==P?t.text(f.get.text(n,e)):"ratio"==i.label&&f.has.total()?(f.verbose("Adding ratio to bar label"),t.text(f.get.text(i.text.ratio,e))):"percent"==i.label&&(f.verbose("Adding percentage to bar label"),t.text(f.get.text(i.text.percent,e)))})},active:function(e){e=e||i.text.active,f.debug("Setting active state"),i.showActivity&&!f.is.active()&&c.addClass(n.active),f.remove.warning(),f.remove.error(),f.remove.success(),(e=i.onLabelUpdate("active",e,f.value,f.total))&&f.set.label(e),f.bind.transitionEnd(function(){i.onActive.call(d,f.value,f.total)})},success:function(e,t){e=e||i.text.success||i.text.active,f.debug("Setting success state"),c.addClass(n.success),f.remove.active(),f.remove.warning(),f.remove.error(),f.complete(t),e=i.text.success?i.onLabelUpdate("success",e,f.value,f.total):i.onLabelUpdate("active",e,f.value,f.total),f.set.label(e),f.bind.transitionEnd(function(){i.onSuccess.call(d,f.total)})},warning:function(e,t){e=e||i.text.warning,f.debug("Setting warning state"),c.addClass(n.warning),f.remove.active(),f.remove.success(),f.remove.error(),f.complete(t),(e=i.onLabelUpdate("warning",e,f.value,f.total))&&f.set.label(e),f.bind.transitionEnd(function(){i.onWarning.call(d,f.value,f.total)})},error:function(e,t){e=e||i.text.error,f.debug("Setting error state"),c.addClass(n.error),f.remove.active(),f.remove.success(),f.remove.warning(),f.complete(t),(e=i.onLabelUpdate("error",e,f.value,f.total))&&f.set.label(e),f.bind.transitionEnd(function(){i.onError.call(d,f.value,f.total)})},transitionEvent:function(){f.get.transitionEnd()},total:function(e){f.total=e},value:function(e){f.value=f.helper.forceArray(e)},progress:function(e){f.has.progressPoll()?(f.debug("Updated within interval, setting next update to use new value",e),f.set.nextValue(e)):(f.debug("First update in progress update interval, immediately updating",e),f.update.progress(e),f.create.progressPoll())},nextValue:function(e){f.nextValue=e}},update:{toNextValue:function(){var e=f.nextValue;e&&(f.debug("Update interval complete using last updated value",e),f.update.progress(e),f.remove.nextValue())},progress:function(e){var n=f.has.total(),e=(n&&f.set.value(e),f.helper.forceArray(e).map(function(e){var t;return!1===(e=f.get.numericValue(e))&&f.error(s.nonNumeric,e),e=f.get.normalizedValue(e),n?(t=0<f.total?e/f.total*100:100,f.debug("Calculating percent complete from total",t)):(t=e,f.debug("Setting value to exact percentage value",t)),t}));f.set.percent(e)}},setting:function(e,t){if(f.debug("Changing setting",e,t),E.isPlainObject(e))E.extend(!0,i,e);else{if(t===P)return i[e];E.isPlainObject(i[e])?E.extend(!0,i[e],t):i[e]=t}},internal:function(e,t){if(E.isPlainObject(e))E.extend(!0,f,e);else{if(t===P)return f[e];f[e]=t}},debug:function(){!i.silent&&i.debug&&(i.performance?f.performance.log(arguments):(f.debug=Function.prototype.bind.call(console.info,console,i.name+":"),f.debug.apply(console,arguments)))},verbose:function(){!i.silent&&i.verbose&&i.debug&&(i.performance?f.performance.log(arguments):(f.verbose=Function.prototype.bind.call(console.info,console,i.name+":"),f.verbose.apply(console,arguments)))},error:function(){i.silent||(f.error=Function.prototype.bind.call(console.error,console,i.name+":"),f.error.apply(console,arguments))},performance:{log:function(e){var t,n;i.performance&&(n=(t=(new Date).getTime())-(x||t),x=t,y.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:d,"Execution Time":n})),clearTimeout(f.performance.timer),f.performance.timer=setTimeout(f.performance.display,500)},display:function(){var e=i.name+":",n=0;x=!1,clearTimeout(f.performance.timer),E.each(y,function(e,t){n+=t["Execution Time"]}),e+=" "+n+"ms",h&&(e+=" '"+h+"'"),(console.group!==P||console.table!==P)&&0<y.length&&(console.groupCollapsed(e),console.table?console.table(y):E.each(y,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),y=[]}},invoke:function(r,e,t){var a,o,n,i=g;return e=e||V,t=d||t,"string"==typeof r&&i!==P&&(r=r.split(/[\. ]/),a=r.length-1,E.each(r,function(e,t){var n=e!=a?t+r[e+1].charAt(0).toUpperCase()+r[e+1].slice(1):r;if(E.isPlainObject(i[n])&&e!=a)i=i[n];else{if(i[n]!==P)return o=i[n],!1;{if(!E.isPlainObject(i[t])||e==a)return i[t]!==P?o=i[t]:f.error(s.method,r),!1;i=i[t]}}})),E.isFunction(o)?n=o.apply(t,e):o!==P&&(n=o),Array.isArray(b)?b.push(n):b!==P?b=[b,n]:n!==P&&(b=n),o}};A?(g===P&&f.initialize(),f.invoke(w)):(g!==P&&g.invoke("destroy"),f.initialize())}),b!==P?b: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%",sumExceedsTotal:"Sum of multiple values exceed total"},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}",bars:[""]},className:{active:"active",error:"error",success:"success",warning:"warning"}}}(jQuery,window,document);