edit/page: load ckeditor dependency from script include
[minimedit.git] / edit / page.js
index ac2288a07fceb1ef132958ef22e44fad7f57f409..ecf520453fb4ffffb6039895600d1725beb2f469 100644 (file)
@@ -1,11 +1,19 @@
+function editorsetup() {
+
+CKEDITOR.disableAutoInline = true;
+
 CKEDITOR.plugins.add('inlinesave', {
        init: function(editor) {
                editor.addCommand( 'inlinesave', {
                        exec: function (editor) {
                                var pagename = window.location.pathname;
                                var body = editor.getData();
+                               // trim trailing whitespace in non-empty paragraphs
+                               body = body.replace(/((?!<p>).{3})(?:\s|\u200B)+(?=<\/p>)/g, '$1');
                                // empty line is equivalent to a paragraph break
                                body = body.replace(/<br \/>\s*<br \/>/g, '<p>');
+                               // keep names and preceding abbreviations together
+                               body = body.replace(/\b((?:dhr|mw|me?vr|mr?s?)\.)\s+(?=[A-Z])/ig, '$1&nbsp;');
                                // wrap long line after each sentence
                                body = body.replace(/^(\t*).{73,}/mg, function (line, indent) {
                                        var dots = '(?:.{24,72}|.{73,}?)'; // chars before punctuation
@@ -149,11 +157,9 @@ 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) {
@@ -178,3 +184,11 @@ if (pagebody) {
        }
 }
 
+}
+
+document.addEventListener('DOMContentLoaded', function (e) {
+       var editorinc = document.createElement('script');
+       editorinc.addEventListener('load', editorsetup);
+       editorinc.src = ckesrc;
+       document.getElementsByTagName('head')[0].appendChild(editorinc);
+});