page: omit numeric placeholders during edit
[minimedit.git] / edit.js
diff --git a/edit.js b/edit.js
index dee103855135dca7f4ddd251a02cb1f9355eb820..c32bd5b81ef3540a775a9dad36ea6b2485f56588 100644 (file)
--- a/edit.js
+++ b/edit.js
@@ -2,10 +2,10 @@ CKEDITOR.plugins.add('inlinesave', {
        init: function(editor) {
                editor.addCommand( 'inlinesave', {
                        exec: function (editor) {
-                               var pagename = window.location.pathname.replace(/\.php$/, '').replace(/\/$/, '/index');
+                               var pagename = window.location.pathname.replace(/\/$/, '/index');
                                var data = 'body='+encodeURIComponent(editor.getData());
                                ajaxpost = new XMLHttpRequest();
-                               ajaxpost.open('POST', '/edit.php'+pagename, true);
+                               ajaxpost.open('POST', '/edit'+pagename, true);
                                ajaxpost.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                                ajaxpost.onreadystatechange = function () {
                                        if (ajaxpost.readyState != 4)
@@ -42,11 +42,11 @@ CKEDITOR.on('instanceCreated', function (event) {
        editor.on('configLoaded', function () {
                var config = editor.config;
                config.language = 'nl';
-               config.extraPlugins = 'sourcedialog,inlinesave';
+               config.extraPlugins = 'sourcedialog,inlinesave,placeholder';
                config.format_tags = 'h2;h3;h4;p';
                config.allowedContent = true;
                config.entities = false; // keep unicode
-               config.filebrowserImageUploadUrl = '/edit.php?type=img';
+               config.filebrowserImageUploadUrl = '/edit?type=img';
                config.forcePasteAsPlainText = true;
                config.contentsCss = '/excelsior.css';
                config.toolbar = [
@@ -54,8 +54,12 @@ CKEDITOR.on('instanceCreated', function (event) {
                        ['Format'],
                        ['BulletedList', 'NumberedList', '-', 'Blockquote'],
                        ['Bold', 'Italic', 'Underline', 'Strike', 'RemoveFormat', '-', 'Anchor', 'Link'],
-                       ['HorizontalRule', 'Table', 'Image'],
+                       ['HorizontalRule', 'Table', 'Image', 'CreatePlaceholder'],
                ];
+               config.toolbarCanCollapse = true;
+               config.floatSpacePreferRight = true;
+               config.floatSpaceDockedOffsetY = 0;
+               config.startupFocus = true;
 
                config.disableObjectResizing = true;
                document.execCommand('enableObjectResizing', false, false); // workaround in inline mode; ff bug?
@@ -65,15 +69,36 @@ CKEDITOR.on('instanceCreated', function (event) {
        CKEDITOR.on('instanceReady', function (event) {
                var editor = event.editor;
                var writer = editor.dataProcessor.writer;
-               writer.selfClosingEnd = '>';
+               writer.selfClosingEnd = ' />';
                writer.setRules( 'p', {
                        breakAfterOpen: true,
                        breakBeforeClose: true,
                });
        });
 
-var pagebody = document.getElementsByClassName('article')[0];
-pagebody.setAttribute('contenteditable', 'true');
+       CKEDITOR.disableAutoInline = true;
 
-document.body.className = 'edit';
+// add edit link to menu
+var pagebody = document.getElementsByClassName('static')[0];
+if (pagebody) {
+       var editlink = document.createElement('a');
+       editlink.style.cursor = 'pointer';
+       editlink.appendChild(document.createTextNode('Wijzig'));
+       editlink.href = '#edit';
+       editlink.onclick = function (e) {
+               editlink.style.fontWeight = 'bold';
+               editlink.href = '';
+               editlink.onclick = undefined;
+               pagebody.setAttribute('contenteditable', true);
+               pagebody.innerHTML = pagebody.innerHTML
+                       .replace(/<!--BLOCK:([^-]*)-->[^]*?<!--\/-->/g, '$1');
+               CKEDITOR.inline(pagebody);
+               document.body.className = 'edit';
+               return false;
+       };
+       if (window.location.hash == '#edit') {
+               editlink.onclick();
+       }
+       document.querySelector('header ul').appendChild(editlink);
+}