11 lines
No EOL
13 KiB
JavaScript
11 lines
No EOL
13 KiB
JavaScript
/*
|
|
* # Fomantic UI - 2.9.2
|
|
* https://github.com/fomantic/Fomantic-UI
|
|
* https://fomantic-ui.com/
|
|
*
|
|
* Copyright 2023 Contributors
|
|
* Released under the MIT license
|
|
* https://opensource.org/licenses/MIT
|
|
*
|
|
*/
|
|
!function(P,e,C){"use strict";e=void 0!==e&&e.Math===Math?e:globalThis,P.fn.progress=function(m){var b,e=P(this),h=e.selector||"",x=Date.now(),y=[],w=m,V="string"==typeof w,A=[].slice.call(arguments,1);return e.each(function(){var i=P.isPlainObject(m)?P.extend(!0,{},P.fn.progress.settings,m):P.extend({},P.fn.progress.settings),r=i.className,t=i.metadata,e=i.namespace,n=i.selector,l=i.error,a="."+e,o="module-"+e,c=P(this),u=P(this).find(n.bar),s=P(this).find(n.progress),d=P(this).find(n.label),p=this,v=c.data(o),g=!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 r=0,n=1,a=e/t;r<10&&!(1<(a*=n));)n=Math.pow(10,r++);return n},forceArray:function(e){return Array.isArray(e)?e:isNaN(e)?"string"==typeof e?e.split(","):[]:[e]}},initialize:function(){f.set.duration(),f.debug(p),f.read.metadata(),f.read.settings(),f.instantiate()},instantiate:function(){f.verbose("Storing instance of progress",f),v=f,c.data(o,f)},destroy:function(){f.verbose("Destroying previous progress for",c),clearInterval(v.interval),f.remove.state(),c.removeData(o),v=void 0},reset:function(){f.remove.nextValue(),f.update.progress(0)},complete:function(e){(void 0===f.percent||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))};void 0!==e.total&&(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){u.one("transitionend"+a,function(e){clearTimeout(f.failSafeTimer),t.call(this,e)}),f.failSafeTimer=setTimeout(function(){u.triggerHandler("transitionend")},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,r;f.get.total()?(r=(t=f.get.value())-(e=e||1),f.debug("Decrementing value by",e,t)):(r=(t=f.get.percent())-(e=e||f.get.randomValue()),f.debug("Decrementing percentage by",e,t)),r=f.get.normalizedValue(r),f.set.progress(r)},has:{progressPoll:function(){return f.progressPoll},total:function(){return!1!==f.get.total()}},get:{text:function(e,t){var r=f.get.value(t=t||0),n=f.get.total(),a=g?f.get.displayPercent(t):f.get.percent(t),o=!1!==n?Math.max(0,n-r):100-a;return e=(e=e||"").replace("{value}",r).replace("{total}",n||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},displayPercent:function(e){var e=P(u[e]),t=e.width(),r=c.width(),e=parseInt(e.css("min-width"),10)<t?t/r*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 void 0!==f.total&&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(r.success)},warning:function(){return c.hasClass(r.warning)},error:function(){return c.hasClass(r.error)},active:function(){return c.hasClass(r.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(r.active)},success:function(){f.verbose("Removing success state"),c.removeClass(r.success)},warning:function(){f.verbose("Removing warning state"),c.removeClass(r.warning)},error:function(){f.verbose("Removing error state"),c.removeClass(r.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 r=t===s-1&&0===i,n=P(u[t]);return 0===e&&l&&!r?n.css("display","none"):(l&&r&&n.css("background","transparent"),-1===a&&(a=t),o=t,n.css({display:"block",width:e+"%"})),parseFloat(e)});e.forEach(function(e,t){P(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,r=f.has.total(),n=f.helper.sum(e),a=1<e.length&&r,o=f.helper.sum(f.helper.forceArray(f.value));a&&o>f.total?f.error(l.sumExceedsTotal,o,f.total):!a&&100<n?f.error(l.tooHigh,n):n<0?f.error(l.tooLow,n):(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,r&&(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(p,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),g=!1,f.set.labels()}),g=!0,f.interval=setInterval(function(){P.contains(C.documentElement,p)||(clearInterval(f.interval),g=!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=f.get.text(e),f.verbose("Setting label to text",e),d.text(e))},state:function(e){100===(e=void 0!==e?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(r){s.each(function(e,t){t=P(t);void 0!==r?t.text(f.get.text(r,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(r.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(p,f.value,f.total)})},success:function(e,t){e=e||i.text.success||i.text.active,f.debug("Setting success state"),c.addClass(r.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(p,f.total)})},warning:function(e,t){e=e||i.text.warning,f.debug("Setting warning state"),c.addClass(r.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(p,f.value,f.total)})},error:function(e,t){e=e||i.text.error,f.debug("Setting error state"),c.addClass(r.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(p,f.value,f.total)})},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 r=f.has.total(),e=(r&&f.set.value(e),f.helper.forceArray(e).map(function(e){var t;return!1===(e=f.get.numericValue(e))&&f.error(l.nonNumeric,e),e=f.get.normalizedValue(e),r?(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),P.isPlainObject(e))P.extend(!0,i,e);else{if(void 0===t)return i[e];P.isPlainObject(i[e])?P.extend(!0,i[e],t):i[e]=t}},internal:function(e,t){if(P.isPlainObject(e))P.extend(!0,f,e);else{if(void 0===t)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,r;i.performance&&(r=(t=Date.now())-(x||t),x=t,y.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:p,"Execution Time":r})),clearTimeout(f.performance.timer),f.performance.timer=setTimeout(f.performance.display,500)},display:function(){var e=i.name+":",r=0;x=!1,clearTimeout(f.performance.timer),P.each(y,function(e,t){r+=t["Execution Time"]}),e+=" "+r+"ms",h&&(e+=" '"+h+"'"),0<y.length&&(console.groupCollapsed(e),console.table?console.table(y):P.each(y,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),y=[]}},invoke:function(n,e,t){var a,o,r,i,s=v;return e=e||A,t=t||p,"string"==typeof n&&void 0!==s&&(n=n.split(/[ .]/),a=n.length-1,P.each(n,function(e,t){var r=e!==a?t+n[e+1].charAt(0).toUpperCase()+n[e+1].slice(1):n;if(P.isPlainObject(s[r])&&e!==a)s=s[r];else{if(void 0!==s[r])return o=s[r],!1;{if(!P.isPlainObject(s[t])||e===a)return void 0!==s[t]?o=s[t]:f.error(l.method,n),!1;s=s[t]}}})),"function"==typeof(i=o)&&"number"!=typeof i.nodeType?r=o.apply(t,e):void 0!==o&&(r=o),Array.isArray(b)?b.push(r):void 0!==b?b=[b,r]:void 0!==r&&(b=r),o}};V?(void 0===v&&f.initialize(),f.invoke(w)):(void 0!==v&&v.invoke("destroy"),f.initialize())}),void 0!==b?b:this},P.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,r,n){return t},onChange:function(e,t,r){},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:/{\$*[\da-z]+}/gi},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); |