Files
dev-manufaktur/Dashboard/static/js/smart-forms.min.js
2025-02-16 21:47:35 +01:00

2 lines
20 KiB
JavaScript

!function i(s,a,u){function l(t,e){if(!a[t]){if(!s[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(c)return c(t,!0);var r=new Error("Cannot find module '"+t+"'");throw r.code="MODULE_NOT_FOUND",r}var o=a[t]={exports:{}};s[t][0].call(o.exports,function(e){return l(s[t][1][e]||e)},o,o.exports,i,s,a,u)}return a[t].exports}for(var c="function"==typeof require&&require,e=0;e<u.length;e++)l(u[e]);return l}({1:[function(e,t,n){"use strict";var r=e("./src/Form"),o=e("./src/helpers/on"),i=e("./src/helpers/trigger"),s=e("./src/helpers/isValidURL"),a=e("./src/helpers/addStyles"),u=(e("./src/helpers/messages"),"https://bootstrapstudio.io/smartform-handler"),l="https://bootstrapstudio.io/smartform-iframe?large=1",c="showMessage",f=null,p=document.createElement("iframe"),h=document.createElement("div"),g="",d={filter:"none",transform:"none","transform-style":"flat","backdrop-filter":"none",perspective:"none","content-visibility":"visible",contain:"none"};function y(){v(h),v(p),document.body.attributes.style&&(document.body.attributes.style.value=g),i(f.element,"smart-form-closed")}function v(e){for(;e.firstChild;)e.removeChild(e.firstChild);e.parentNode.removeChild(e)}function m(e){b({operation:c,message:e.message||"",status:e.status||"loading",title:e.title||""},"*")}function b(e,t){p.contentWindow.postMessage(e,t)}function w(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};e.redirectURL&&s(e.redirectURL)?window.location.href=e.redirectURL:(i(f.element,"smart-form-sent"),m({status:"success",title:e.title,message:e.message}),f.reset())}function k(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};i(f.element,"smart-form-error"),m({status:"error",title:e.title,message:e.message})}a(p,{position:"fixed",top:"50%",left:"50%",transform:"translate(-50%, -50%)",display:"block","max-width":"100%",width:"600px",height:"500px",background:"white",border:"none","border-radius":"10px","z-index":"9999"}),a(h,{position:"fixed",display:"block",top:"0",width:"100%",height:"100%","background-color":"rgba(0,0,0,0.7)","z-index":"9998"}),o(p,"load",null,function(){if(!f)return;10485760<f.getFileSize()?m({status:"error",title:f.getMessage("filesize","title",f.getMessage("error","title")),message:f.getMessage("filesize","message")}):b({operation:"showRecaptcha"},"*")}),o(window,"message",null,function(e){var t=e.data,n=t.operation,r=t.recaptchaToken;"submitEmail"===n?(o=r,f.submit(u,"POST",[{name:"recaptchaToken",value:o},{name:"sentFromURL",value:window.location.href}])):"closeIframe"===n&&y();var o}),o(document,"submit","form[data-bss-recipient]",function(e){e.preventDefault(),f=new r(e.target,{onSuccess:w,onError:k,beforeSend:function(e){return m(Object.assign({status:"loading"},e))}}),function(){var e=new URL(l),t=new URLSearchParams(e.search.slice(1)),n=f.getMessage("close");t.append("closeBtnText",n),e.search=t.toString(),p.src=e.toString();var r=document.body;g=r.attributes.style?r.attributes.style.value:"",a(r,d,!0),r.appendChild(p),r.appendChild(h)}()},!0),o(h,"click",null,y)},{"./src/Form":6,"./src/helpers/addStyles":10,"./src/helpers/isValidURL":11,"./src/helpers/messages":12,"./src/helpers/on":13,"./src/helpers/trigger":14}],2:[function(e,t,n){"use strict";var r=function(){function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}}();var o=function(){function t(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t)}return r(t,null,[{key:"get",value:function(e){e.method="GET",t.send(e)}},{key:"post",value:function(e){e.method="POST",t.send(e)}},{key:"send",value:function(n){var e=n.headers||{"X-Requested-With":"XMLHttpRequest"},t=n.body||null,r=n.method||(t?"POST":"GET"),o=n.url,i=new XMLHttpRequest;for(var s in n.beforeSend&&n.beforeSend(),i.open(r,o,!0),i.onload=function(e){if(4===i.readyState){var t={};try{t=JSON.parse(i.responseText),200===i.status?n.success&&n.success(t):n.error&&n.error(t)}catch(e){console.error(e)}}},i.onerror=function(e){n.error&&n.error({})},e)i.setRequestHeader(s,e[s]);i.send(t)}}]),t}();t.exports=o},{}],3:[function(e,t,n){"use strict";var r=function(){function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}}();var o=e("./RadioButton"),i=function(e){function t(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,o),r(t,[{key:"getType",value:function(){return"checkbox"}},{key:"hasValue",value:function(){return!0}},{key:"getName",value:function(){return this.hasMultipleValues()?function e(t,n,r){null===t&&(t=Function.prototype);var o=Object.getOwnPropertyDescriptor(t,n);if(void 0===o){var i=Object.getPrototypeOf(t);return null===i?void 0:e(i,n,r)}if("value"in o)return o.value;var s=o.get;return void 0!==s?s.call(r):void 0}(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"getName",this).call(this):""}},{key:"hasMultipleValues",value:function(){return!!this.getSiblings().length}}]),t}();t.exports=i},{"./RadioButton":8}],4:[function(e,t,n){"use strict";var o=function(){function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}}();var r=function(){function r(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r),this.element=e,this.id=e.id.trim(),this.text=e.innerText.trim()}return o(r,[{key:"isTag",value:function(e){return this.element.tagName.toLowerCase()===e.toLowerCase()}},{key:"find",value:function(e){return this.element.querySelector(e)}},{key:"findAll",value:function(e){return this.element.querySelectorAll(e)}},{key:"getParentByTag",value:function(e){for(var t=this.element;(t=t.parentNode)&&t!==document;){var n=new r(t,this.form);if(n.isTag(e))return n}return null}}]),r}();t.exports=r},{}],5:[function(e,t,n){"use strict";var r=function(){function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}}();var o=e("./FormField"),i=function(e){function t(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,o),r(t,[{key:"getType",value:function(){return"file"}},{key:"getData",value:function(){for(var e=[],t=0;t<this.element.files.length;t++)e.push({name:(this.isNameSet()?this.getName():this.identifier)+(1<this.element.files.length?"[]":""),value:this.element.files[t]});return e}},{key:"getSize",value:function(){for(var e=0,t=0;t<this.element.files.length;t++)e+=this.element.files[t].size;return e}}]),t}();t.exports=i},{"./FormField":7}],6:[function(e,t,n){"use strict";var o=function(){function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}}();var i=e("./Component"),s=e("./Checkbox"),a=e("./FormField"),u=e("./RadioButton"),l=e("./Select"),c=e("./FileField"),f=e("./Ajax"),p=e("./helpers/messages"),r=function(e){function r(e,t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r);var n=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,e));return n.options=t,n.recipient=e.getAttribute("data-bss-recipient"),n.redirectURL=e.getAttribute("data-bss-redirect-url")||"",n.initialize(),n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(r,i),o(r,[{key:"initialize",value:function(){var e=this.element.querySelectorAll("input, textarea, select");this.fields=[];for(var t=0;t<e.length;t++){"submit"!==e[t].type&&this.fields.push(this.createChild(e[t],"field-"+t))}}},{key:"createChild",value:function(e,t){var n=void 0;switch(e.tagName.toLowerCase()){case"input":n="radio"===e.type?new u(e,this,t):"checkbox"===e.type?new s(e,this,t):"file"===e.type?new c(e,this,t):new a(e,this,t);break;case"select":n=new l(e,this,t);break;default:n=new a(e,this,t)}return n}},{key:"getDataFields",value:function(){return this.fields.filter(function(e){return"file"!==e.getType()})}},{key:"getFileFields",value:function(){return this.fields.filter(function(e){return"file"===e.getType()})}},{key:"getData",value:function(){var n=this.getDataFields().slice(),r=[];return n.forEach(function(e){if(e.hasValue())if(e.hasMultipleValues()){var t={name:e.getName(),data:{type:e.getType(),value:[].concat(e.getValue())}};"checkbox"===e.getType()&&e.getSiblings().forEach(function(e){t.data.value.push(e.getValue()),n.splice(n.indexOf(e),1)}),r=r.concat(t)}else r=r.concat(e.getData())}),r}},{key:"getFiles",value:function(){var t=[];return this.getFileFields().forEach(function(e){e.hasValue()&&(t=t.concat(e.getData()))}),t}},{key:"getFieldsByType",value:function(t){return this.fields.filter(function(e){return e instanceof t})}},{key:"getFileSize",value:function(){var e=this.getFieldsByType(c),t=0;return e.forEach(function(e){t+=e.getSize()}),t}},{key:"getAttributeForMessage",value:function(){return"data-bss-"+[0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",1<arguments.length&&void 0!==arguments[1]?arguments[1]:""].filter(function(e){return!!e}).join("-")}},{key:"getKeyForMessage",value:function(){return[0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",1<arguments.length&&void 0!==arguments[1]?arguments[1]:""].filter(function(e){return!!e}).join(".")}},{key:"getDefaultMessage",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"";return p[this.getKeyForMessage(e,t)]||n}},{key:"getCustomMessage",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"";return this.element.getAttribute(this.getAttributeForMessage(e,t))||n}},{key:"getMessage",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"";return this.getCustomMessage(e,t,n)||this.getDefaultMessage(e,t,n)||n}},{key:"submit",value:function(e,t){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:[],r=this.getFiles(),o=new FormData,i=[].filter.call(this.element.attributes,function(e){return e.name.match(/^data-bss-/g)}).map(function(e){return{name:e.name.replace("data-bss-",""),value:e.value}});r=r.concat(n,i);for(var s=0;s<r.length;s++)o.append(r[s].name,r[s].value);o.append("data",JSON.stringify(this.getData())),f.send({url:e,method:t,body:o,error:this.onError.bind(this),success:this.onSuccess.bind(this),beforeSend:this.beforeSend.bind(this)})}},{key:"reset",value:function(){this.element.reset()}},{key:"beforeSend",value:function(){var e={title:this.getMessage("loading","title"),message:this.getMessage("loading","message")};this.options.beforeSend&&this.options.beforeSend(e)}},{key:"onSuccess",value:function(e){var t={title:this.getMessage("success","title"),message:this.getMessage("success","message"),redirectURL:this.redirectURL};this.options.onSuccess&&this.options.onSuccess(t)}},{key:"onError",value:function(e){var t={};e&&e.error&&(t.title=this.getMessage(e.error.type,"title",this.getMessage("error","title")),t.message=this.getMessage(e.error.type,"message")),t.title&&t.message||(t.title=t.title||this.getMessage("error","title"),t.message=t.message||this.getMessage("error","message")),this.options.onError&&this.options.onError(t)}}]),r}();t.exports=r},{"./Ajax":2,"./Checkbox":3,"./Component":4,"./FileField":5,"./FormField":7,"./RadioButton":8,"./Select":9,"./helpers/messages":12}],7:[function(e,t,n){"use strict";var r=function(){function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}}();var i=e("./Component"),o=function(e){function o(e,t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o);var r=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return r.form=t,r.identifier=n,r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(o,i),r(o,[{key:"getType",value:function(){return this.element.type||"text"}},{key:"hasValue",value:function(){return!!this.getValue()}},{key:"hasMultipleValues",value:function(){return!!this.element.multiple}},{key:"getValue",value:function(){return this.element.value.trim()}},{key:"getName",value:function(){var e=this.element.name.trim();if(!e){var t=this.getLabel();e=t?t.text:this.element.placeholder?this.element.placeholder:this.id?this.id:this.getDefaultName()}return this.normalizeName(e)}},{key:"getDefaultName",value:function(){return"Not Defined"}},{key:"isNameSet",value:function(){return this.getName()!==this.getDefaultName()}},{key:"normalizeName",value:function(e){return e.trim()}},{key:"getData",value:function(){return{name:this.getName(),data:{type:this.getType(),value:this.getValue()}}}},{key:"getLabel",value:function(){var e=void 0;if(this.id&&(e=this.form.find("label[for="+this.id+"]")))return new i(e);if(e=this.getParentByTag("label"))return e;var t=this.element.previousElementSibling?new i(this.element.previousElementSibling):null;return t&&t.isTag("label")?t:null}},{key:"getSiblings",value:function(){var t=this;return this.element.name.trim()?this.form.getFieldsByType(this.constructor).filter(function(e){return e!==t&&e.element.name===t.element.name}):[]}}]),o}();t.exports=o},{"./Component":4}],8:[function(e,t,n){"use strict";var r=function(){function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}}(),o=function e(t,n,r){null===t&&(t=Function.prototype);var o=Object.getOwnPropertyDescriptor(t,n);if(void 0===o){var i=Object.getPrototypeOf(t);return null===i?void 0:e(i,n,r)}if("value"in o)return o.value;var s=o.get;return void 0!==s?s.call(r):void 0};var i=e("./FormField"),s=function(e){function n(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(n.__proto__||Object.getPrototypeOf(n)).apply(this,arguments))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(n,i),r(n,[{key:"getType",value:function(){return"radio"}},{key:"hasValue",value:function(){return o(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"hasValue",this).call(this)&&this.element.checked}},{key:"getValue",value:function(){var e=this.getLabel(),t=void 0;return e&&(t=e.text),{value:t||o(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"getValue",this).call(this),active:this.element.checked}}}]),n}();t.exports=s},{"./FormField":7}],9:[function(e,t,n){"use strict";var o=function(){function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}}();var i=e("./FormField"),r=function(e){function r(e,t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r);var n=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,e,t));return n.options=n.element.options,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(r,i),o(r,[{key:"getType",value:function(){return"select"}},{key:"getValue",value:function(){for(var e=[],t=0;t<this.options.length;t++)this.options[t].selected&&e.push({value:this.options[t].textContent});return e}}]),r}();t.exports=r},{"./FormField":7}],10:[function(e,t,n){"use strict";t.exports=function(e,t){var n=2<arguments.length&&void 0!==arguments[2]&&arguments[2];for(var r in t)e.style.setProperty(r,t[r],n?"important":"")}},{}],11:[function(e,t,n){"use strict";t.exports=function(e){try{return e=/^https?:\/\//i.test(e)?new URL(e):new URL(e,window.location.origin),!0}catch(e){return!1}}},{}],12:[function(e,t,n){"use strict";t.exports={close:"Close","loading.title":"","loading.message":"Sending...","success.title":"Success","success.message":"Your message has been delivered.","error.title":"Oops...","error.message":"Something went wrong, please try again later.","filesize.title":"Oops, files are too big!","filesize.message":"Total size should be less than 10mb.","unknown-recipient.title":"Unknown recipient","unknown-recipient.message":"We couldn't locate the email address for sending this form.","empty-form.title":"The form is empty!","empty-form.message":"Please fill in the required fields and try again."}},{}],13:[function(e,t,n){"use strict";t.exports=function(e,t,a,u,n){var r,l=void 0;n=n||!1,(l=e?"string"==typeof e?document.querySelector(e):e:document)&&(r=n?function(e){for(var t=l.querySelectorAll(a),n=e.target,r=0,o=t.length;r<o;r++)for(var i=n,s=t[r];i&&i!==l;){if(i===s)return u.call(s,e);i=i.parentNode}}:u,l.addEventListener(t,r))}},{}],14:[function(e,t,n){"use strict";t.exports=function(e,t){var n=new Event(t,{bubbles:!0,cancelable:!0});setTimeout(function(){e.dispatchEvent(n)},0)}},{}]},{},[1]);