Files
liceo-ariosto/media/plg_editors_none/js/joomla-editor-none.min.js
2025-06-17 11:53:18 +02:00

1 line
2.0 KiB
JavaScript

import{JoomlaEditor,JoomlaEditorDecorator}from"editor-api";class EditorNoneDecorator extends JoomlaEditorDecorator{getValue(){return this.instance.getValue()}setValue(t){return this.instance.setValue(t),this}getSelection(){return this.instance.getSelection()}replaceSelection(t){return this.instance.replaceSelection(t),this}disable(t){return this.instance.editor&&(this.instance.editor.disabled=!t,this.instance.editor.readOnly=!t),this}}class JoomlaEditorNone extends HTMLElement{constructor(){super(),this.editor="",this.unregisterEditor=this.unregisterEditor.bind(this),this.registerEditor=this.registerEditor.bind(this),this.childrenChange=this.childrenChange.bind(this),this.getSelection=this.getSelection.bind(this),new MutationObserver((()=>this.childrenChange())).observe(this,{childList:!0}),this.interactionCallback=()=>{this.editor&&JoomlaEditor.setActive(this.editor.id)}}connectedCallback(){this.childrenChange(),this.addEventListener("click",this.interactionCallback)}disconnectedCallback(){this.unregisterEditor(),this.removeEventListener("click",this.interactionCallback)}getValue(){return this.editor.value}setValue(t){this.editor.value=t}getSelection(){return this.editor.selectionStart||0===this.editor.selectionStart?this.editor.value.substring(this.editor.selectionStart,this.editor.selectionEnd):this.editor.value}replaceSelection(t){const e=this.editor;e.selectionStart||0===e.selectionStart?e.value=e.value.substring(0,e.selectionStart)+t+e.value.substring(e.selectionEnd,e.value.length):e.value+=t}registerEditor(){const t=new EditorNoneDecorator(this,"none",this.editor.id);JoomlaEditor.register(t)}unregisterEditor(){this.editor&&JoomlaEditor.unregister(this.editor.id)}childrenChange(){this.firstElementChild&&this.firstElementChild.tagName&&"textarea"===this.firstElementChild.tagName.toLowerCase()&&this.firstElementChild.getAttribute("id")&&(this.editor=this.firstElementChild,this.unregisterEditor(),this.registerEditor())}}customElements.define("joomla-editor-none",JoomlaEditorNone);