edit/page: copy static contents before dynamic alterations
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 10 Jan 2020 21:16:11 +0000 (22:16 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 19 Dec 2020 02:01:43 +0000 (03:01 +0100)
Revert javascript alterations before starting edits, preventing them being
saved on lijtweg.nl/doc/splitsing and various Excelsior pages.

edit/page.js

index ecf520453fb4ffffb6039895600d1725beb2f469..0566bcf819b0cc628192c6754076cb463eeb4a38 100644 (file)
@@ -1,3 +1,5 @@
+var pagebody;
+
 function editorsetup() {
 
 CKEDITOR.disableAutoInline = true;
@@ -157,7 +159,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 +167,8 @@ if (pagebody) {
                editlink.style.fontWeight = 'bold';
                editlink.href = '';
                editlink.onclick = undefined;
+               var dynpage = document.getElementsByClassName('static')[0];
+               document.body.replaceChild(pagebody, dynpage);
                pagebody.setAttribute('contenteditable', true);
                pagebody.querySelectorAll('[data-dyn]').forEach(function (el) {
                        let blockname = el.getAttribute('data-dyn');
@@ -187,6 +190,7 @@ if (pagebody) {
 }
 
 document.addEventListener('DOMContentLoaded', function (e) {
+       pagebody = document.getElementsByClassName('static')[0].cloneNode(true);
        var editorinc = document.createElement('script');
        editorinc.addEventListener('load', editorsetup);
        editorinc.src = ckesrc;