edit: restore placeholders on edit
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 14 Sep 2017 15:41:51 +0000 (17:41 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 18 Sep 2017 18:21:28 +0000 (20:21 +0200)
edit.js
page.php

diff --git a/edit.js b/edit.js
index 164cc1ef9829a2add8472ebe617771bd99a90c70..974def438490f669f7ef073793cd7a913dd53942 100644 (file)
--- a/edit.js
+++ b/edit.js
@@ -84,19 +84,16 @@ if (pagebody) {
        var editlink = document.createElement('a');
        editlink.style.cursor = 'pointer';
        editlink.appendChild(document.createTextNode('Wijzig'));
+       editlink.href = '#edit';
        editlink.onclick = function (e) {
-               var toggled = editlink.style.fontWeight;
-               editlink.style.fontWeight = toggled ? '' : 'bold';
-               pagebody.setAttribute('contenteditable', !toggled);
-               if (toggled) {
-                       for (name in CKEDITOR.instances) {
-                               CKEDITOR.instances[name].destroy()
-                       }
-               }
-               else {
-                       CKEDITOR.inline(pagebody);
-               }
-               document.body.className = toggled ? '' : 'edit';
+               editlink.style.fontWeight = 'bold';
+               editlink.href = '';
+               editlink.onclick = undefined;
+               pagebody.setAttribute('contenteditable', true);
+               pagebody.innerHTML = pagebody.innerHTML
+                       .replace(/<!--BLOCK ([a-z]*)-->[^]*?<!--\/-->/g, '[[$1]]');
+               CKEDITOR.inline(pagebody);
+               document.body.className = 'edit';
                return false;
        };
        if (window.location.hash == '#edit') {
index 6d98863165e670b5d55cc8793fb89b89777ad62a..9e3388ee0757cc27a3d384066c74799d1f805ade 100644 (file)
--- a/page.php
+++ b/page.php
@@ -62,7 +62,7 @@ if ($Page) {
        {
                $rep = [];
                foreach ($blocks as $name => $html) {
-                       $rep["[[$name]]"] = $html;
+                       $rep["[[$name]]"] = "<!--BLOCK $name-->$html<!--/-->";
                }
                return str_replace(array_keys($rep), array_values($rep), ob_get_clean());
        }