From: Mischa POSLAWSKY Date: Fri, 10 Jan 2020 21:16:11 +0000 (+0100) Subject: edit/page: copy static contents before dynamic alterations X-Git-Tag: v5.0~34 X-Git-Url: http://git.shiar.net/minimedit.git/commitdiff_plain/4bf9341c044f4081ac80317d758435d2d537e006 edit/page: copy static contents before dynamic alterations Revert javascript alterations before starting edits, preventing them being saved on lijtweg.nl/doc/splitsing and various Excelsior pages. --- diff --git a/edit/page.js b/edit/page.js index ecf5204..0566bcf 100644 --- a/edit/page.js +++ b/edit/page.js @@ -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;