X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/5738327522a74f1a5458d9b568fdf28092aaba23..a7131e1013d54f0a6f0e80d05d04ff724d68466e:/edit/page.js diff --git a/edit/page.js b/edit/page.js index 522d63e..b21a038 100644 --- a/edit/page.js +++ b/edit/page.js @@ -1,11 +1,25 @@ +var pagebody; + +function editorcontents() { + return document.getElementsByClassName('static')[0]; +} + +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 @@ -109,16 +123,20 @@ CKEDITOR.on('instanceCreated', function (event) { config.image2_alignClasses = ['left', 'center', 'right']; config.image2_disableResizer = true; config.stylesSet = [ - { name: 'Klein', element: 'small' }, - { name: 'Zijkant', element: 'span', attributes: { 'class': 'right' } }, - { name: 'Attributie', element: 'em', attributes: { 'class': 'right' } }, - { name: 'Quote', element: 'q' }, - { name: 'Gemarkeerd', element: 'span', styles: { 'background-color': 'Yellow' } }, - - { name: 'Kadertekst', element: 'aside' }, - { name: 'Uitgelijnd', element: 'div', attributes: { 'class': 'right' } }, + { name: 'Gerelateerd', element: 'aside' }, + { name: 'Voetnoot', element: 'div', attributes: { 'class': 'right' } }, { name: 'Kolom', element: 'div', attributes: { 'class': 'col' } }, + { name: 'Navigatie', element: 'p', attributes: { 'class': 'nav' } }, { name: 'Waarschuwing', element: 'div', attributes: { 'class': 'warn' } }, + + { name: 'Klein', element: 'small' }, + { name: 'Aanhaling', element: 'q' }, + { name: 'Doorstreept', element: 's' }, + { name: 'Gemarkeerd', element: 'mark' }, + { name: 'Rechts', element: 'span', attributes: { 'class': 'right' } }, + { name: 'Attributie', element: 'em', attributes: { 'class': 'right' } }, + { name: 'Ingelogd', element: 'span', attributes: { 'class': 'login' } }, + { name: 'Uitgelogd', element: 'span', attributes: { 'class': 'logout' } }, ]; config.pasteFilter = pastefilter; config.contentsCss = document.styleSheets[0].href; @@ -149,20 +167,24 @@ 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) { editlink.style.fontWeight = 'bold'; editlink.href = ''; editlink.onclick = undefined; + document.body.replaceChild(pagebody, editorcontents()); 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; @@ -172,3 +194,12 @@ if (pagebody) { } } +} + +document.addEventListener('DOMContentLoaded', function (e) { + pagebody = editorcontents().cloneNode(true); + var editorinc = document.createElement('script'); + editorinc.addEventListener('load', editorsetup); + editorinc.src = ckesrc; + document.getElementsByTagName('head')[0].appendChild(editorinc); +});