/*
formBuilder - https://formbuilder.online/
Version: 1.15.2
Author: Kevin Chappell
*/
"use strict";
function FormRenderFn(e, t) {
var n = this, r = {
destroyTemplate: !0,
container: !1,
dataType: "xml",
formData: !1,
label: {
formRendered: "Form Rendered",
noFormData: "No form data.",
other: "Other",
selectColor: "Select Color"
},
render: !0,
notify: {
error: function (e) {
return console.error(e)
}, success: function (e) {
return console.log(e)
}, warning: function (e) {
return console.warn(e)
}
}
}, a = {}, o = $.extend(!0, r, e);
a.getElement = function () {
return t.id || (t.id = a.makeId(t)), document.getElementById(t.id)
}, a.makeId = function (e) {
var t = (new Date).getTime();
return e.tagName + "-" + t
}, !o.formData && t && (t = a.getElement(), o.formData = t.value), a.markup = function (e) {
var t = arguments.length <= 1 || void 0 === arguments[1] ? "" : arguments[1], n = arguments.length <= 2 || void 0 === arguments[2] ? {} : arguments[2], r = void 0, o = document.createElement(e), i = function (e) {
return Array.isArray(e) ? "array" : "undefined" == typeof e ? "undefined" : _typeof(e)
}, l = {
string: function (e) {
o.innerHTML = e
}, object: function (e) {
return o.appendChild(e)
}, array: function (e) {
for (var t = 0; t < e.length; t++)r = i(e[t]), l[r](e[t])
}
};
for (var s in n)if (n.hasOwnProperty(s)) {
var c = a.safeAttrName(s);
o.setAttribute(c, n[s])
}
return r = i(t), t && l[r].call(this, t), o
}, a.fieldRender = function (e) {
var t = "", n = "", r = "", i = a.parseAttrs(e.attributes), l = i.label || "", s = i.description || "", c = "", d = $("option", e);
i.id = i.name, i.type = i.subtype || i.type, i.required && (i.required = null, i["aria-required"] = "true", c = '*'), "hidden" !== i.type && (s && (s = '?'), n = '");
var u = i.label;
delete i.label, delete i.description;
var f = a.attrString(i);
switch (i.type) {
case"textarea":
case"rich-text":
delete i.type, t = n + "";
break;
case"select":
i.type = i.type.replace("-group", ""), d.length && d.each(function (e, t) {
e = e;
var n = a.parseAttrs(t.attributes), o = a.attrString(n);
r += ""
}), t = n + "";
break;
case"checkbox-group":
case"radio-group":
var p = !1;
i.type = i.type.replace("-group", ""), i.other && (delete i.other, p = !0), d.length && !function () {
var e = "checkbox" === i.type ? i.name + "[]" : i.name, t = void 0;
if (d.each(function (n, o) {
var l = $.extend({}, i, a.parseAttrs(o.attributes));
l.selected && (delete l.selected, l.checked = null), l.name = e, l.id = i.id + "-" + n, t = a.attrString(l), r += " "
}), p) {
var n = {id: i.id + "-other", name: e, "class": i["class"] + " other-option"};
t = a.attrString($.extend({}, i, n)), r += " '
}
}(), t = n + '
' + r + "
";
break;
case"text":
case"password":
case"email":
case"number":
case"file":
case"hidden":
case"date":
case"autocomplete":
t = n + " ";
break;
case"color":
t = n + " " + o.label.selectColor;
break;
case"button":
case"submit":
t = "";
break;
case"checkbox":
t = " " + n, i.toggle && setTimeout(function () {
$(document.getElementById(i.id)).kcToggle()
}, 100);
break;
default:
t = "<" + i.type + " " + f + ">" + u + "" + i.type + ">"
}
if ("hidden" !== i.type) {
var m = i.id ? "form-group field-" + i.id : "";
t = a.markup("div", t, {className: m})
} else t = a.markup("input", null, i);
return t
}, a.hyphenCase = function (e) {
return e = e.replace(/[^\w\s\-]/gi, ""), e = e.replace(/([A-Z])/g, function (e) {
return "-" + e.toLowerCase()
}), e.replace(/\s/g, "-").replace(/^-+/g, "")
}, a.attrString = function (e) {
var t = [];
for (var n in e)e.hasOwnProperty(n) && (n = a.safeAttr(n, e[n]), t.push(n.name + n.value));
return t.join(" ")
}, a.safeAttr = function (e, t) {
var n = {className: "class"};
return e = n[e] || e, t = t ? window.JSON.stringify(t) : !1, t = t ? "=" + t : "", {name: e, value: t}
}, a.safeAttrName = function (e) {
var t = {className: "class"};
return t[e] || a.hyphenCase(e)
}, a.parseAttrs = function (e) {
var t = {};
for (var n in e)e.hasOwnProperty(n) && (t[e[n].name] = e[n].value);
return t
}, Element.prototype.appendFormFields = function (e) {
var t = this;
e.reverse();
for (var n = e.length - 1; n >= 0; n--)t.appendChild(e[n])
}, Element.prototype.emptyContainer = function () {
for (var e = this; e.lastChild;)e.removeChild(e.lastChild)
};
var i = function () {
for (var e = document.getElementsByClassName("other-option"), t = function () {
var t = document.getElementById(e[n].id + "-value");
e[n].onclick = function (e) {
var n = this;
this.checked ? (t.style.display = "inline-block", n.nextElementSibling.style.display = "none", t.oninput = function (e) {
n.value = this.value
}) : (t.style.display = "none", n.nextElementSibling.style.display = "inline-block", t.oninput = void 0)
}
}, n = 0; n < e.length; n++)t()
}, l = function () {
i()
}, s = [], c = $.parseXML(o.formData), d = $("field", c);
if (d.length)d.each(function (e, t) {
e = e, s.push(a.fieldRender(t))
}); else {
var u = a.markup("div", o.label.noFormData, {className: "no-form-data"});
s.push(u), o.notify.error(o.label.noFormData)
}
if (o.render) {
if (o.container) {
var f = a.markup("div", s, {className: "rendered-form"});
o.container = o.container instanceof jQuery ? o.container[0] : o.container, o.container.emptyContainer(), o.container.appendChild(f)
} else if (t) {
var p = document.querySelector(".rendered-form");
p ? (p.emptyContainer(), p.appendFormFields(s)) : (p = a.markup("div", s, {className: "rendered-form"}), t.parentNode.insertBefore(p, t.nextSibling), t.style.display = "none", t.setAttribute("disabled", "disabled"))
}
d.length && (l(d), o.notify.success(o.label.formRendered))
} else n.markup = s.map(function (e) {
return e.innerHTML
}).join("");
return n
}
!function (e) {
var t = function (t, n) {
var r = {
theme: "fresh",
labels: {off: "Off", on: "On"}
}, a = e.extend(r, n), o = e('').insertAfter(t).append(t);
o.toggleClass("on", t.is(":checked"));
var i = '
' + a.labels.on + "
", l = '
' + a.labels.off + "
", s = '', c = '
' + i + s + l + "
";
o.append(c), o.click(function () {
t.attr("checked", !t.attr("checked")), e(this).toggleClass("on")
})
};
e.fn.kcToggle = function (n) {
var r = this;
return r.each(function () {
var r = e(this);
if (!r.data("kcToggle")) {
var a = new t(r, n);
r.data("kcToggle", a)
}
})
}
}(jQuery);
var _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (e) {
return typeof e
} : function (e) {
return e && "function" == typeof Symbol && e.constructor === Symbol ? "symbol" : typeof e
};
!function (e) {
e.fn.formRender = function (e) {
this.each(function () {
var t = new FormRenderFn(e, this);
return t
})
}
}(jQuery);