$(".gjs-editor").append($("#toggle-sidebar"));
$(".gjs-pn-panels").prepend($("#sidebar-header"));
$(".gjs-pn-panels").append($("#sidebar-bottom-buttons"));
$("#toggle-sidebar").click(function() {
$("#gjs").toggleClass("sidebar-collapsed"), S();
});
y();
window.editor.on("run:open-sm", function(t) {
$(".gjs-trt-traits").parent().parent().css("display", "none"), $(".gjs-sm-sectors").parent().parent().css("display", "block"), $("#gjs-sm-advanced .gjs-sm-properties").append($(".gjs-clm-tags"));
});
window.editor.on("run:open-tm", function(t) {
$(".gjs-sm-sectors").parent().parent().css("display", "none"), $(".gjs-trt-traits").parent().parent().css("display", "block");
});
window.editor.on("block:drag:start", function(t) {
y();
});
window.editor.on("rteToolbarPosUpdate", function(t) {
!window.editor || !window.editor.getSelected() || !window.editor.getSelected().getEl() || setTimeout(function() {
let i = $(".gjs-rte-toolbar").first();
if (i.offset().top < t.elementTop + 0.5 * t.elementHeight) {
let a = t.elementTop - i.height();
a > 0 && i.css("top", a + "px");
}
}, 0);
});
function y() {
$(window).width() < 1e3 && ($("#gjs").addClass("sidebar-collapsed"), S());
}
function S() {
window.editor.trigger("change:canvasOffset canvasScroll");
}
let g = !1;
$(document).keydown(function(t) {
t.which === 8 && (g = !0);
}).keyup(function(t) {
t.which === 8 && (g = !1);
});
$(window).on("beforeunload", function(t) {
g && t.preventDefault();
});
function A() {
$(".gjs-blocks-cs").prepend($("#block-search"));
}
window.addEventListener("message", V, !1);
function V(t) {
t.data === "page-loaded" ? ($("#phpb-loading").addClass("loaded"), A(), window.isLoaded = !0, $(window).trigger("pagebuilder-page-loaded")) : t.data === "touch-start" && window.touchStart();
}
$(document).on("input", "#block-search input", function() {
let t = $(this).val().toLowerCase();
$(".gjs-block-category").each(function() {
let e = !1;
$(this).find(".gjs-block").each(function() {
$(this).data("original-html") || $(this).data("original-html", $(this).html());
let i = $(this).text();
if (i.toLowerCase().includes(t)) {
$(this).removeClass("d-none"), e = !0;
let n = new RegExp("(" + t + ")", "gi"), a = i.replace(n, "$1");
$(this).find(".gjs-block-label").html(
$(this).data("original-html").replace(i.trim(), a)
);
} else
$(this).addClass("d-none");
}), $(this).removeClass("d-none"), e || $(this).addClass("d-none");
});
});
window.customBuilderScripts = {};
window.editor.on("component:create", (t) => {
if (t.components().length) {
let e = t.components().models[t.components().length - 1];
if (e.attributes.type === "script") {
let i = t.attributes.attributes["block-id"];
i === void 0 && (i = t.attributes.attributes.id);
let n = e, a = !1;
for (; n.parent(); )
if (n = n.parent(), n.attributes.attributes["phpb-content-container"]) {
a = !0;
break;
}
a && (window.customBuilderScripts[i] = e.toHTML(), e.remove());
}
}
});
window.editor.on("component:add", function(t) {
if (t.attributes["run-builder-script"] !== void 0) {
let e = customBuilderScripts;
window.customBuilderScripts[t.attributes["block-id"]] = customBuilderScripts[t.attributes["run-builder-script"]], runScriptsOfComponentAndChildren(t), window.customBuilderScripts = e, delete t.attributes["run-builder-script"];
}
});
window.editor.on("sorter:drag:end", function(t) {
let e = t.modelToDrop;
e && e.attributes && (e.attributes["block-id"] || e.attributes.id) && window.runScriptsOfComponentAndChildren(e);
for (let i in CKEDITOR.instances)
CKEDITOR.instances[i].destroy(!0);
});
window.runScriptsOfComponentAndChildren = function(t) {
x(t), t.components().each(function(e) {
runScriptsOfComponentAndChildren(e);
});
};
function x(t) {
let e = t.attributes["block-id"];
if (e === void 0 && (e = t.attributes.attributes.id), e && window.customBuilderScripts[e] !== void 0) {
let i = t.attributes["style-identifier"], n = $("").append(window.customBuilderScripts[e]);
n.find("script").prepend("let inPageBuilder = true;"), n.find("script").prepend('let blockSelector = ".' + i + '";'), n.find("script").prepend('let block = document.getElementsByClassName("' + i + '")[0];'), n.find("script").prepend("(function(){"), n.find("script").append("})();");
let a = document.createElement("script");
a.type = "text/javascript", a.innerHTML = n.find("script").html(), window.editor.Canvas.getDocument().body.appendChild(a);
}
}
function H() {
R();
let t = document.createElement("script");
t.type = "text/javascript", t.src = window.injectionScriptUrl;
let e = t.outerHTML + "