Current File : /home/pacjaorg/www/km/media/plg_editors_codemirror/js/joomla-editor-codemirror.min.js |
class CodemirrorEditor extends HTMLElement{constructor(){super(),this.instance="",this.host=window.location.origin,this.element=this.querySelector("textarea"),this.refresh=this.refresh.bind(this),this.intersectionObserver=new IntersectionObserver(s=>{s[0].isIntersecting&&this.instance&&this.instance.refresh()},{threshold:0})}static get observedAttributes(){return["options"]}get options(){return JSON.parse(this.getAttribute("options"))}set options(s){this.setAttribute("options",s)}attributeChangedCallback(s,r,t){switch(s){case"options":r&&t!==r&&this.refresh(this.element);break}}async connectedCallback(){const s=this.getAttribute("editor"),r=this.getAttribute("addons");await import(`${this.host}/${s}`),this.options.keyMapUrl&&await import(`${this.host}/${this.options.keyMapUrl}`),await import(`${this.host}/${r}`);const t=this;window.CodeMirror.modeURL=this.getAttribute("mod-path"),window.CodeMirror.defineInitHook(i=>{const o=window.CodeMirror.findModeByName(i.options.mode||"")||window.CodeMirror.findModeByExtension(i.options.mode||"");window.CodeMirror.autoLoadMode(i,typeof o=="object"?o.mode:i.options.mode),o&&o.mime&&(["text/x-php","application/x-httpd-php","application/x-httpd-php-open"].includes(o.mime)?i.setOption("mode","php"):o.mime==="text/html"?i.setOption("mode",o.mode):i.setOption("mode",o.mime));const a=()=>{t.instance.setOption("fullScreen",!t.instance.getOption("fullScreen"));const e=document.getElementById("subhead");e&&(document.getElementById("header").classList.toggle("hidden"),e.classList.toggle("hidden"),t.instance.display.wrapper.style.top=`${e.getBoundingClientRect().height}px`)},c=()=>{if(t.instance.getOption("fullScreen"),t.instance.setOption("fullScreen",!1),!t.instance.getOption("fullScreen")){const e=document.getElementById("subhead");if(e){const n=document.getElementById("header");e.classList.toggle("hidden"),n.classList.toggle("hidden"),t.instance.display.wrapper.style.top=`${e.getBoundingClientRect().height}px`}}},h={"Ctrl-Q":a,[t.getAttribute("fs-combo")]:a,Esc:c};i.addKeyMap(h);const l=()=>{const e=document.createElement("div");return e.className="CodeMirror-markergutter-mark",e};i.on("gutterClick",(e,n,m)=>{if(m!=="CodeMirror-markergutter")return;const d=e.lineInfo(n),p=!!d.gutterMarkers&&!!d.gutterMarkers["CodeMirror-markergutter"];e.setGutterMarker(n,"CodeMirror-markergutter",p?null:l())}),t.parentNode.tagName.toLowerCase()==="fieldset"&&(t.parentNode.style.minWidth=0)}),this.instance=window.CodeMirror.fromTextArea(this.element,this.options),this.instance.disable=i=>this.setOption("readOnly",i?"nocursor":!1),Joomla.editors.instances[this.element.id]=this.instance,this.intersectionObserver.observe(this)}disconnectedCallback(){delete Joomla.editors.instances[this.element.id],this.intersectionObserver.unobserve(this)}refresh(s){this.instance.fromTextArea(s,this.options)}}customElements.define("joomla-editor-codemirror",CodemirrorEditor);