var ContentBuilder = function () {
"use strict";
function e(t) {
return (e = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (e) {
return typeof e
} : function (e) {
return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
})(t)
}
function t(e, t) {
if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function")
}
function i(e, t) {
for (var i = 0; i < t.length; i++) {
var n = t[i];
n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), Object.defineProperty(e, n.key, n)
}
}
function n(e, t, n) {
return t && i(e.prototype, t), n && i(e, n), e
}
var o, r, a, l, s, c, d, u, p = function () {
function e(i) {
t(this, e), this.builder = i
}
return n(e, [{
key: "cellSelected",
value: function () {
return document.querySelector(".cell-active")
}
}, {
key: "builderStuff",
value: function () {
return document.querySelector("#_cbhtml")
}
}, {
key: "cellNext",
value: function (e) {
var t = new v,
i = e.nextElementSibling;
return i ? t.hasClass(i, "is-row-tool") || t.hasClass(i, "is-rowadd-tool") ? null : i : null
}
}, {
key: "out",
value: function (e) {
if (this.builder) {
var t = this.builder.opts.lang[e];
return t || (this.builder.checkLang && console.log(e), e)
}
return e
}
}, {
key: "confirm",
value: function (e, t) {
var i = this,
n = new v,
o = '
\n
\n
'.concat(e, '
\n \n
\n
"),
r = this.builderStuff(),
a = r.querySelector(".is-confirm");
a || (n.appendHtml(r, o), a = r.querySelector(".is-confirm")), this.showModal(a, !1, (function () {
a.parentNode.removeChild(a), t(!1)
}), !0);
var l = a.querySelector(".is-confirm .input-ok");
n.addEventListener(l, "click", (function () {
i.hideModal(a), a.parentNode.removeChild(a), t(!0)
}))
}
}, {
key: "showModal",
value: function (e, t, i, n) {
var o = this,
r = new v;
r.addClass(e, "active");
var a, l = !1;
if (this.builder ? this.builder.opts.animateModal && (l = !0, n || (l = !1)) : n && (l = !0), l && this.builder) {
var s = document.querySelectorAll(this.builder.opts.container);
Array.prototype.forEach.call(s, (function (e) {
e.style.transform = "scale(0.98)", e.style.WebkitTransform = "scale(0.98)", e.style.MozTransform = "scale(0.98)"
}))
}
if (!e.querySelector(".is-modal-overlay") && (a = t ? '' : '', e.insertAdjacentHTML("afterbegin", a), !t)) {
var c = e.querySelector(".is-modal-overlay");
r.addEventListener(c, "click", (function () {
i && i(), o.hideModal(e)
}))
}
}
}, {
key: "hideModal",
value: function (e) {
if (this.builder) {
var t = document.querySelectorAll(this.builder.opts.container);
Array.prototype.forEach.call(t, (function (e) {
e.style.transform = "", e.style.WebkitTransform = "", e.style.MozTransform = ""
}))
}(new v).removeClass(e, "active")
}
}, {
key: "fixLayout",
value: function (e) {
var t = new v,
i = e.childElementCount - 2,
n = this.builder.opts.row,
o = this.builder.opts.cols,
r = this.builder.opts.colequal;
if (r.length > 0) t.elementChildren(e).forEach((function (e) {
if (!t.hasClass(e, "is-row-tool") && !t.hasClass(e, "is-rowadd-tool")) {
for (var n = 0; n <= o.length - 1; n++) t.removeClass(e, o[n]);
for (var a = 0; a <= r.length - 1; a++)
if (r[a].length === i) {
t.addClass(e, r[a][0]);
break
} 1 === i && t.addClass(e, o[o.length - 1])
}
}));
else if ("" !== n && o.length > 0) {
var a = 0;
t.elementChildren(e).forEach((function (e) {
if (!t.hasClass(e, "is-row-tool") && !t.hasClass(e, "is-rowadd-tool")) {
a++;
for (var n = 0; n <= o.length - 1; n++) t.removeClass(e, o[n]);
1 === i && t.addClass(e, o[11]), 2 === i && t.addClass(e, o[5]), 3 === i && t.addClass(e, o[3]), 4 === i && t.addClass(e, o[2]), 5 === i && (5 === a ? t.addClass(e, o[3]) : t.addClass(e, o[1])), 6 === i && t.addClass(e, o[1]), 7 === i && (a >= 6 ? t.addClass(e, o[0]) : t.addClass(e, o[1])), 8 === i && (a >= 5 ? t.addClass(e, o[0]) : t.addClass(e, o[1])), 9 === i && (a >= 4 ? t.addClass(e, o[0]) : t.addClass(e, o[1])), 10 === i && (a >= 3 ? t.addClass(e, o[0]) : t.addClass(e, o[1])), 11 === i && (a >= 2 ? t.addClass(e, o[0]) : t.addClass(e, o[1])), 12 === i && t.addClass(e, o[0])
}
}))
}
}
}, {
key: "addContent",
value: function (e, t, i) {
var n, o = new v,
r = this.cellSelected();
if (r) n = r.parentNode;
else {
if (!(n = document.querySelector(".row-active"))) return;
t = "row"
}
if ("cell" === t || "cell-left" === t || "cell-right" === t) {
var a, l = 4;
if (this.builder.maxColumns && (l = this.builder.maxColumns), n.childElementCount >= l + 2) return alert(this.out("You have reached the maximum number of columns")), !1;
if (this.builder.uo.saveForUndo(), "" === this.builder.opts.row) {
var s = this.builder.opts.cellFormat,
c = s.indexOf("");
e = s.substring(0, c) + e + s.substring(c), a = this.createElementFromHTML(e)
} else {
(a = r.cloneNode(!0)).removeAttribute("data-noedit"), a.removeAttribute("data-protected"), a.removeAttribute("data-module"), a.removeAttribute("data-module-desc"), a.removeAttribute("data-dialog-width"), a.removeAttribute("data-html"), a.removeAttribute("data-settings");
for (var d = 1; d <= 20; d++) a.removeAttribute("data-html-" + d);
a.removeAttribute("data-noedit"), o.removeClass(a, "cell-active"), a.removeAttribute("data-click"), i && a.setAttribute(i, ""), a.innerHTML = e
}
n.insertBefore(a, r), "cell" !== t && "cell-right" !== t || o.moveAfter(a, r), this.builder.applyBehavior(), this.fixLayout(n), a.click()
}
if ("row" === t) {
var u, p;
if (this.builder.uo.saveForUndo(), "" === this.builder.opts.row) {
u = this.htmlToElement(this.builder.opts.rowFormat);
var h = this.builder.opts.cellFormat,
f = h.indexOf("");
e = h.substring(0, f) + e + h.substring(f);
for (var g = o.elementChildren(u); g.length > 0 && (g = g[0], o.elementChildren(g).length > 0);) g = o.elementChildren(g);
g.innerHTML = e, p = g.firstChild, i && p.setAttribute(i, "")
} else p = o.createElement("div"), o.addClass(p, this.builder.opts.cols[this.builder.opts.cols.length - 1]), p.innerHTML = e, i && p.setAttribute(i, ""), u = o.createElement("div"), o.addClass(u, this.builder.opts.row), o.appendChild(u, p);
n.parentNode.insertBefore(u, n), o.moveAfter(u, n), this.builder.applyBehavior(), p.click()
}
if ("elm" === t) {
var m = this.builder.activeElement;
if (!m) return;
this.builder.uo.saveForUndo();
var y = m;
y.insertAdjacentHTML("afterend", e), this.builder.applyBehavior();
var b, x = y.nextElementSibling;
if ("img" === x.tagName.toLowerCase()) clearTimeout(b), b = setTimeout((function () {
x.complete && x.click()
}), 200);
else x.click()
}
this.builder.opts.onChange()
}
}, {
key: "htmlToElement",
value: function (e) {
var t = document.createElement("template");
return e = e.trim(), t.innerHTML = e, t.content.firstChild
}
}, {
key: "addSnippet",
value: function (e, t, i) {
var n = this;
this.builder.uo.saveForUndo();
var o, r, a, l, s = new v,
c = !1,
d = this.builderStuff().querySelector(".quickadd").getAttribute("data-mode");
if (!t || "cell" !== d && "cell-left" !== d && "cell-right" !== d) {
if (t && "row" === d) {
var u;
if ((a = document.createElement("div")).className = this.builder.opts.cols[this.builder.opts.cols.length - 1], a.innerHTML = e, i && a.setAttribute("data-noedit", ""), (o = document.createElement("div")).className = this.builder.opts.row, o.appendChild(a), (r = this.builder.cellSelected()) ? u = r.parentNode : (u = document.querySelector(".row-active")) || (c = !0), c) {
var p = document.querySelectorAll(".is-builder"),
h = p[p.length - 1],
f = s.elementChildren(h);
u = f[f.length - 1]
}
u.parentNode.insertBefore(o, u), s.moveAfter(o, u), this.builder.applyBehavior(), a.click(), o.className = o.className.replace("row-outline", ""), (l = document.querySelector(".is-column-tool")).className = l.className.replace("active", "")
} else {
var g = document.createElement("div");
g.innerHTML = e;
var m, y = g.querySelectorAll("[data-html]");
if (Array.prototype.forEach.call(y, (function (t) {
e = (e = decodeURIComponent(t.getAttribute("data-html"))).replace(/{id}/g, n.makeId());
for (var i = 1; i <= 20; i++) e = e.replace("[%HTML" + i + "%]", void 0 === t.getAttribute("data-html-" + i) ? "" : decodeURIComponent(t.getAttribute("data-html-" + i)));
t.innerHTML = e
})), (r = this.builder.activeCol) ? m = r.parentNode : (m = document.querySelector(".row-active")) || (c = !0), c) {
var b = document.querySelectorAll(".is-builder"),
x = b[b.length - 1],
w = s.elementChildren(x);
m = w[w.length - 1]
}
var S = document.createRange();
m.parentNode.insertBefore(S.createContextualFragment(g.innerHTML), m.nextSibling), o = g.childNodes[0];
var C = m.getBoundingClientRect().top + m.offsetHeight + window.pageYOffset - 120;
window.scroll({
top: C,
behavior: "smooth"
}), o = m.nextElementSibling, this.builder.applyBehavior(), (a = o.childNodes[0]).click(), o.className = o.className.replace("row-outline", ""), (l = document.querySelector(".is-column-tool")).className = l.className.replace("active", "")
}
this.builder.opts.onChange()
} else i ? this.addContent(e, d, "data-noedit") : this.addContent(e, d)
}
}, {
key: "clearActiveCell",
value: function () {
for (var e = new v, t = document.getElementsByClassName("cell-active"); t.length;) t[0].classList.remove("cell-active");
for (t = document.getElementsByClassName("row-outline"); t.length;) t[0].classList.remove("row-outline");
for (t = document.getElementsByClassName("row-active"); t.length;) t[0].classList.remove("row-active");
for (t = document.getElementsByClassName("builder-active"); t.length;) t[0].classList.remove("builder-active");
var i = this.builderStuff();
if (i) {
var n = i.querySelector(".is-column-tool");
e.removeClass(n, "active"), i.querySelector(".is-element-tool").style.display = ""
}
this.builder.activeCol = null
}
}, {
key: "clearAfterUndoRedo",
value: function () {
var e = new v,
t = this.builderStuff(),
i = t.querySelectorAll(".is-tool");
Array.prototype.forEach.call(i, (function (e) {
e.style.display = ""
})), this.builder.moveable.updateRect(), document.querySelector(".moveable-control-box").style.display = "none", this.builder.activeSpacer = null, this.builder.activeCodeBlock = null, this.builder.activeLink = null, this.builder.activeIframe = null, this.builder.activeTd = null, this.builder.activeTable = null, this.builder.activeModule = null;
var n = document.querySelectorAll(".icon-active");
Array.prototype.forEach.call(n, (function (t) {
e.removeClass(t, "icon-active")
})), this.builder.activeIcon = null;
var o = t.querySelector(".is-rte-tool").querySelectorAll("button");
Array.prototype.forEach.call(o, (function (t) {
e.removeClass(t, "on")
}));
var r = t.querySelectorAll(".is-pop");
Array.prototype.forEach.call(r, (function (e) {
e.style.display = ""
}))
}
}, {
key: "hideControls",
value: function () {
var e = this.builderStuff().querySelectorAll(".is-tool");
Array.prototype.forEach.call(e, (function (e) {
e.style.display = ""
})), this.builder.moveable.updateRect(), document.querySelector(".moveable-control-box").style.display = "none"
}
}, {
key: "clearControls",
value: function () {
var e = new v,
t = this.builderStuff();
if (t) {
var i = t.querySelectorAll(".is-tool");
Array.prototype.forEach.call(i, (function (e) {
e.style.display = ""
})), this.builder.moveable.updateRect(), document.querySelector(".moveable-control-box").style.display = "none", this.builder.activeSpacer = null, this.builder.activeCodeBlock = null, this.builder.activeLink = null, this.builder.activeIframe = null, this.builder.activeTd = null, this.builder.activeTable = null, this.builder.activeModule = null, this.builder.activeImage = null;
var n = document.querySelectorAll(".icon-active");
Array.prototype.forEach.call(n, (function (t) {
e.removeClass(t, "icon-active")
})), this.builder.activeIcon = null;
var o = document.querySelectorAll(".ovl");
Array.prototype.forEach.call(o, (function (e) {
e.style.display = "block"
}));
var r = t.querySelectorAll(".is-side.elementstyles");
Array.prototype.forEach.call(r, (function (t) {
e.removeClass(t, "active")
}));
var a = document.querySelectorAll("[data-saveforundo]");
Array.prototype.forEach.call(a, (function (e) {
e.removeAttribute("data-saveforundo")
})), a = document.querySelectorAll(".elm-inspected"), Array.prototype.forEach.call(a, (function (t) {
e.removeClass(t, "elm-inspected")
})), t.querySelector(".is-rte-tool").style.display = "none", a = document.querySelectorAll(".elm-active"), Array.prototype.forEach.call(a, (function (t) {
e.removeClass(t, "elm-active")
}))
}
}
}, {
key: "makeId",
value: function () {
for (var e = "", t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", i = 0; i < 2; i++) e += t.charAt(Math.floor(Math.random() * t.length));
for (var n = "", o = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", r = 0; r < 5; r++) n += o.charAt(Math.floor(Math.random() * o.length));
return e + n
}
}, {
key: "saveSelection",
value: function () {
if (window.getSelection) {
var e = window.getSelection();
if (e.getRangeAt && e.rangeCount) {
for (var t = [], i = 0, n = e.rangeCount; i < n; ++i) t.push(e.getRangeAt(i));
return this.builder.selection = t, t
}
} else if (document.selection && document.selection.createRange) return this.builder.selection = document.selection.createRange(), document.selection.createRange();
return this.builder.selection = null, null
}
}, {
key: "restoreSelection",
value: function () {
var e = this.builder.selection;
if (e)
if (window.getSelection) {
var t = window.getSelection();
if (document.body.createTextRange) {
var i = document.body.createTextRange();
i.collapse(), i.select()
} else window.getSelection ? window.getSelection().empty ? window.getSelection().empty() : window.getSelection().removeAllRanges && window.getSelection().removeAllRanges() : document.selection && document.selection.empty();
for (var n = 0, o = e.length; n < o; ++n) t.addRange(e[n])
} else document.selection && e.select && e.select()
}
}, {
key: "cleanHTML",
value: function (e, t) {
var i, n = e.replace(/(\n|\r| class=(")?Mso[a-zA-Z]+(")?)/g, " "),
o = new RegExp("\x3c!--(.*?)--\x3e", "g");
n = n.replace(o, ""), i = t ? new RegExp("<(/)*(meta|link|span|\\?xml:|st1:|o:|font)(.*?)>", "gi") : new RegExp("<(/)*(meta|link|\\?xml:|st1:|o:|font)(.*?)>", "gi"), n = n.replace(i, "");
for (var r, a = ["style", "script", "applet", "embed", "noframes", "noscript"], l = 0; l < a.length; l++) i = new RegExp("<" + a[l] + ".*?" + a[l] + "(.*?)>", "gi"), n = n.replace(i, "");
r = t ? ["style", "start"] : ["start"];
for (var s = 0; s < r.length; s++) {
var c = new RegExp(" " + r[s] + '="(.*?)"', "gi");
n = n.replace(c, "")
}
return n = (n = (n = (n = (n = n.replace(/<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s/>]))[^>]*>/gi, "")).replace(/<(\/?)s>/gi, "<$1strike>")).replace(/ /gi, " ")).replace(/background-color: rgba\(200, 200, 201, 0.11\);/gi, "")).replace(/background-color: rgba\(200, 200, 201, 0.11\)/gi, "")
}
}, {
key: "checkEmpty",
value: function () {
var e = this,
t = new v,
i = document.querySelectorAll(this.builder.opts.container);
Array.prototype.forEach.call(i, (function (i) {
var n = t.elementChildren(i),
o = !0;
if (n.forEach((function (e) {
t.hasClass(e, "row-add-initial") || t.hasClass(e, "dummy-space") || (o = !1)
})), o) {
var r = i.querySelector(".row-add-initial");
r || (i.innerHTML = '