page: retain conditional login elements in editor
[minimedit.git] / edit / page.js
index ecf520453fb4ffffb6039895600d1725beb2f469..ccc1115eaeda6798426c0266cb06c3e2ed727555 100644 (file)
@@ -1,3 +1,9 @@
+var pagebody;
+
+function editorcontents() {
+       return document.getElementsByClassName('static')[0];
+}
+
 function editorsetup() {
 
 CKEDITOR.disableAutoInline = true;
@@ -122,6 +128,8 @@ CKEDITOR.on('instanceCreated', function (event) {
                        { name: 'Attributie', element: 'em', attributes: { 'class': 'right' } },
                        { name: 'Quote', element: 'q' },
                        { name: 'Gemarkeerd', element: 'span', styles: { 'background-color': 'Yellow' } },
+                       { name: 'Ingelogd', element: 'span', attributes: { 'class': 'login' } },
+                       { name: 'Uitgelogd', element: 'span', attributes: { 'class': 'logout' } },
 
                        { name: 'Kadertekst', element: 'aside' },
                        { name: 'Uitgelijnd', element: 'div', attributes: { 'class': 'right' } },
@@ -157,7 +165,6 @@ CKEDITOR.on('instanceCreated', function (event) {
        };
 });
 
-var pagebody = document.getElementsByClassName('static')[0];
 if (pagebody) {
        // add edit link to menu
        var editlink = document.querySelector('a[href="#edit"]');
@@ -166,6 +173,7 @@ if (pagebody) {
                editlink.style.fontWeight = 'bold';
                editlink.href = '';
                editlink.onclick = undefined;
+               document.body.replaceChild(pagebody, editorcontents());
                pagebody.setAttribute('contenteditable', true);
                pagebody.querySelectorAll('[data-dyn]').forEach(function (el) {
                        let blockname = el.getAttribute('data-dyn');
@@ -187,6 +195,7 @@ if (pagebody) {
 }
 
 document.addEventListener('DOMContentLoaded', function (e) {
+       pagebody = editorcontents().cloneNode(true);
        var editorinc = document.createElement('script');
        editorinc.addEventListener('load', editorsetup);
        editorinc.src = ckesrc;