'use strict';dotclear.ToolBar.prototype.elements.link.data={};dotclear.ToolBar.prototype.elements.link.fncall={};dotclear.ToolBar.prototype.elements.link.open_url='index.php?process=LinkPopup&popup=1&plugin_id=dcLegacyEditor';dotclear.ToolBar.prototype.elements.link.popup=function(args=''){globalThis.the_toolbar=this;this.elements.link.data={};const url=this.elements.link.open_url+args;window.open(url,'dc_popup','alwaysRaised=yes,dependent=yes,toolbar=yes,height=420,width=520,menubar=no,resizable=yes,scrollbars=yes,status=no',);};dotclear.ToolBar.prototype.elements.link.fn.wiki=function(){this.elements.link.popup.call(this,`&hreflang=${this.elements.link.default_hreflang}`);};dotclear.ToolBar.prototype.elements.link.fncall.wiki=function(){const{data}=this.elements.link;if(!data.href){return;}
let etag=`|${data.href}`;if(data.hreflang){etag+=`|${data.hreflang}`;}
if(data.title){if(!data.hreflang){etag+='|';}
etag+=`|${data.title}`;}
if(data.content){this.encloseSelection(`[${data.content}`,`${etag}]`);}else{this.encloseSelection(`[${this.getCurrentSelection() ? '' : data.href_title || ''}`,`${etag}]`);}};dotclear.ToolBar.prototype.elements.link.fn.xhtml=function(){this.elements.link.popup.call(this,`&hreflang=${this.elements.link.default_hreflang}`);};dotclear.ToolBar.prototype.elements.link.fncall.xhtml=function(){const{data}=this.elements.link;if(!data.href){return;}
let stag=`<a href="${data.href}"`;if(data.hreflang){stag+=` hreflang="${data.hreflang}"`;}
if(data.title){stag+=` title="${data.title}"`;}
stag+='>';const etag='</a>';if(data.content){this.encloseSelection('','',()=>stag+data.content+etag);}else{this.encloseSelection(`${stag}${this.getCurrentSelection() ? '' : data.href_title || ''}`,etag);}};dotclear.ToolBar.prototype.elements.link.fn.wysiwyg=function(){let href;let title;let hreflang;href=title='';hreflang=this.elements.link.default_hreflang;const a=this.getAncestor();if(a.tagName==='a'){href=a.tag.href||'';title=a.tag.title||'';hreflang=a.tag.hreflang||'';}
this.elements.link.popup.call(this,`&href=${href}&hreflang=${hreflang}&title=${title}`);};dotclear.ToolBar.prototype.elements.link.fncall.wysiwyg=function(){const{data}=this.elements.link;let a=this.getAncestor();if(a.tagName==='a'){if(data.href){a.tag.href=data.href;if(data.hreflang){a.tag.setAttribute('hreflang',data.hreflang);}else{a.tag.removeAttribute('hreflang');}
if(data.title){a.tag.setAttribute('title',data.title);}else{a.tag.removeAttribute('title');}}else{this.replaceNodeByContent(a.tag);this.iwin.focus();}
return;}
const n=data.content?document.createTextNode(data.content):this.getSelectedNode();a=this.iwin.document.createElement('a');a.href=data.href;if(data.hreflang)a.setAttribute('hreflang',data.hreflang);if(data.title)a.setAttribute('title',data.title);if(!n.textContent&&n.childElementCount===0&&data.href_title)n.textContent=data.href_title;a.appendChild(n);this.insertNode(a);};dotclear.ToolBar.prototype.getAncestor=function(){const res={};let range;let commonAncestorContainer;if(this.iwin.getSelection){const selection=this.iwin.getSelection();range=selection.getRangeAt(0);commonAncestorContainer=range.commonAncestorContainer;while(commonAncestorContainer.nodeType!==1){commonAncestorContainer=commonAncestorContainer.parentNode;}}else{range=this.iwin.document.selection.createRange();commonAncestorContainer=range.parentElement();}
let ancestorTagName=commonAncestorContainer.tagName.toLowerCase();while(ancestorTagName!=='a'&&ancestorTagName!=='body'){commonAncestorContainer=commonAncestorContainer.parentNode;ancestorTagName=commonAncestorContainer.tagName.toLowerCase();}
res.tag=commonAncestorContainer;res.tagName=ancestorTagName;return res;};dotclear.ToolBar.prototype.elements.img_select={group:'media',type:'button',title:'Image chooser',accesskey:'m',key:'m',shortkey_name:'M',fn:{},fncall:{},open_url:'index.php?process=Media&popup=1&plugin_id=dcLegacyEditor',data:{},popup(){globalThis.the_toolbar=this;this.elements.img_select.data={};window.open(this.elements.img_select.open_url,'dc_popup','alwaysRaised=yes,dependent=yes,toolbar=yes,height=500,width=760,menubar=no,resizable=yes,scrollbars=yes,status=no',);},};dotclear.ToolBar.prototype.elements.img_select.fn.wiki=function(){this.elements.img_select.popup.call(this);};dotclear.ToolBar.prototype.elements.img_select.fncall.wiki=function(){const d=this.elements.img_select.data;if(d.src===undefined){return;}
this.encloseSelection('','',(str)=>{const alt=(str||d.title).replace('&','&amp;').replace('>','&gt;').replace('<','&lt;').replace('"','&quot;');let legend=d.description!==''&&alt.length?d.description.replace('&','&amp;').replace('>','&gt;').replace('<','&lt;').replace('"','&quot;'):false;if(alt===legend)legend=false;let res=`((${d.src}|${alt}`;if(d.alignment==='left'){res+='|L';}else if(d.alignment==='right'){res+='|R';}else if(d.alignment==='center'){res+='|C';}else if(legend){res+='|';}
if(legend){res+='|';res+=`|${legend}`;}
res+='))';if(d.link&&alt.length){const link_title=`||${this.img_link_title}`;return`[${res}|${d.url}${this.img_link_title ? link_title : ''}]`;}
return res;});};dotclear.ToolBar.prototype.elements.img_select.fn.xhtml=function(){this.elements.img_select.popup.call(this);};dotclear.ToolBar.prototype.elements.img_select.fncall.xhtml=function(){const d=this.elements.img_select.data;if(d.src===undefined){return;}
this.encloseSelection('','',(str)=>{const alignments={left:this.style.left,right:this.style.right,center:this.style.center,};const alt=(str||d.title).replace('&','&amp;').replace('>','&gt;').replace('<','&lt;').replace('"','&quot;');let legend=d.description!==''&&alt.length?d.description.replace('&','&amp;').replace('>','&gt;').replace('<','&lt;').replace('"','&quot;'):false;if(alt===legend)legend=false;let img=`<img src="${d.src}" alt="${alt}"`;let figure='<figure';const caption=legend?`<figcaption>${legend}</figcaption>\n`:'';if(d.alignment in alignments){if(legend){figure=`${figure} class="${alignments[d.alignment]}"`;}else{img=`${img} class="${alignments[d.alignment]}"`;}}
img=`${img}>`;figure=`${figure}>`;if(d.link&&alt.length){const ltitle=alt?` title="${this.img_link_title
            .replace('&', '&amp;')
            .replace('>', '&gt;')
            .replace('<', '&lt;')
            .replace('"', '&quot;')}"`:'';img=`<a href="${d.url}"${ltitle}>${img}</a>`;}
return legend?`${figure}\n${img}\n${caption}</figure>`:img;});};dotclear.ToolBar.prototype.elements.img.fn.wysiwyg=function(){const src=this.elements.img.prompt.call(this);if(!src){return;}
const img=this.iwin.document.createElement('img');img.src=src;img.setAttribute('alt',this.getSelectedText());this.insertNode(img);};dotclear.ToolBar.prototype.elements.img_select.fn.wysiwyg=function(){this.elements.img_select.popup.call(this);};dotclear.ToolBar.prototype.elements.img_select.fncall.wysiwyg=function(){const d=this.elements.img_select.data;if(d.src===undefined){return;}
const alignments={left:this.style.left,right:this.style.right,center:this.style.center,};const alt=(this.getSelectedText()?this.getSelectedText():d.title).replace('&','&amp;').replace('>','&gt;').replace('<','&lt;').replace('"','&quot;');let legend=d.description!==''&&alt.length?d.description.replace('&','&amp;').replace('>','&gt;').replace('<','&lt;').replace('"','&quot;'):false;if(alt===legend)legend=false;const fig=legend?this.iwin.document.createElement('figure'):null;const img=this.iwin.document.createElement('img');const block=legend?fig:img;if(d.alignment in alignments){block.classList.add(alignments[d.alignment]);}
img.src=d.src;img.setAttribute('alt',alt);if(legend){const figcaption=this.iwin.document.createElement('figcaption');figcaption.appendChild(this.iwin.document.createTextNode(legend));fig.appendChild(img);fig.appendChild(figcaption);}
if(d.link&&alt.length){const ltitle=alt?this.img_link_title.replace('&','&amp;').replace('>','&gt;').replace('<','&lt;').replace('"','&quot;'):'';const a=this.iwin.document.createElement('a');a.href=d.url;a.setAttribute('title',ltitle);a.appendChild(block);this.insertNode(a);return;}
this.insertNode(block);};dotclear.ToolBar.prototype.elements.mp3_insert={fncall:{},data:{},};dotclear.ToolBar.prototype.elements.mp3_insert.fncall.wiki=function(){const d=this.elements.mp3_insert.data;if(d.player===undefined){return;}
this.encloseSelection('','',()=>`\n///html\n${d.player}///\n`);};dotclear.ToolBar.prototype.elements.mp3_insert.fncall.xhtml=function(){const d=this.elements.mp3_insert.data;if(d.player===undefined){return;}
this.encloseSelection('','',()=>`\n${d.player}\n`);};dotclear.ToolBar.prototype.elements.mp3_insert.fncall.wysiwyg=()=>{return;};dotclear.ToolBar.prototype.elements.flv_insert={fncall:{},data:{},};dotclear.ToolBar.prototype.elements.flv_insert.fncall.wiki=function(){const d=this.elements.flv_insert.data;if(d.player===undefined){return;}
this.encloseSelection('','',()=>`\n///html\n${d.player}///\n`);};dotclear.ToolBar.prototype.elements.flv_insert.fncall.xhtml=function(){const d=this.elements.flv_insert.data;if(d.player===undefined){return;}
this.encloseSelection('','',()=>`\n${d.player}\n`);};dotclear.ToolBar.prototype.elements.flv_insert.fncall.wysiwyg=()=>{return;};dotclear.ToolBar.prototype.elements.post_link={group:'link',type:'button',title:'Link to an entry',key:'e',shortkey_name:'E',fn:{},open_url:'index.php?process=PostsPopup&popup=1&plugin_id=dcLegacyEditor',data:{},popup(){globalThis.the_toolbar=this;this.elements.post_link.data={};window.open(this.elements.post_link.open_url,'dc_popup','alwaysRaised=yes,dependent=yes,toolbar=yes,height=500,width=760,menubar=no,resizable=yes,scrollbars=yes,status=no',);},};dotclear.ToolBar.prototype.elements.post_link.fn.wiki=function(){this.elements.post_link.popup.call(this);};dotclear.ToolBar.prototype.elements.post_link.fn.xhtml=function(){this.elements.post_link.popup.call(this);};dotclear.ToolBar.prototype.elements.post_link.fn.wysiwyg=function(){this.elements.post_link.popup.call(this);};