(function () { 'use strict'; const instances=new Map(); function get(id){ const editor=instances.get(id); if(editor&&document.getElementById(id)!==editor.targetElm){editor.remove();return null;} return editor||null; } function mount(textarea,options){ const old=get(textarea.id);if(old)return old; if(!textarea.id)return null; let native; try{if(!window.Jodit)throw Error('Editor unavailable');native=Jodit.make(textarea,{ language:window.FI_EDITOR_LANGUAGE||'en',height:180,minHeight:120, toolbarButtonSize:'small',toolbarAdaptive:false,toolbarSticky:false, buttons:['bold','italic','underline','|','ul','ol','|','paragraph','fontsize','|','link','image','table','|','undo','redo','source','fullsize'], statusbar:false,showCharsCounter:false,showWordsCounter:false,showXPathInStatusbar:false, askBeforePasteHTML:false,askBeforePasteFromWord:false, defaultActionOnPaste:'insert_as_html',spellcheck:true });}catch(error){ // Keep raw HTML editable and available to legacy save/mail handlers if loading fails. native={get value(){return textarea.value;},set value(value){textarea.value=value;},events:{on(){}},focus(){textarea.focus();},destruct(){}}; } const handlers=new Map(); const editor={id:textarea.id,targetElm:textarea, getContent(opts){if(opts&&opts.format==='text'){const node=document.createElement('div');node.innerHTML=native.value;return node.textContent;}return native.value;}, setContent(html){native.value=String(html??'');editor.save();}, save(){textarea.value=native.value;return textarea.value;}, focus(){native.focus();}, on(name,callback){name.split(/\s+/).forEach(event=>{if(event==='init'){handlers.set(event,callback);}else native.events.on(event,callback);});}, remove(){editor.save();instances.delete(textarea.id);native.destruct();if(api.activeEditor===editor)api.activeEditor=null;} }; instances.set(textarea.id,editor); native.events.on('change',()=>editor.save()); native.events.on('focus',()=>{api.activeEditor=editor;}); if(typeof options.setup==='function')options.setup(editor); Promise.resolve().then(()=>{const callback=handlers.get('init');if(callback)callback({target:editor});}); return editor; } const api={activeEditor:null,get, init(options){options=options||{};const editors=[];document.querySelectorAll(options.selector||'textarea.WYSIWYG').forEach(el=>{const editor=mount(el,options);if(editor)editors.push(editor);});return Promise.resolve(editors);}, remove(selector){if(typeof selector==='string')document.querySelectorAll(selector).forEach(el=>{const editor=get(el.id);if(editor)editor.remove();});else if(selector&&selector.remove)selector.remove();else Array.from(instances.values()).forEach(editor=>editor.remove());}, triggerSave(){instances.forEach(editor=>editor.save());} }; window.tinymce=window.tinyMCE=api; document.addEventListener('submit',()=>api.triggerSave(),true); // Existing site initialization mounts editors when their tabs and accordions open. new MutationObserver(()=>{Array.from(instances.values()).forEach(editor=>{if(!editor.targetElm.isConnected)editor.remove();});}).observe(document.documentElement,{childList:true,subtree:true}); })();