PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.6
JetFormBuilder — Dynamic Blocks Form Builder v3.6.6
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 134 releases
jetformbuilder / assets / build / frontend / calculated.field.js

calculated.field.js in JetFormBuilder — Dynamic Blocks Form Builder 3.6.6, at assets/build/frontend/calculated.field.js

1 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (()=>{"use strict";var __webpack_modules__={7889(__unused_webpack_module,__webpack_exports__,__webpack_require__){function getCalculatedWrapper(e){return e.closest(".jet-form-builder__calculated-field")}function isCalculated(e){var t;return!(null===(t=getCalculatedWrapper(e)?.dataset?.formula?.length)||void 0===t||!t)}function convertMillisToDateString(millisInput,format="YYYY-MM-DD"){const millis=eval(millisInput);if(!millis||isNaN(millis)||null===millis||0===millis)return 0;const date=new Date(millis),monthsFull=["January","February","March","April","May","June","July","August","September","October","November","December"],monthsShort=monthsFull.map(e=>e.slice(0,3)),daysFull=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],daysShort=daysFull.map(e=>e.slice(0,3)),hours12=date.getHours()%12||12,ampm=date.getHours()>=12?"PM":"AM",map={YYYY:date.getFullYear(),MM:String(date.getMonth()+1).padStart(2,"0"),M:date.getMonth()+1,MMM:monthsShort[date.getMonth()],MMMM:monthsFull[date.getMonth()],DD:String(date.getDate()).padStart(2,"0"),D:date.getDate(),HH:String(date.getHours()).padStart(2,"0"),H:date.getHours(),hh:String(hours12).padStart(2,"0"),h:hours12,mm:String(date.getMinutes()).padStart(2,"0"),m:date.getMinutes(),ss:String(date.getSeconds()).padStart(2,"0"),s:date.getSeconds(),dddd:daysFull[date.getDay()],ddd:daysShort[date.getDay()],A:ampm},sortedKeys=Object.keys(map).sort((e,t)=>t.length-e.length);let formatted=format;const placeholders={};sortedKeys.forEach((e,t)=>{const a=`\0${t}\0`;placeholders[a]=String(map[e]);const i=e.length<=2&&/^[a-zA-Z]+$/.test(e)?new RegExp(`\\b${e}\\b`,"g"):new RegExp(e,"g");formatted=formatted.replace(i,a)});for(const[e,t]of Object.entries(placeholders))formatted=formatted.split(e).join(t);return formatted}__webpack_require__.d(__webpack_exports__,{eN:()=>convertMillisToDateString,u3:()=>getCalculatedWrapper,vf:()=>isCalculated})}};const __webpack_module_cache__={};function __webpack_require__(e){const t=__webpack_module_cache__[e];if(void 0!==t)return t.exports;const a=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e](a,a.exports,__webpack_require__),a.exports}__webpack_require__.d=(e,t)=>{for(var a in t)__webpack_require__.o(t,a)&&!__webpack_require__.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let __webpack_exports__={};var functions=__webpack_require__(7889),_window$JetFormBuilde;const{InputData,CalculatedFormula}=window.JetFormBuilderAbstract,{applyFilters}=JetPlugins.hooks,{applyFilters:deprecatedApplyFilters=!1}=null!==(_window$JetFormBuilde=window?.JetFormBuilderMain?.filters)&&void 0!==_window$JetFormBuilde?_window$JetFormBuilde:{};function CalculatedData(){InputData.call(this),this.calculatedFormula=null,this.formula="",this.precision=0,this.sepDecimal="",this.sepThousands="",this.visibleValNode=null,this.valueTypeProp="number",this.isSupported=function(e){return(0,functions.vf)(e)},this.setValue=function(){this.calculatedFormula?.clearWatchers();const e=new CalculatedFormula(this,{forceFunction:!0});this.calculatedFormula=e,e.observe(this.formula),e.setResult=()=>{if("date"===this.valueTypeProp){const t=e.calculate();this.value.current=(0,functions.eN)(t,this.dateFormat)}else this.value.current=e.calculate()},e.relatedCallback=e=>{const t=applyFilters("jet.fb.calculated.callback",!1,e,this);if(!1!==t)return t;const a="number"===this.valueTypeProp?e.calcValue:e.value.current;if(!1===deprecatedApplyFilters)return a;const i=deprecatedApplyFilters("forms/calculated-field-value",e.value.current,jQuery(e.nodes[0]));return i===e.value.current?a:i},e.emptyValue=()=>"number"===this.valueTypeProp?0:"",e.setResult(),this.value.current=this.value.applySanitizers(this.value.current),this.beforeSubmit(t=>{this.value.silence(),this.value.current=null,this.value.silence(),e.setResult(),t()},this)},this.setNode=function(e){InputData.prototype.setNode.call(this,e),InputData.prototype.reQueryValue=()=>{};const{formula:t,precision:a,sepDecimal:i,valueType:l,sepThousands:r,dateFormat:s}=(0,functions.u3)(e).dataset;this.formula=t,this.precision=+a,this.sepDecimal=null!=i?i:"",this.sepThousands=null!=r?r:"",this.visibleValNode=e.nextElementSibling,this.valueTypeProp=l,this.dateFormat=s,this.inputType="calculated"},this.addListeners=function(){},this.report=()=>{},this.reQueryValue=()=>{},this.revertValue=()=>{}}CalculatedData.prototype=Object.create(InputData.prototype);const input=CalculatedData,{BaseSignal}=window.JetFormBuilderAbstract;function SignalCalculated(){BaseSignal.call(this),this.isSupported=function(e){return(0,functions.vf)(e)},this.baseSignal=function(){const[e]=this.input.nodes,t="number"===this.input.valueTypeProp;this.input.calcValue=t?this.withPrecision():this.input.value.current,this.input.value.silence(),this.input.value.current=t?this.convertValue():this.input.value.current,this.input.value.silence(),this.input.visibleValNode.textContent=this.input.value.current,e.value=this.input.calcValue},this.runSignal=function(){this.baseSignal();const[e]=this.input.nodes;this.triggerJQuery(e)}}SignalCalculated.prototype=Object.create(BaseSignal.prototype),SignalCalculated.prototype.convertValue=function(){const e=this.input.value.current;if(Number.isNaN(Number(e)))return 0;const t=this.withPrecision().toString().split(".");return this.input.sepThousands&&(t[0]=t[0].replace(/\B(?=(\d{3})+(?!\d))/g,this.input.sepThousands)),t.join(this.input.sepDecimal)},SignalCalculated.prototype.withPrecision=function(){return Number(this.input.value.current).toFixed(this.input.precision)};const signal=SignalCalculated,{addFilter}=JetPlugins.hooks;addFilter("jet.fb.inputs","jet-form-builder/calculated-field",function(e){return[input,...e]}),addFilter("jet.fb.signals","jet-form-builder/calculated-field",function(e){return[signal,...e]})})();