wishthis/semantic/dist/components/progress.min.js
2022-02-23 22:46:34 +01:00

11 lines
No EOL
14 KiB
JavaScript

/*
* # Fomantic UI - 2.8.8
* 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,a=i.selector,s=i.error,o="."+e,g="module-"+e,r=E(this),c=E(this).find(a.bar),v=E(this).find(a.progress),f=E(this).find(a.label),l=this,u=r.data(g),p=!1,d={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(){d.set.duration(),d.set.transitionEvent(),d.debug(l),d.read.metadata(),d.read.settings(),d.instantiate()},instantiate:function(){d.verbose("Storing instance of progress",d),u=d,r.data(g,d)},destroy:function(){d.verbose("Destroying previous progress for",r),clearInterval(u.interval),d.remove.state(),r.removeData(g),u=P},reset:function(){d.remove.nextValue(),d.update.progress(0)},complete:function(e){(d.percent===P||d.percent<100)&&(d.remove.progressPoll(),!0!==e&&d.set.percent(100))},read:{metadata:function(){var e={percent:d.helper.forceArray(r.data(t.percent)),total:r.data(t.total),value:d.helper.forceArray(r.data(t.value))};e.total!==P&&(d.debug("Total value set from metadata",e.total),d.set.total(e.total)),0<e.value.length&&(d.debug("Current value set from metadata",e.value),d.set.value(e.value),d.set.progress(e.value)),0<e.percent.length&&(d.debug("Current percent value set from metadata",e.percent),d.set.percent(e.percent))},settings:function(){!1!==i.total&&(d.debug("Current total set in settings",i.total),d.set.total(i.total)),!1!==i.value&&(d.debug("Current value set in settings",i.value),d.set.value(i.value),d.set.progress(d.value)),!1!==i.percent&&(d.debug("Current percent set in settings",i.percent),d.set.percent(i.percent))}},bind:{transitionEnd:function(t){var e=d.get.transitionEnd();c.one(e+o,function(e){clearTimeout(d.failSafeTimer),t.call(this,e)}),d.failSafeTimer=setTimeout(function(){c.triggerHandler(e)},i.duration+i.failSafeDelay),d.verbose("Adding fail safe timer",d.timer)}},increment:function(e){var t;e=d.has.total()?(t=d.get.value(),e||1):(t=d.get.percent(),e||d.get.randomValue()),d.debug("Incrementing percentage by",t,t=t+e,e),t=d.get.normalizedValue(t),d.set.progress(t)},decrement:function(e){var t,n;d.get.total()?(n=(t=d.get.value())-(e=e||1),d.debug("Decrementing value by",e,t)):(n=(t=d.get.percent())-(e=e||d.get.randomValue()),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,t){var t=t||0,n=d.get.value(t),r=d.get.total(),a=p?d.get.displayPercent(t):d.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]||""),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(100<e)return d.debug("Value cannot increment above 100 percent"),100;return e},updateInterval:function(){return"auto"==i.updateInterval?i.duration:i.updateInterval},randomValue:function(){return d.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(c[e]),t=e.width(),n=r.width(),e=parseInt(e.css("min-width"),10)<t?t/n*100:d.percent;return 0<i.precision?Math.round(e*(10*i.precision))/(10*i.precision):Math.round(e)},percent:function(e){return d.percent&&d.percent[e||0]||0},value:function(e){return d.nextValue||d.value&&d.value[e||0]||0},total:function(){return d.total!==P&&d.total}},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 r.hasClass(n.success)},warning:function(){return r.hasClass(n.warning)},error:function(){return r.hasClass(n.error)},active:function(){return r.hasClass(n.active)},visible:function(){return r.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"),r.removeClass(n.active)},success:function(){d.verbose("Removing success state"),r.removeClass(n.success)},warning:function(){d.verbose("Removing warning state"),r.removeClass(n.warning)},error:function(){d.verbose("Removing error state"),r.removeClass(n.error)}},set:{barWidth:function(e){d.debug("set bar width with ",e),e=d.helper.forceArray(e);var a=-1,o=-1,i=d.helper.sum(e),s=c.length,l=1<s,t=e.map(function(e,t){var n=t===s-1&&0===i,r=E(c[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(c[t]).css({borderTopLeftRadius:t==a?"":0,borderBottomLeftRadius:t==a?"":0,borderTopRightRadius:t==o?"":0,borderBottomRightRadius:t==o?"":0})}),r.attr("data-percent",t)},duration:function(e){e=e||i.duration,d.verbose("Setting progress bar transition duration",e="number"==typeof e?e+"ms":e),c.css({"transition-duration":e})},percent:function(e){e=d.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=d.has.total(),r=d.helper.sum(e),a=1<e.length&&n,o=d.helper.sum(d.helper.forceArray(d.value));a&&o>d.total?d.error(s.sumExceedsTotal,o,d.total):!a&&100<r?d.error(s.tooHigh,r):r<0?d.error(s.tooLow,r):(t=0<i.precision?i.precision:a?d.helper.derivePrecision(Math.min.apply(null,d.value),d.total):0,o=e.map(function(e){return 0<t?Math.round(e*(10*t))/(10*t):Math.round(e)}),d.percent=o,n&&(d.value=e.map(function(e){return 0<t?Math.round(e/100*d.total*(10*t))/(10*t):Math.round(e/100*d.total*10)/10})),d.set.barWidth(e),d.set.labelInterval()),i.onChange.call(l,e,d.value,d.total)},labelInterval:function(){clearInterval(d.interval),d.bind.transitionEnd(function(){d.verbose("Bar finished animating, removing continuous label updates"),clearInterval(d.interval),p=!1,d.set.labels()}),p=!0,d.interval=setInterval(function(){E.contains(T.documentElement,l)||(clearInterval(d.interval),p=!1),d.set.labels()},i.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),f.text(e))},state:function(e){100===(e=e!==P?e:d.helper.sum(d.percent))?i.autoSuccess&&1===c.length&&!(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()):0<e?(d.verbose("Adjusting active progress bar label",e),d.set.active()):(d.remove.active(),d.set.label(i.text.active))},barLabel:function(n){v.map(function(e,t){t=E(t);n!==P?t.text(d.get.text(n,e)):"ratio"==i.label&&d.has.total()?(d.verbose("Adding ratio to bar label"),t.text(d.get.text(i.text.ratio,e))):"percent"==i.label&&(d.verbose("Adding percentage to bar label"),t.text(d.get.text(i.text.percent,e)))})},active:function(e){e=e||i.text.active,d.debug("Setting active state"),i.showActivity&&!d.is.active()&&r.addClass(n.active),d.remove.warning(),d.remove.error(),d.remove.success(),(e=i.onLabelUpdate("active",e,d.value,d.total))&&d.set.label(e),d.bind.transitionEnd(function(){i.onActive.call(l,d.value,d.total)})},success:function(e,t){e=e||i.text.success||i.text.active,d.debug("Setting success state"),r.addClass(n.success),d.remove.active(),d.remove.warning(),d.remove.error(),d.complete(t),e=i.text.success?i.onLabelUpdate("success",e,d.value,d.total):i.onLabelUpdate("active",e,d.value,d.total),d.set.label(e),d.bind.transitionEnd(function(){i.onSuccess.call(l,d.total)})},warning:function(e,t){e=e||i.text.warning,d.debug("Setting warning state"),r.addClass(n.warning),d.remove.active(),d.remove.success(),d.remove.error(),d.complete(t),(e=i.onLabelUpdate("warning",e,d.value,d.total))&&d.set.label(e),d.bind.transitionEnd(function(){i.onWarning.call(l,d.value,d.total)})},error:function(e,t){e=e||i.text.error,d.debug("Setting error state"),r.addClass(n.error),d.remove.active(),d.remove.success(),d.remove.warning(),d.complete(t),(e=i.onLabelUpdate("error",e,d.value,d.total))&&d.set.label(e),d.bind.transitionEnd(function(){i.onError.call(l,d.value,d.total)})},transitionEvent:function(){d.get.transitionEnd()},total:function(e){d.total=e},value:function(e){d.value=d.helper.forceArray(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 n=d.has.total(),e=(n&&d.set.value(e),d.helper.forceArray(e).map(function(e){var t;return!1===(e=d.get.numericValue(e))&&d.error(s.nonNumeric,e),e=d.get.normalizedValue(e),n?(t=0<d.total?e/d.total*100:100,d.debug("Calculating percent complete from total",t)):(t=e,d.debug("Setting value to exact percentage value",t)),t}));d.set.percent(e)}},setting:function(e,t){if(d.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,d,e);else{if(t===P)return d[e];d[e]=t}},debug:function(){!i.silent&&i.debug&&(i.performance?d.performance.log(arguments):(d.debug=Function.prototype.bind.call(console.info,console,i.name+":"),d.debug.apply(console,arguments)))},verbose:function(){!i.silent&&i.verbose&&i.debug&&(i.performance?d.performance.log(arguments):(d.verbose=Function.prototype.bind.call(console.info,console,i.name+":"),d.verbose.apply(console,arguments)))},error:function(){i.silent||(d.error=Function.prototype.bind.call(console.error,console,i.name+":"),d.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:l,"Execution Time":n})),clearTimeout(d.performance.timer),d.performance.timer=setTimeout(d.performance.display,500)},display:function(){var e=i.name+":",n=0;x=!1,clearTimeout(d.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=u;return e=e||V,t=l||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]:d.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?(u===P&&d.initialize(),d.invoke(w)):(u!==P&&u.invoke("destroy"),d.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 multple 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);