Files
plugi/plugi-core/dist/PageBuilderBody.umd.cjs
T

2 lines
24 KiB
JavaScript

!function(t){"function"==typeof define&&define.amd?define(t):t()}(function(){"use strict";function t(){$(window).width()<1e3&&($("#gjs").addClass("sidebar-collapsed"),e())}function e(){window.editor.trigger("change:canvasOffset canvasScroll")}$(".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"),e()}),t(),window.editor.on("run:open-sm",function(){$(".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(){$(".gjs-sm-sectors").parent().parent().css("display","none"),$(".gjs-trt-traits").parent().parent().css("display","block")}),window.editor.on("block:drag:start",function(){t()}),window.editor.on("rteToolbarPosUpdate",function(t){if(!window.editor||!window.editor.getSelected())return;window.editor.getSelected().getEl()&&setTimeout(function(){let e=$(".gjs-rte-toolbar").first();if(e.offset().top<t.elementTop+.5*t.elementHeight){let n=t.elementTop-e.height();n>0&&e.css("top",n+"px")}},0)});let n=!1;function i(){!function(){for(let t in window.themeBlocks){let e=window.themeBlocks[t],n=$("<container>").append(e.content);n.find("[phpb-blocks-container]").each(function(){""!==$(this).html()&&""===$(this).html().trim()&&$(this).html("")}),window.themeBlocks[t].content=n.html(),e.content=n.html(),editor.BlockManager.add(t,e)}}();let t=document.createElement("script");t.type="text/javascript",t.src=window.injectionScriptUrl;let e=t.outerHTML+"<script>"+o.toString()+o.name+"()<\/script>";window.initialComponents=window.initialComponents.replace("</body>",e+"</body>"),$.each(window.languages,t=>{null===window.pageBlocks[t]&&(window.pageBlocks[t]={})}),activateLanguage(window.currentLanguage)}function o(){let t=document.querySelectorAll("script");for(let e=0;e<t.length;e++){let n=t[e];if(n.innerHTML.startsWith("var script")){let t=n.innerHTML.split("=")[0],e=parseInt(t.replace("var script",""));if(Number.isInteger(e)){let t="script"+e+"Start";if("function"==typeof window[t])return 0!==e&&window[t](),!1}}}}function a(t){let e=t;if("phpb-block"===t.get("tagName")){let n=t.attributes.attributes.id;void 0!==window.pageBlocks[window.currentLanguage][n]&&void 0!==window.pageBlocks[window.currentLanguage][n].html&&(e=t.replaceWith(window.pageBlocks[window.currentLanguage][n].html),window.pageBlocks[window.currentLanguage][n].html="")}e.get("components").each(t=>a(t))}function s(t){"phpb-content-container"in t.attributes.attributes||(f(t),t.get("components").each(t=>s(t)))}function r(t){let e=!1,n=t.getEl();if(n&&n.style){let t=window.getComputedStyle(n);["background","background-image","background-color"].forEach(n=>{let i=t.getPropertyValue(n);void 0===i||""===i||i.includes("none")||i.includes("rgba(0, 0, 0, 0)")||(e=!0)})}return e}function l(t){return t.attributes.traits.length>0}function c(t){if("phpb-block"===t.attributes.tagName){let e,n=t.parent(),i=cloneComponent(t);"false"===t.attributes.attributes["is-html"]?n.components().each(function(n){if(n.cid===t.cid){let n="wrapper"in t.attributes.attributes?t.attributes.attributes.wrapper:"div";e=t.replaceWith({tagName:n}),e.attributes["is-style-wrapper"]=!0,i.components().each(function(t){e.append(cloneComponent(t))})}}):n.components().each(function(n){if(n.cid===t.cid)if(1===i.components().length){let n=cloneComponent(i.components().models[0]);e=t.replaceWith(n)}else e=t.replaceWith({tagName:"div"}),e.attributes["is-style-wrapper"]=!0,i.components().each(function(t){e.append(cloneComponent(t))})}),t.remove(),b(i,e,!0,!1),function(t){if(void 0===window.blockSettings[t.attributes["block-slug"]])return;t.attributes.settings={};let e=function(t){let e=[],n=t,i=!1;for(;n.parent()&&void 0===n.parent().attributes.attributes["phpb-blocks-container"]&&"true"!==n.parent().attributes["is-html"]&&void 0===n.parent().attributes.attributes["phpb-content-container"];)"false"===n.parent().attributes["is-html"]&&(i=!0),void 0!==n.attributes["block-id"]&&e.push(n.attributes["block-id"]),n=n.parent();let o=t.attributes["block-id"];i?o=n.attributes["block-id"]:e=[];let a=window.pageBlocks[window.currentLanguage][o];e.reverse().forEach(function(t){a=void 0===a||void 0===a.blocks||void 0===a.blocks[t]?{}:a.blocks[t]});let s={};void 0!==a&&void 0!==a.settings&&void 0!==a.settings.attributes&&(s=a.settings.attributes);return s}(t);void 0!==e["style-identifier"]&&t.addClass(e["style-identifier"]);t.attributes["is-updating"]=!0;let n=window.blockSettings[t.attributes["block-slug"]];n.forEach(function(n){let i=t.addTrait(n);void 0!==e[n.name]?i[0].setTargetValue(e[n.name]):void 0!==n["default-value"]&&i[0].setTargetValue(n["default-value"])}),t.attributes["is-updating"]=!1}(e),c(e)}else t.components().each(function(t){c(t)})}function d(t,e){if(0===e.length)return t;let n=null;return t.forEachChild(function(t){if(t.attributes["block-id"]===e[0])return n=d(t,e.slice(1)),!1}),t.forEachChild(function(t){let i=d(t,e);if(null!==i)return n=i,!1}),n}$(document).keydown(function(t){8===t.which&&(n=!0)}).keyup(function(t){8===t.which&&(n=!1)}),$(window).on("beforeunload",function(t){n&&t.preventDefault()}),window.addEventListener("message",function(t){"page-loaded"===t.data?($("#phpb-loading").addClass("loaded"),$(".gjs-blocks-cs").prepend($("#block-search")),window.isLoaded=!0,$(window).trigger("pagebuilder-page-loaded")):"touch-start"===t.data&&window.touchStart()},!1),$(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 n=$(this).text();if(n.toLowerCase().includes(t)){$(this).removeClass("d-none"),e=!0;let i=new RegExp("("+t+")","gi"),o=n.replace(i,"<b>$1</b>");$(this).find(".gjs-block-label").html($(this).data("original-html").replace(n.trim(),o))}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("script"===e.attributes.type){let n=t.attributes.attributes["block-id"];void 0===n&&(n=t.attributes.attributes.id);let i=e,o=!1;for(;i.parent();)if(i=i.parent(),i.attributes.attributes["phpb-content-container"]){o=!0;break}o&&(window.customBuilderScripts[n]=e.toHTML(),e.remove())}}}),window.editor.on("component:add",function(t){if(void 0!==t.attributes["run-builder-script"]){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 n in CKEDITOR.instances)CKEDITOR.instances[n].destroy(!0)}),window.runScriptsOfComponentAndChildren=function(t){!function(t){let e=t.attributes["block-id"];void 0===e&&(e=t.attributes.attributes.id);if(e&&void 0!==window.customBuilderScripts[e]){let n=t.attributes["style-identifier"],i=$("<container>").append(window.customBuilderScripts[e]);i.find("script").prepend("let inPageBuilder = true;"),i.find("script").prepend('let blockSelector = ".'+n+'";'),i.find("script").prepend('let block = document.getElementsByClassName("'+n+'")[0];'),i.find("script").prepend("(function(){"),i.find("script").append("})();");let o=document.createElement("script");o.type="text/javascript",o.innerHTML=i.find("script").html(),window.editor.Canvas.getDocument().body.appendChild(o)}}(t),t.components().each(function(t){runScriptsOfComponentAndChildren(t)})},$("#language-selector select").on("change",function(){let t=$(this).find("option:selected").val();window.switchLanguage(t,function(){activateLanguage(t)})}),window.activateLanguage=function(t){window.currentLanguage=t,window.editor.select(),window.editor.DomComponents.clear(),window.editor.DomComponents.componentsById=[],window.editor.UndoManager.clear(),window.editor.Canvas.getDocument().querySelectorAll("script").forEach(function(t){t.remove()}),window.editor.setComponents(window.initialComponents),s(editor.getWrapper()),window.editor.getWrapper().find("[phpb-content-container]").forEach((t,e)=>{t.set("custom-name",window.translations["page-content"]),t.components(window.contentContainerComponents[e]),a(t),c(t)})},$(window).on("pagebuilder-page-loaded",function(){window.editor.getWrapper().find("[phpb-content-container]").forEach(t=>{g(t),window.runScriptsOfComponentAndChildren(t)}),window.setWaiting(!1),setTimeout(function(){window.changesOffset=window.editor.getModel().get("changesCount"),window.afterInitialRendering=!0},250)}),window.editor.on("component:selected",function(t){l(t)?$(".gjs-pn-buttons .gjs-pn-btn:nth-of-type(2)").click():""===t.get("type")&&r(t)&&($(".gjs-pn-buttons .gjs-pn-btn:nth-of-type(3)").click(),$("#gjs-sm-position").hasClass("gjs-sm-open")&&$("#gjs-sm-position").find(".gjs-sm-title").click(),$("#gjs-sm-background").hasClass("gjs-sm-open")||$("#gjs-sm-background").find(".gjs-sm-title").click()),l(t)||setTimeout(function(){$(".gjs-trt-traits").html('<p class="no-settings">'+window.translations["trait-manager"]["no-settings"]+"</p>")},0),setTimeout(function(){t.attributes.removable||$(".gjs-toolbar .fa-trash-o.gjs-toolbar-item").hide(),t.attributes.copyable||$(".gjs-toolbar .fa-clone.gjs-toolbar-item").hide(),t.attributes.draggable||$(".gjs-toolbar .fa-arrows.gjs-toolbar-item").hide(),t.attributes.removable||t.attributes.copyable||t.attributes.draggable||window.editor.select(t.parent());let e=t.attributes["block-slug"];if(e){let t=window.themeBlocks[e].label.split("</div>");t.length>1&&$(".gjs-toolbar").attr("title","Bloknaam: "+t[1])}},0)}),window.editor.on("component:clone",function(t){if(!u){let e=window.editor.getWrapper().find("."+t.attributes["style-identifier"])[0];void 0!==t.attributes["style-identifier"]&&""!==t.attributes["style-identifier"]&&(t.removeClass(t.attributes["style-identifier"]),delete t.attributes["style-identifier"],w(t)),t.attributes["block-id"]=t.attributes["block-slug"],e&&void 0!==window.customBuilderScripts[e.attributes["block-id"]]&&(t.attributes["run-builder-script"]=e.attributes["block-id"])}}),window.editor.on("block:drag:stop",function(t){if(!t||!t.attributes||!t.attributes.attributes)return;let e=m();t.attributes.attributes["dropped-component-id"]=e;let n=t.parent();c(t),n.components().each(function(n){n.attributes["dropped-component-id"]===e&&(delete n.attributes["dropped-component-id"],t=n)}),g(t),window.runScriptsOfComponentAndChildren(t)}),window.editor.on("component:update",function(t){if(!0!==window.isLoaded||void 0===t.attributes["block-slug"]||t.attributes["is-updating"]||void 0===t.changed.attributes||0===$(".gjs-frame").contents().find("#"+t.ccid).length)return;let e=[],n=t,i=!1;for(;n.parent()&&void 0===n.parent().attributes.attributes["phpb-blocks-container"]&&"true"!==n.parent().attributes["is-html"]&&void 0===n.parent().attributes.attributes["phpb-content-container"];)"false"===n.parent().attributes["is-html"]&&(i=!0),void 0!==n.attributes["block-id"]&&e.push(n.attributes["block-id"]),n=n.parent();i?t=n:e=[],t.attributes["is-updating"]=!0,$(".gjs-frame").contents().find("#"+t.ccid).addClass("gjs-freezed");let o=window.editor.getWrapper().find("#"+t.ccid)[0].parent(),s=window.getComponentDataInStorageFormat(t);$.ajax({type:"POST",url:window.renderBlockUrl,data:{data:JSON.stringify(s),language:window.currentLanguage},success:function(n){let i=$(n).attr("block-id");window.pageBlocks[window.currentLanguage][i]=void 0===s.blocks[i]?{}:s.blocks[i],t.replaceWith(n),a(o),c(o),g(o,!1,!1);let r=d(o,[i]);runScriptsOfComponentAndChildren(r),e.push(i);let l=d(o,e.reverse());window.editor.select(l)},error:function(){$(".gjs-frame").contents().find("#"+t.ccid).removeClass("gjs-freezed"),t.attributes["is-updating"]=!1,window.toastr.error(window.translations["toastr-component-update-failed"])}})});let u=!1;function p(t,e){b(t,e,!1,!0);for(let n=0;n<t.components().length;n++){p(t.components().models[n],e.components().models[n])}}function b(t,e,n,i){let o=t.attributes.attributes;for(let a in o)i&&(e.attributes.attributes[a]=o[a]),n&&(e.attributes[a]=o[a])}function g(t,e=!1,n=!0){if(f(t),void 0!==t.attributes.attributes["phpb-content-container"])t.set({droppable:!0,hoverable:!0});else if(void 0!==t.attributes["block-slug"]){t.find("[phpb-hide-if-not-editable]").forEach(t=>{n||window.afterInitialRendering?t.addClass("editable"):t.removeClass("editable")});let i={selectable:!0,hoverable:!0};e||(i={removable:!0,draggable:!0,copyable:!0,selectable:!0,hoverable:!0,stylable:!0},w(t)),"true"===t.attributes["is-html"]?(e=!1,n=!0):(e=!0,n=!1,t.getEl().setAttribute("data-cursor","default")),t.set(i)}if(void 0===t.attributes.attributes["data-raw-content"]){if(n&&(function(t){let e=t.get("tagName"),n=["h1","h2","h3","h4","h5","h6","h7","p","small","b","strong","i","em","label","button","ol","ul","li","table"],i=["img"],o={};"phpb-blocks-container"in t.attributes.attributes&&(o.hoverable=!0,o.selectable=!0,o.droppable=!0);n.includes(e)||"phpb-editable"in t.attributes.attributes?(o.editable=!0,t.attributes["made-text-editable"]="true"):i.includes(e)&&(o.editable=!0);r(t)&&(o.hoverable=!0,o.selectable=!0,o.stylable=!0);"a"===e&&(o.hoverable=!0,o.selectable=!0,o.stylable=!0,o.removable=!0);$.isEmptyObject(o)||(t.set(o),void 0!==o.stylable&&o.stylable&&w(t))}(t),"true"===t.attributes["made-text-editable"])){t.attributes.attributes["data-raw-content"]="true";let e=t.replaceWith(t.toHTML());return["block-id","block-slug","is-html","style-identifier"].forEach(n=>{e.attributes[n]=t.attributes[n]}),void g(e)}t.get("components").each(t=>g(t,e,n))}else t.set({editable:!0})}function w(t){let e=!1;t.getClasses().forEach(t=>{t.startsWith("ID")&&t.length>=16&&(e=t)}),void 0===t.attributes["style-identifier"]&&(t.attributes["style-identifier"]=e||m()),t.addClass(t.attributes["style-identifier"])}function f(t){t.set({removable:!1,draggable:!1,droppable:!1,badgable:!1,stylable:!1,highlightable:!1,copyable:!1,resizable:!1,editable:!1,layerable:!1,selectable:!1,hoverable:!1})}window.cloneComponent=function(t){u=!0;let e=t.clone();return p(t,e),u=!1,e};let h=0;function m(){return"ID"+(Date.now().toString(36)+Math.random().toString(36).substr(2,5)+h++).toUpperCase()}function k(t){let e=window.pageBlocks[t],n=window.pageBlocks[window.currentLanguage];if(void 0===e)e=n;else{!function(t,e){for(let n in t)if(void 0!==e[n])for(let i in t[n].blocks){let o=t[n].blocks[i],a=e[n].blocks[i];if(!o||!a)continue;let s=o.html.match(/phpb-blocks-container(.*)>(.*)</g),r=a.html.match(/phpb-blocks-container(.*)>(.*)</g);if(s&&r)for(let t=0;t<s.length;t++)e[n].blocks[i].html=e[n].blocks[i].html.replace(r[t],s[t])}}(n,e);for(let t in n)void 0===e[t]&&(e[t]=n[t])}for(let i in n){let t=$("<container>"+n[i].html+"</container>"),o=$("<container>"+e[i].html+"</container>");t.find("[phpb-blocks-container]").each(function(t){let e=$(this).html();o.find("[phpb-blocks-container]").eq(t).html(e)}),e[i].html=o.html()}window.pageBlocks[t]=e}function C(t){setTimeout(function(){let e=window.pageData.css?window.pageData.css:window.initialCss;window.pageData={html:[],components:[],css:null,style:null},window.pageBlocks[window.currentLanguage]=[],window.editor.getWrapper().find("[phpb-content-container]").forEach((t,n)=>{let i=v(t);window.pageData.css=function(t,e){if(!t)return e;let n=JSON.stringify(window.pageBlocks),i="\\.ID(.*?){(.*?)}",o=t.match(new RegExp(i,"g"));if(!o)return e;return o.forEach(function(t){let i=t.split("{")[0],o=i.replace("."," ").trim();-1===e.indexOf(i)&&n.indexOf(o)>=0&&(e+=t)}),e}(e,i.css),window.pageData.style=i.style,window.pageData.html[n]=i.html,window.pageData.components[n]=i.components,window.pageBlocks[window.currentLanguage]={...window.pageBlocks[window.currentLanguage],...i.blocks},window.contentContainerComponents[n]=i.components}),t&&t()},200)}function y(){B(),C(function(){$.each(window.languages,t=>{t!==window.currentLanguage&&k(t)});let t=window.pageData;t.style=function(t){let e=JSON.stringify(window.pageBlocks),n=[];return t.forEach(t=>{if(t.attributes.selectors.models.length){let i=t.attributes.selectors.models[0].id;e.includes(i)&&n.push(t)}}),n}(t.style),t.blocks=window.pageBlocks,$.ajax({type:"POST",url:$("#save-page").data("url"),data:{data:JSON.stringify(t)},success:function(){B(),window.toastr.success(window.translations["toastr-changes-saved"]),setTimeout(function(){window.changesOffset=window.editor.getModel().get("changesCount")},250)},error:function(t){B(),console.log(t);let e=t.statusText+" "+t.status;e=t.responseJSON.message?e+': "'+t.responseJSON.message+'"':e,window.toastr.error(e),window.toastr.error(window.translations["toastr-saving-failed"])}})})}function v(t){let e=window.editor.DomComponents.componentsById;window.editor.DomComponents.componentsById=[];let n=j(t=window.cloneComponent(t)).blocks,i=window.html_beautify(function(t){let e="";t.get("components").forEach(t=>e+=t.toHTML());let n=$("<container>"+e+"</container>");return n.find("phpb-block").each(function(){$(this).replaceWith('[block slug="'+$(this).attr("slug")+'" id="'+$(this).attr("id")+'"]')}),n.html()}(t)),o=window.editor.getCss(),a=window.editor.getStyle(),s=JSON.parse(JSON.stringify(t.get("components")));return window.editor.DomComponents.componentsById=e,{html:i,css:o,components:s,blocks:n,style:a}}function S(t){let e=$("<container>"+t.toHTML()+"</container>");return e.find("phpb-block").each(function(){$(this).replaceWith('[block slug="'+$(this).attr("slug")+'" id="'+$(this).attr("id")+'"]')}),e.html()}function j(t,e=!1,n=!1){let i={current_block:{settings:{},blocks:{},html:"",is_html:!1},blocks:{}},o=e,a=n;if(void 0!==t.attributes["block-id"]&&("false"===t.attributes["is-html"]?(o=!0,a=!1):e&&(o=!1,a=!0)),t.get("components").forEach(function(t){let e=j(t,o,a);for(let n in e.current_block.blocks)i.current_block.blocks[n]=e.current_block.blocks[n];for(let n in e.blocks)i.blocks[n]=e.blocks[n]}),!t.parent())return i;if(void 0===t.attributes["block-id"])return i;if("true"===t.attributes["is-html"])if(e)i.current_block.blocks[t.attributes["block-id"]]={settings:{},blocks:{},html:window.html_beautify(S(t)),is_html:!0};else{void 0!==t.attributes["style-identifier"]&&(i.current_block.settings.attributes={"style-identifier":t.attributes["style-identifier"]});let e=t.attributes["block-id"];t.attributes["block-id"].startsWith("ID")||(e=O()),t.replaceWith({tagName:"phpb-block",attributes:{slug:t.attributes["block-slug"],id:e}}),i.blocks[e]={settings:i.current_block.settings,blocks:{},html:window.html_beautify(S(t)),is_html:!0},i.current_block={settings:{},blocks:{},html:"",is_html:!1}}else{let n={};t.get("traits").each(function(t){n[t.get("name")]=t.getTargetValue()}),i.current_block.settings.attributes=n,void 0!==t.attributes["style-identifier"]&&(i.current_block.settings.attributes["style-identifier"]=t.attributes["style-identifier"]);let o=t.attributes["block-id"];if(t.attributes["block-id"].startsWith("ID")||(o=O()),t.replaceWith({tagName:"phpb-block",attributes:{slug:t.attributes["block-slug"],id:o}}),e){let e={settings:{},blocks:{},html:"",is_html:!1};e.blocks[t.attributes["block-id"]]=i.current_block,i.current_block=e}else i.blocks[o]=i.current_block,i.current_block={settings:{},blocks:{},html:"",is_html:!1}}return i}!function t(){window.grapesJSLoaded?i():setTimeout(t,100)}(),window.pageData={},window.changesOffset=0,window.onbeforeunload=function(){if(window.editor.getModel().get("changesCount")-window.changesOffset>0)return"Are you sure? There are unsaved changes."},$("#save-page").click(function(){y()}),$(document).bind("keydown",function(t){if(t.ctrlKey&&83===t.which)return window.editor.store(),y(),t.preventDefault(),!1}),window.switchLanguage=function(t,e){window.setWaiting(!0),C(function(){k(t);let n=window.pageData;n.blocks={[t]:window.pageBlocks[t]},$.ajax({type:"POST",url:window.renderLanguageVariantUrl,data:{data:JSON.stringify(n),language:t},success:function(n){n=JSON.parse(n),window.pageBlocks[t]=n.dynamicBlocks?n.dynamicBlocks:{},e(),window.setWaiting(!1)},error:function(t){e(),console.log(t);let n=t.statusText+" "+t.status;n=t.responseJSON.message?n+': "'+t.responseJSON.message+'"':n,window.toastr.error(n),window.toastr.error(window.translations["toastr-switching-language-failed"])}})})},window.getComponentDataInStorageFormat=function(t){let e=window.cloneComponent(t.parent());console.log({container:e,componentParent:t.parent()});const n=t.attributes["block-id"];return console.log(t.attributes["block-id"]),e.components().forEach(t=>{console.log({c:t}),(null==t?void 0:t.attributes["block-id"])!==n&&(null==t||t.remove())}),console.log({containerL:e.get("components").length,componentParentL:t.parent().get("components").length}),v(e)};let E=0;function O(){return"ID"+(Date.now().toString(36)+Math.random().toString(36).substr(2,5)+E++).toUpperCase()}function B(){let t=$("#save-page");t.blur(),t.hasClass("waiting")?(t.attr("disabled",!1),t.removeClass("waiting"),t.find(".spinner-border").addClass("d-none")):(t.attr("disabled",!0),t.addClass("waiting"),t.find(".spinner-border").removeClass("d-none"))}window.setWaiting=function(t){let e=window.editor.DomComponents.getWrapper();t?e.addClass("gjs-waiting"):e.removeClass("gjs-waiting")},window.CKEDITOR.on("instanceReady",function(t){t.editor.on("paste",function(t){let e=t.data.dataValue;e=e.replace(/<(?!\/?(?:a|table|tr|td|th|thead|tbody|tfoot|caption|col|colgroup|p|ul|ol|li|br|strong|em|b|i|u|strike|sub|sup|h1|h2|h3|h4|h5|h6|blockquote|pre|hr)\b)[^>]+>/gm,""),e=e.replace(/<(a|table|tr|td|th|thead|tbody|tfoot|caption|col|colgroup|p|ul|ol|li|br|strong|em|b|i|u|strike|sub|sup|h1|h2|h3|h4|h5|h6|blockquote|pre|hr)\b[^>]*>/gm,function(t,e){if("a"===e){let e=t.match(/href="([^"]*)"/);return e?'<a href="'+e[1]+'">':t}if("|table|tr|td|th|thead|tbody|tfoot|".includes("|"+e+"|")){let n=t.match(/style="([^"]*)"/);return n?"<"+e+' style="'+n[1]+'">':t}return"<"+e+">"}),t.data.dataValue=e})}),window.CKEDITOR.on("dialogDefinition",function(t){let e=t.data.name,n=t.data.definition;if("link"===e){let t=n.getContents("info");n.onLoad=function(){let t=CKEDITOR.dialog.getCurrent();t.getContentElement("info","linkType").getElement().hide(),t.getContentElement("info","protocol").getElement().hide(),t.getContentElement("info","url").getElement().hide()},t.add({type:"select",id:"linktype-selector",label:"Linktype","default":"",items:[[window.translations.page,"page"],["URL","url"]],onChange:function(t){let e=CKEDITOR.dialog.getCurrent();"page"===t.data.value?(e.getContentElement("info","page-selector").getElement().show(),e.getContentElement("info","url-field").getElement().hide()):(e.getContentElement("info","page-selector").getElement().hide(),e.getContentElement("info","url-field").getElement().show(),e.getContentElement("info","url-field").setValue(""))},setup:function(t){void 0===t.type||"url"===t.type&&t.url.url.startsWith("[page id=")?this.setValue("page"):this.setValue(t.type)}}),t.add({type:"select",id:"page-selector",label:window.translations.page,"default":"",items:window.pages,onChange:function(){let t=CKEDITOR.dialog.getCurrent(),e="[page id="+this.getValue()+"]";t.setValueOf("info","url",e),t.setValueOf("info","protocol","")},setup:function(t){this.allowOnChange=!1;let e="";t.url&&(e=t.url.url.substr(9,t.url.url.length-10)),this.setValue(e),this.allowOnChange=!0}}),t.add({type:"text",id:"url-field",label:"URL","default":"",onChange:function(){let t=CKEDITOR.dialog.getCurrent(),e=this.getValue();t.setValueOf("info","url",e)},setup:function(t){this.allowOnChange=!1;let e="";t.url&&(e=t.url.url),this.setValue(e),this.allowOnChange=!0}})}}),window.touchStart=function(){$("#gjs").addClass("sidebar-collapsed")},window.addEventListener("keydown",function(t){if(t.ctrlKey&&"s"===t.key)return t.preventDefault(),!1}),window.parent.postMessage("page-loaded","*"),document.addEventListener("touchstart",()=>{window.parent.postMessage("touch-start","*")})});