X-Git-Url: http://git.shiar.nl/minimedit.git/blobdiff_plain/81dcf42eb0bd11110ec30ce3840718b259ec5082..772961fd4e9be46ad340cad1e55ee5f28cc5b968:/edit/page.js diff --git a/edit/page.js b/edit/page.js index c9a6f1e..ecf5204 100644 --- a/edit/page.js +++ b/edit/page.js @@ -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.replace(/\/$/, '/index'); + var pagename = window.location.pathname; var body = editor.getData(); + // trim trailing whitespace in non-empty paragraphs + body = body.replace(/((?!

).{3})(?:\s|\u200B)+(?=<\/p>)/g, '$1'); // empty line is equivalent to a paragraph break body = body.replace(/
\s*
/g, '

'); + // keep names and preceding abbreviations together + body = body.replace(/\b((?:dhr|mw|me?vr|mr?s?)\.)\s+(?=[A-Z])/ig, '$1 '); // wrap long line after each sentence body = body.replace(/^(\t*).{73,}/mg, function (line, indent) { var dots = '(?:.{24,72}|.{73,}?)'; // chars before punctuation @@ -39,6 +47,7 @@ CKEDITOR.plugins.add('inlinesave', { ajaxpost.send(data); }, }); + editor.setKeystroke(CKEDITOR.CTRL + 83 /*S*/, 'inlinesave'); editor.ui.addButton( 'Inlinesave', { command: 'inlinesave', label: editor.lang.save.toolbar, @@ -58,6 +67,17 @@ CKEDITOR.on('dialogDefinition', function (event) { infotab.remove('txtCellSpace'); infotab.remove('txtCellPad'); infotab.remove('cmbAlign'); + + // horizontal repositioning of existing elements + var hbox = { + id: 'hboxDimensions', + type: 'hbox', + children: [ infotab.get('txtCols'), infotab.get('txtRows') ], + }; + infotab.add(hbox, 'selHeaders'); + infotab.remove('txtCols'); + infotab.remove('txtRows'); + break; case 'link': // hide unneeded widgets from the Link Info tab @@ -137,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) { @@ -149,8 +167,14 @@ if (pagebody) { editlink.href = ''; editlink.onclick = undefined; pagebody.setAttribute('contenteditable', true); - pagebody.innerHTML = pagebody.innerHTML - .replace(/[^]*?/g, '$1'); + pagebody.querySelectorAll('[data-dyn]').forEach(function (el) { + let blockname = el.getAttribute('data-dyn'); + if (!blockname) { + el.remove(); + return; + } + el.outerHTML = '[[' + blockname + ']]'; + }); CKEDITOR.inline(pagebody, { customConfig: '' }); document.body.className = 'edit'; return false; @@ -160,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); +});