/**
 * HTML Editor for PHPMaker 2024
 * @license Copyright (c) e.World Technology Limited. All rights reserved.
 */
tinymce.DOM.get=function(e){if(e&&this.doc&&typeof e=="string"){let m=e.match(/^(f[\w]+)\$(x[\w]+)\$$/);if(m){let f=this.doc.getElementById(m[1]);e=f?ew.getElement(m[2],f):null}else{e=this.doc.getElementById(e)}}return e};ew.createEditor=function(formid,name,cols,rows,readonly){if(typeof tinymce=="undefined"||name.includes("$rowindex$"))return;let form=document.getElementById(formid),el=ew.getElement(name,form);if(!el)return;let $=jQuery,language=(ew.LANGUAGE_ID||"").replace("-","_"),useDarkMode=ew.isDark(),settings={height:(rows?Math.abs(rows):4)*4+"em",plugins:["advlist","autolink","lists","link","image","charmap","preview","anchor","searchreplace","visualblocks","code","fullscreen","insertdatetime","media","table","help","wordcount"],toolbar:"undo redo | blocks | "+"bold italic backcolor | alignleft aligncenter "+"alignright alignjustify | bullist numlist outdent indent | "+"removeformat | help",skin:useDarkMode?"oxide-dark":"oxide",content_css:useDarkMode?"dark":"default",file_picker_callback:function(cb,value,meta){let dlg=tinymce.activeEditor.windowManager.openUrl({title:"Insert/Edit "+(meta.filetype=="file"?"link":meta.filetype),url:ew.PATH_BASE+"vendor/hkvstore/richfilemanager/index.html",width:Math.max(Math.round(window.parent.screen.width*.8,640)),height:Math.max(Math.round(window.parent.screen.height*.7,420))});window.addEventListener("message",(function(event){let data=event.data;if(data.source=="richfilemanager")cb(data.preview_url);dlg.close()}),{once:true})}};if(language!="en_US")settings.language=language;let args={id:name,enabled:true,form:form,settings:settings};$(document).trigger("create.editor",[args]);if(!args.enabled)return;if(readonly){args.settings.readonly=true;args.settings.menubar=false;args.settings.plugins=[];args.settings.toolbar=false;delete args.settings.toolbar1;delete args.settings.toolbar2}let editor={name:name,active:false,instance:null,create:function(){let longname=formid+"$"+name+"$",ed=this.instance=tinymce.EditorManager.createEditor(longname,args.settings);ed.render(true);ed.on("init",ew.fixLayoutHeight);this.active=true},set:function(){this.instance?.setContent(el.value)},save:function(){this.instance?.save();let args={id:name,form:form,value:ew.removeSpaces(el.value)};$(document).trigger("save.editor",[args]).val(args.value)},focus:function(){this.instance?.focus(false)},destroy:function(){!this.instance||tinymce.remove(this.instance);this.active=false}};$(el).data("editor",editor).addClass("editor")};
