X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/4b21db92773d4b8ea47d24ef95eba462d0094c8d..9be973973162c972e1bbaac46ccdf82049f75e7c:/edit.js diff --git a/edit.js b/edit.js index fcc8d5f..5384f2c 100644 --- a/edit.js +++ b/edit.js @@ -4,13 +4,17 @@ CKEDITOR.plugins.add('inlinesave', { exec: function (editor) { var pagename = window.location.pathname.replace(/\/$/, '/index'); var body = editor.getData(); + // empty line is equivalent to a paragraph break body = body.replace(/
\s*
/g, '

'); + // wrap long line after each sentence body = body.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 + var wrap = new RegExp('('+dots+'[.:!?]) (?=[A-Z(<])', 'g'); // separate lines return line.replace(wrap, '$1\n'+indent+'\t'); }); + // treat standalone placeholders as block elements + body = body.replace(/

(\[\[.*\]\])<\/p>/g, '$1'); + var data = 'body='+encodeURIComponent(body); ajaxpost = new XMLHttpRequest(); ajaxpost.open('POST', '/edit'+pagename, true); @@ -35,13 +39,20 @@ CKEDITOR.plugins.add('inlinesave', { }); CKEDITOR.on('dialogDefinition', function (event) { - if (event.data.name === 'table') { + switch (event.data.name) { + case 'table': // override initial attribute values var infoTab = event.data.definition.getContents('info'); infoTab.get('txtWidth').default = ''; infoTab.get('txtBorder').default = '0'; infoTab.get('txtCellSpace').default = ''; infoTab.get('txtCellPad').default = ''; + break; + case 'link': + // remove unneeded widgets from the Link Info tab + var infotab = event.data.definition.getContents('info'); + infotab.remove('linkType'); + break; } }); @@ -65,7 +76,7 @@ CKEDITOR.on('instanceCreated', function (event) { editor.on('configLoaded', function () { var config = editor.config; config.language = 'nl'; - config.extraPlugins = 'sourcedialog,inlinesave,placeholder,image2,uploadimage'; + config.extraPlugins = 'inlinesave,placeholder,image2,uploadimage'; config.format_tags = 'h2;h3;h4;p'; config.allowedContent = true; config.entities = false; // keep unicode @@ -73,14 +84,21 @@ CKEDITOR.on('instanceCreated', function (event) { config.uploadUrl = '/edit?output=ckjson'; config.image2_alignClasses = ['left', 'center', 'right']; config.image2_disableResizer = true; + config.stylesSet = [ + { name: 'Kolom', element: 'div', attributes: { 'class': 'col' } }, + { name: 'Rechts', element: 'div', attributes: { 'class': 'right' } }, + ]; config.pasteFilter = pastefilter; config.contentsCss = document.styleSheets[0].href; config.toolbar = [ ['Inlinesave', '-', 'Undo', 'Redo'], - ['Format', 'BulletedList', 'NumberedList', 'Blockquote'], + ['Format'], ['Bold', 'Italic', 'Link'], - ['HorizontalRule', 'Table', 'Image'], - ['CreatePlaceholder', 'Sourcedialog'], + ['BulletedList', 'NumberedList', 'Blockquote'], + ['Table', 'CreateDiv'], + ['Image', 'HorizontalRule', 'CreatePlaceholder'], +// ['Sourcedialog'], + ['closebtn'], ]; config.toolbarCanCollapse = true; config.floatSpacePreferRight = true; @@ -104,14 +122,15 @@ CKEDITOR.on('instanceCreated', function (event) { var pagebody = document.getElementsByClassName('static')[0]; if (pagebody) { var editlink = document.querySelector('a[href="#edit"]'); + if (editlink) editlink.onclick = function (e) { editlink.style.fontWeight = 'bold'; editlink.href = ''; editlink.onclick = undefined; pagebody.setAttribute('contenteditable', true); pagebody.innerHTML = pagebody.innerHTML - .replace(/[^]*?/g, '$1'); - CKEDITOR.inline(pagebody); + .replace(/[^]*?/g, '$1'); + CKEDITOR.inline(pagebody, { customConfig: '' }); document.body.className = 'edit'; return false; };