wysiwyg.js
1 lines
| 1 | (()=>{"use strict";const{InputData:t}=JetFormBuilderAbstract,{getParsedName:e}=JetFormBuilderFunctions;function i(t){var e;const i=t.closest(".jet-form-builder-repeater");if(!i)return;const o=i.querySelector(".jet-form-builder-repeater__initial");if(!o)return;const n=null!==(e=o.content)&&void 0!==e?e:o;for(const t of n.querySelectorAll('link[rel="stylesheet"]')){if(t.id&&document.getElementById(t.id))continue;const e=t.getAttribute("href");e&&[...document.querySelectorAll('link[rel="stylesheet"]')].some(t=>t.getAttribute("href")===e)||document.head.appendChild(t.cloneNode(!0))}}function o(){t.call(this),this.isSupported=function(t){return t.classList.contains("wysiwyg-field")},this.setNode=function(o){t.prototype.setNode.call(this,o),this.inputType="wysiwyg",this.getSubmit().submitter.promise(t=>{window.tinyMCE.triggerSave(),t()}),this.textArea=o.querySelector(".wp-editor-area");const n=JSON.parse(o.dataset.editor);this.rawName=n.textarea_name,this.name=e(this.rawName);const r=()=>window.tinymce.get(this.textArea.id);r()?.remove?.(),i(o),window.wp.editor.initialize(this.textArea.id,n),this.editor=r(),this.getEditor=r,document.addEventListener("jet-form-builder/conditional-block/block-toggle-hidden-dom",t=>{if(t.detail.block.contains(o)){const e=t.detail.block;e.contains(o)&&(e.__initialized?t.detail.result&&(r()?.remove?.(),i(o),window.wp.editor.initialize(this.textArea.id,n),this.editor=r(),this.getEditor=r):(r()?.remove?.(),i(o),window.wp.editor.initialize(this.textArea.id,n),this.editor=r(),this.getEditor=r,e.__initialized=!0))}})},this.addListeners=function(){this.reporting.makeInvalid=()=>{},this.reporting.makeValid=()=>{};const t=()=>{this.value.current=this.editor.getContent()};this.getEditor()?.on?.("input",t)?.on?.("change",t)},this.setValue=function(){this.getEditor()?.on?.("init",()=>{this.transferStylesToIframe(),this.callable.lock.current=!1,this.silenceSet(this.editor.getContent())})},this.initNotifyValue=()=>{},this.focusRaw=function(){this.getEditor()?.getBody()?.focus({preventScroll:!0})},this.hasAutoScroll=function(){return!1},this.transferStylesToIframe=function(){const t=this.getWrapperNode(),e=this.editor.iframeElement.contentDocument.body,i=t.style.cssText.split(";").filter(Boolean);for(const t of i){const[i,o]=t.split(":");switch(i.trim()){case"--jfb-wysiwyg-container-bg":e.style.backgroundColor=o;break;case"--jfb-wysiwyg-container-text":e.style.color=o}}}}o.prototype=Object.create(t.prototype);const n=o,{BaseSignal:r}=JetFormBuilderAbstract;function s(){r.call(this),this.lock.current=!0,this.isSupported=function(t,e){return t.classList.contains("wysiwyg-field")},this.runSignal=function(){var t;this.input.value.current!==this.input.editor.getContent()&&this.input.editor.setContent(null!==(t=this.input.value.current)&&void 0!==t?t:"")}}s.prototype=Object.create(r.prototype);const l=s,{addFilter:c}=JetPlugins.hooks;c("jet.fb.inputs","jet-form-builder/wysiwyg-field",function(t){return[n,...t]}),c("jet.fb.signals","jet-form-builder/wysiwyg-field",function(t){return[l,...t]})})(); |