$(".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"); triggerEditorResize(); }); autoCollapseSidebar(); window.editor.on("run:open-sm", function(editor2) { $(".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(editor2) { $(".gjs-sm-sectors").parent().parent().css("display", "none"); $(".gjs-trt-traits").parent().parent().css("display", "block"); }); window.editor.on("block:drag:start", function(block) { autoCollapseSidebar(); }); window.editor.on("rteToolbarPosUpdate", function(toolbarPosition) { if (!window.editor || !window.editor.getSelected()) return; let selectedDomComponent = window.editor.getSelected().getEl(); if (!selectedDomComponent) return; setTimeout(function() { let $toolbar = $(".gjs-rte-toolbar").first(); let toolbarInUpperHalf = $toolbar.offset().top < toolbarPosition.elementTop + 0.5 * toolbarPosition.elementHeight; if (toolbarInUpperHalf) { let newTop = toolbarPosition.elementTop - $toolbar.height(); if (newTop > 0) { $toolbar.css("top", newTop + "px"); } } }, 0); }); function autoCollapseSidebar() { if ($(window).width() < 1e3) { $("#gjs").addClass("sidebar-collapsed"); triggerEditorResize(); } } function triggerEditorResize() { window.editor.trigger("change:canvasOffset canvasScroll"); } let backspaceIsPressed = false; $(document).keydown(function(event) { if (event.which === 8) backspaceIsPressed = true; }).keyup(function(event) { if (event.which === 8) backspaceIsPressed = false; }); $(window).on("beforeunload", function(event) { if (backspaceIsPressed) event.preventDefault(); }); function addBlockSearch() { $(".gjs-blocks-cs").prepend($("#block-search")); } window.addEventListener("message", onMessage, false); function onMessage(event) { if (event.data === "page-loaded") { $("#phpb-loading").addClass("loaded"); addBlockSearch(); window.isLoaded = true; $(window).trigger("pagebuilder-page-loaded"); } else if (event.data === "touch-start") { window.touchStart(); } } $(document).on("input", "#block-search input", function() { let term = $(this).val().toLowerCase(); $(".gjs-block-category").each(function() { let atLeastOneMatch = false; $(this).find(".gjs-block").each(function() { if (!$(this).data("original-html")) { $(this).data("original-html", $(this).html()); } let label = $(this).text(); if (label.toLowerCase().includes(term)) { $(this).removeClass("d-none"); atLeastOneMatch = true; let regEx = new RegExp("(" + term + ")", "gi"); let highlightedText = label.replace(regEx, "$1"); $(this).find(".gjs-block-label").html( $(this).data("original-html").replace(label.trim(), highlightedText) ); } else { $(this).addClass("d-none"); } }); $(this).removeClass("d-none"); if (!atLeastOneMatch) { $(this).addClass("d-none"); } }); }); window.customBuilderScripts = {}; window.editor.on("component:create", (component) => { if (component.components().length) { let lastChild = component.components().models[component.components().length - 1]; if (lastChild.attributes.type === "script") { let blockId = component.attributes.attributes["block-id"]; if (blockId === void 0) { blockId = component.attributes.attributes["id"]; } let rootComponent = lastChild; let insideEditablePartOfPage = false; while (rootComponent.parent()) { rootComponent = rootComponent.parent(); if (rootComponent.attributes.attributes["phpb-content-container"]) { insideEditablePartOfPage = true; break; } } if (insideEditablePartOfPage) { window.customBuilderScripts[blockId] = lastChild.toHTML(); lastChild.remove(); } } } }); window.editor.on("component:add", function(component) { if (component.attributes["run-builder-script"] !== void 0) { let originalCustomBuilderScripts = customBuilderScripts; window.customBuilderScripts[component.attributes["block-id"]] = customBuilderScripts[component.attributes["run-builder-script"]]; runScriptsOfComponentAndChildren(component); window.customBuilderScripts = originalCustomBuilderScripts; delete component.attributes["run-builder-script"]; } }); window.editor.on("sorter:drag:end", function(event) { let component = event.modelToDrop; if (component && component.attributes && (component.attributes["block-id"] || component.attributes["id"])) { window.runScriptsOfComponentAndChildren(component); } for (let instanceName in CKEDITOR.instances) { CKEDITOR.instances[instanceName].destroy(true); } }); window.runScriptsOfComponentAndChildren = function(component) { runComponentScript(component); component.components().each(function(child) { runScriptsOfComponentAndChildren(child); }); }; function runComponentScript(component) { let blockId = component.attributes["block-id"]; if (blockId === void 0) { blockId = component.attributes.attributes["id"]; } if (blockId && window.customBuilderScripts[blockId] !== void 0) { let styleIdentifier = component.attributes["style-identifier"]; let $scriptTag = $("").append(window.customBuilderScripts[blockId]); $scriptTag.find("script").prepend("let inPageBuilder = true;"); $scriptTag.find("script").prepend('let blockSelector = ".' + styleIdentifier + '";'); $scriptTag.find("script").prepend('let block = document.getElementsByClassName("' + styleIdentifier + '")[0];'); $scriptTag.find("script").prepend("(function(){"); $scriptTag.find("script").append("})();"); let scriptTag = document.createElement("script"); scriptTag.type = "text/javascript"; scriptTag.innerHTML = $scriptTag.find("script").html(); window.editor.Canvas.getDocument().body.appendChild(scriptTag); } } function afterGrapesJSLoaded() { addThemeBlocks(); let scriptTag = document.createElement("script"); scriptTag.type = "text/javascript"; scriptTag.src = window.injectionScriptUrl; let fullScript = scriptTag.outerHTML + "