"use strict";if(void 0===dotclear)var dotclear={};dotclear.resizeTimer=void 0,dotclear.prevWidth=0,dotclear.jsButton=class{constructor(t,e,s,i){this.title=t||null,this.fn=e||(()=>{}),this.scope=s||null,this.className=i||null,this.toolbarNode=null}draw(){if(!this.scope)return null;const t=document.createElement("button");t.setAttribute("type","button"),this.className&&(t.className=this.className);const e=document.createElement("span");return e.className="sr-only",e.appendChild(document.createTextNode(this.title)),t.appendChild(e),null!=this.icon&&(t.style.backgroundImage='url(" + this.icon + ")'),t.addEventListener("keydown",this.keyDown),t.addEventListener("focus",this.focus),t.addEventListener("blur",this.blur),t.addEventListener("mouseover",this.mouseOver),t.addEventListener("mouseleave",this.mouseLeave),"function"==typeof this.fn&&(t.onclick=()=>{try{this.fn.apply(this.scope,arguments)}catch(t){}return!1}),t}keyDown(t){let e=!1;switch(t.keyCode){case 13:case 32:default:break;case 39:case 40:this.toolbarNode.moveFocus(this,"next"),e=!0;break;case 37:case 38:this.toolbarNode.moveFocus(this,"previous"),e=!0;break;case 36:this.toolbarNode.setFocus(this.toolbarNode.firstItem),e=!0;break;case 35:this.toolbarNode.setFocus(this.toolbarNode.lastItem),e=!0}e&&(t.stopPropagation(),t.preventDefault())}blur(t){t.target.firstChild.classList.add("sr-only"),document.querySelector(".jstElements").classList.remove("focus")}focus(t){this.toolbarNode.hideAllTooltips(),t.target.firstChild.classList.remove("sr-only"),document.querySelector(".jstElements").classList.add("focus")}mouseLeave(t){"BUTTON"===t.target.nodeName&&(t.target.classList.remove("hovered"),setTimeout((()=>{t.target.classList.contains("hovered")||t.target.firstChild.classList.add("sr-only")}),800))}mouseOver(t){"BUTTON"===t.target.nodeName&&(this.toolbarNode.hideAllTooltips(),t.target.firstChild.classList.remove("sr-only"),t.target.classList.add("hovered"))}},dotclear.jsSpace=class{constructor(t){this.id=t||null,this.width=null}draw(){const t=document.createElement("span");return this.id&&(t.id=this.id),t.appendChild(document.createTextNode(String.fromCharCode(160))),t.setAttribute("aria-hidden","true"),t.className="jstSpacer",this.width&&(t.style.marginRight=`${this.width}px`),t}},dotclear.jsCombo=class{constructor(t,e,s,i,o){this.title=t||null,this.options=e||null,this.scope=s||null,this.fn=i||(()=>{}),this.className=o||null}draw(){if(!this.scope||!this.options)return null;const t=document.createElement("select");this.className&&(t.className=this.className),t.title=this.title;for(const e in this.options){const s=document.createElement("option");s.value=e,s.appendChild(document.createTextNode(this.options[e])),t.appendChild(s)}const e=this;return t.onchange=function(){try{e.fn.call(e.scope,this.value)}catch(t){window.alert(t)}return!1},t}},dotclear.jsToolBar=class{constructor(t,e="",s="wiki",i="",o=null){document.createElement&&t&&(void 0===document.selection&&void 0===t.setSelectionRange||(this.textarea=t,this.base_url=e,this.mode=s,this.label=i,this.editor=document.createElement("div"),this.editor.className="jstEditor",this.textarea.parentNode.insertBefore(this.editor,this.textarea),this.editor.appendChild(this.textarea),this.toolbar=document.createElement("div"),this.toolbar.className="jstElements",this.toolbar.setAttribute("role","toolbar"),this.toolbar.setAttribute("aria-label",this.label),this.toolbar.setAttribute("aria-controls","c_content"),this.editor.parentNode.insertBefore(this.toolbar,this.editor),this.context=null,this.toolNodes={},this.elements={strong:{type:"button",title:"Strong emphasis",fn:{wiki(){this.singleTag("__")},markdown(){this.singleTag("**")}}},em:{type:"button",title:"Emphasis",fn:{wiki(){this.singleTag("''")},markdown(){this.singleTag("*")}}},ins:{type:"button",title:"Inserted",fn:{wiki(){this.singleTag("++")},markdown(){this.singleTag("<ins>","</ins>")}}},del:{type:"button",title:"Deleted",fn:{wiki(){this.singleTag("--")},markdown(){this.singleTag("<del>","</del>")}}},quote:{type:"button",title:"Inline quote",fn:{wiki(){this.singleTag("{{","}}")},markdown(){this.singleTag("<q>","</q>")}}},code:{type:"button",title:"Code",fn:{wiki(){this.singleTag("@@")},markdown(){this.singleTag("`")}}},br:{type:"button",title:"Line break",fn:{wiki(){this.encloseSelection("%%%\n","")},markdown(){this.encloseSelection("  \n","")}}},ul:{type:"button",title:"Unordered list",fn:{wiki(){this.encloseSelection("","",(t=>`* ${(t=t.replace(/\r/g,"")).replace(/\n/g,"\n* ")}`))},markdown(){this.encloseSelection("","",(t=>`* ${(t=t.replace(/\r/g,"")).replace(/\n/g,"\n* ")}`))}}},ol:{type:"button",title:"Ordered list",fn:{wiki(){this.encloseSelection("","",(t=>`# ${(t=t.replace(/\r/g,"")).replace(/\n/g,"\n# ")}`))},markdown(){this.encloseSelection("","",(t=>`1. ${(t=t.replace(/\r/g,"")).replace(/\n/g,"\n1. ")}`))}}},pre:{type:"button",title:"Preformatted",fn:{wiki(){this.encloseSelection("","",(t=>` ${(t=t.replace(/\r/g,"")).replace(/\n/g,"\n ")}`))},markdown(){this.encloseSelection("\n","",(t=>`    ${(t=t.replace(/\r/g,"")).replace(/\n/g,"\n    ")}`))}}},bquote:{type:"button",title:"Block quote",fn:{wiki(){this.encloseSelection("","",(t=>`> ${(t=t.replace(/\r/g,"")).replace(/\n/g,"\n> ")}`))},markdown(){this.encloseSelection("\n","",(t=>`> ${(t=t.replace(/\r/g,"")).replace(/\n/g,"\n> ")}`))}}},link:{type:"button",title:"Link",fn:{wiki(){const t=this.elements.link.prompt.call(this);if(t){const e="[";let s=`|${t.href}`;t.hreflang&&(s=`${s}|${t.hreflang}`),s=`${s}]`,this.encloseSelection(e,s)}},markdown(){const t=this.elements.link.prompt.call(this);if(t){const e="[";let s=`](${t.href}`;t.title&&(s=`${s} "${t.title}"`),s=`${s})`,this.encloseSelection(e,s)}}},href_prompt:"Please give page URL:",hreflang_prompt:"Language of this page:",title_prompt:"Title:",default_hreflang:"",default_title:"",prompt(t="",e="",s=""){return e=e||this.elements.link.default_hreflang,s=s||this.elements.link.default_title,!!(t=window.prompt(this.elements.link.href_prompt,t))&&("markdown"===this.mode?s=window.prompt(this.elements.link.title_prompt,s):e=window.prompt(this.elements.link.hreflang_prompt,e),{href:this.stripBaseURL(t),hreflang:e,title:s})}}},o&&dotclear.mergeDeep(this.elements,o),window.addEventListener("resize",(()=>{void 0!==dotclear.resizeTimer&&clearTimeout(dotclear.resizeTimer),dotclear.resizeTimer=setTimeout((()=>{document.documentElement.clientWidth!==dotclear.prevWidth&&(this.updateTooltipsPos(),dotclear.prevWidth=document.documentElement.clientWidth)}),250)}))))}getMode(){return this.mode}setMode(t){this.mode=t||"wiki"}switchMode(t="wiki"){this.draw(t)}button(t){const e=this.elements[t];if("function"!=typeof e.fn[this.mode])return null;const s=new dotclear.jsButton(e.title,e.fn[this.mode],this,`jstb_${t}`);return null!=e.icon&&(s.icon=e.icon),s}space(t){const e=new dotclear.jsSpace(t);return void 0!==this.elements[t].width&&(e.width=this.elements[t].width),e}combo(t){const e=this.elements[t],s=e[this.mode].list.length;if("function"!=typeof e[this.mode].fn||0==s)return null;const i={};for(const t of e[this.mode].list)i[t]=e.options[t];return new dotclear.jsCombo(e.title,i,this,e[this.mode].fn)}draw(t){for(this.setMode(t);this.toolbar.hasChildNodes();)this.toolbar.removeChild(this.toolbar.firstChild);this.toolNodes={};for(const t in this.elements){const e=this.elements[t];if(!(null==e.type||""==e.type||null!=e.disabled&&e.disabled||null!=e.context&&null!=e.context&&e.context!=this.context)&&"function"==typeof this[e.type]){const s=this[e.type](t);if(s){const e=s.draw();e&&(this.toolNodes[t]=e,this.toolbar.appendChild(e),e.toolbarNode=this)}}}this.firstItem=document.querySelector(".jstElements button:first-child"),this.lastItem=document.querySelector(".jstElements button:last-child"),this.items=Array.from(document.querySelectorAll(".jstElements button")),this.initTabindex(),this.updateTooltipsPos(),document.body.addEventListener("keydown",this.keyDown.bind(this))}keyDown(t){27==t.keyCode&&(this.hideAllTooltips(),t.stopPropagation(),t.preventDefault())}singleTag(t=null,e=t){t&&e&&this.encloseSelection(t,e)}encloseSelection(t="",e="",s=null){let i,o,n,l,r,a;this.textarea.focus(),void 0!==document.selection?n=document.selection.createRange().text:void 0!==this.textarea.setSelectionRange&&(i=this.textarea.selectionStart,o=this.textarea.selectionEnd,l=this.textarea.scrollTop,n=this.textarea.value.substring(i,o)),n.match(/ $/)&&(n=n.substring(0,n.length-1),e+=" "),a="function"==typeof s?n?s.call(this,n):s(""):n||"",r=t+a+e,void 0!==document.selection?(document.selection.createRange().text=r,this.textarea.caretPos-=e.length):void 0!==this.textarea.setSelectionRange&&(this.textarea.value=this.textarea.value.substring(0,i)+r+this.textarea.value.substring(o),n?this.textarea.setSelectionRange(i+r.length,i+r.length):this.textarea.setSelectionRange(i+t.length,i+t.length),this.textarea.scrollTop=l)}stripBaseURL(t){return""!=this.base_url&&0==t.indexOf(this.base_url)?t.substring(this.base_url.length):t}initTabindex(){for(let t=1;t<this.items.length;t++)this.items[t].setAttribute("tabindex","-1");this.items[0].setAttribute("tabindex","0")}setFocus(t){for(const t of this.items)t.setAttribute("tabindex","-1");t.setAttribute("tabindex","0"),t.focus()}moveFocus(t,e){let s;s="previous"==e?t===this.firstItem?this.lastItem:this.items[this.items.indexOf(t)-1]:t===this.lastItem?this.firstItem:this.items[this.items.indexOf(t)+1],this.setFocus(s)}updateTooltipsPos(){Array.from(document.querySelectorAll(".jstElements button span")).forEach((t=>{const e=t.parentNode.getBoundingClientRect().left;t.style.left="0px",t.classList.add("hidden"),t.classList.remove("sr-only");const s=t.clientWidth;if(t.classList.add("sr-only"),t.classList.remove("hidden"),s+e>document.documentElement.clientWidth-15){const i=Math.trunc(-1*(s+e-document.documentElement.clientWidth+15));t.style.left=`${i}px`}}))}hideAllTooltips(){Array.from(document.querySelectorAll(".jstElements button span")).forEach((t=>{t.classList.add("sr-only")}))}};
