edit/page: include admin stylesheet in editor ui
[minimedit.git] / edit / page.js
index f927c1fd248c2d746996e791ed51e1676432b8d5..f9bfd629948f46d2bddaee01318fb02cb97147a9 100644 (file)
@@ -28,6 +28,10 @@ CKEDITOR.plugins.add('inlinesave', {
                                });
                                // treat standalone placeholders as block elements
                                body = body.replace(/<p>(\[\[.*\]\])<\/p>/g, '$1');
+                               // strip redundant domain in relative urls
+                               var hostlink = 'https?://' + window.location.hostname.replace(/\W/g, '\\$&');
+                               hostlink = new RegExp('(<a [^>]*href="|<img [^>]*src=")' + hostlink + '(?=/)', 'gi');
+                               body = body.replace(hostlink, '$1');
 
                                var data = 'body='+encodeURIComponent(body);
                                var ajaxpost = new XMLHttpRequest();
@@ -142,7 +146,7 @@ CKEDITOR.on('instanceCreated', function (event) {
                        { name: 'Uitgelogd', element: 'span', attributes: { 'class': 'logout' } },
                ];
                config.pasteFilter = pastefilter;
-               config.contentsCss = document.styleSheets[0].href;
+               config.contentsCss = [...document.styleSheets].map(e => e.href).filter(Boolean);
                config.toolbar = [
                        ['Inlinesave', '-', 'Undo', 'Redo'],
                        ['Styles', 'Bold', 'Italic', 'Link'],
@@ -171,8 +175,12 @@ CKEDITOR.on('instanceCreated', function (event) {
 
 if (pagebody) {
        // add edit link to menu
-       var editlink = document.querySelector('a[href="#edit"]');
-       if (editlink)
+       var editdiv = document.querySelector('header .login > p');
+       if (!editdiv) return;
+       var editlink = editdiv.appendChild(document.createElement('a'));
+       editlink.append('\u270D');
+       editlink.className = 'icon icon-edit';
+       editlink.href = '#edit';
        editlink.onclick = function (e) {
                editlink.style.fontWeight = 'bold';
                editlink.href = '';
@@ -198,6 +206,7 @@ if (pagebody) {
 
 }
 
+var ckesrc = document.currentScript.getAttribute('data-ckesrc');
 document.addEventListener('DOMContentLoaded', function (e) {
        pagebody = editorcontents().cloneNode(true);
        var editorinc = document.createElement('script');