edit: static edit link
[minimedit.git] / edit.js
diff --git a/edit.js b/edit.js
index c32bd5b81ef3540a775a9dad36ea6b2485f56588..21028dc6f4b7d65c8584429e0cc0267c8af5b0b4 100644 (file)
--- a/edit.js
+++ b/edit.js
@@ -3,7 +3,13 @@ CKEDITOR.plugins.add('inlinesave', {
                editor.addCommand( 'inlinesave', {
                        exec: function (editor) {
                                var pagename = window.location.pathname.replace(/\/$/, '/index');
-                               var data = 'body='+encodeURIComponent(editor.getData());
+                               var body = editor.getData().replace(/^(\t*).{73,}/mg, function (line, indent) {
+                                       // wrap long line after each sentence
+                                       var dots = '(?:.{24,72}|.{73,}?)'; // chars before punctuation
+                                       var wrap = new RegExp('('+dots+'[.;:!?]) (?=[A-Z(<])', 'g'); // separate lines
+                                       return line.replace(wrap, '$1\n'+indent+'\t');
+                               });
+                               var data = 'body='+encodeURIComponent(body);
                                ajaxpost = new XMLHttpRequest();
                                ajaxpost.open('POST', '/edit'+pagename, true);
                                ajaxpost.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
@@ -66,25 +72,12 @@ CKEDITOR.on('instanceCreated', function (event) {
        });
 });
 
-       CKEDITOR.on('instanceReady', function (event) {
-               var editor = event.editor;
-               var writer = editor.dataProcessor.writer;
-               writer.selfClosingEnd = ' />';
-               writer.setRules( 'p', {
-                       breakAfterOpen: true,
-                       breakBeforeClose: true,
-               });
-       });
-
        CKEDITOR.disableAutoInline = true;
 
 // 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';
+       var editlink = document.querySelector('a[href="#edit"]');
        editlink.onclick = function (e) {
                editlink.style.fontWeight = 'bold';
                editlink.href = '';
@@ -99,6 +92,5 @@ if (pagebody) {
        if (window.location.hash == '#edit') {
                editlink.onclick();
        }
-       document.querySelector('header ul').appendChild(editlink);
 }