1/** 2 * Attach editing button to editable diagrams 3 */ 4document.addEventListener('DOMContentLoaded', () => { 5 // check if the current page is editable by the current user 6 if (!document.querySelector('head link[rel="edit"]')) return; 7 8 document.querySelectorAll('object.diagrams-svg[data-pos]').forEach(embed => { 9 const button = document.createElement('button'); 10 button.className = 'diagrams-btn'; 11 button.innerText = LANG.plugins.diagrams.editButton; 12 button.addEventListener('click', event => { 13 event.preventDefault(); 14 const diagramsEditor = new DiagramsEditor(() => { 15 // replace instead of reload to avoid accidentally re-submitting forms 16 window.location.replace(window.location.href); 17 }); 18 diagramsEditor.editEmbed( 19 JSINFO.id, 20 parseInt(embed.getAttribute('data-pos')), 21 parseInt(embed.getAttribute('data-len')) 22 ); 23 }); 24 25 embed.parentNode.appendChild(button); 26 }); 27}); 28