edit/page: copy static contents before dynamic alterations
[minimedit.git] / edit / page.js
index d1f16bf3c2b705d3323de6fb7963d010d5b0d440..0566bcf819b0cc628192c6754076cb463eeb4a38 100644 (file)
@@ -1,3 +1,9 @@
+var pagebody;
+
+function editorsetup() {
+
+CKEDITOR.disableAutoInline = true;
+
 CKEDITOR.plugins.add('inlinesave', {
        init: function(editor) {
                editor.addCommand( 'inlinesave', {
@@ -153,17 +159,16 @@ CKEDITOR.on('instanceCreated', function (event) {
        };
 });
 
-       CKEDITOR.disableAutoInline = true;
-
-// add edit link to menu
-var pagebody = document.getElementsByClassName('static')[0];
 if (pagebody) {
+       // add edit link to menu
        var editlink = document.querySelector('a[href="#edit"]');
        if (editlink)
        editlink.onclick = function (e) {
                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');
@@ -182,3 +187,12 @@ 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;
+       document.getElementsByTagName('head')[0].appendChild(editorinc);
+});