X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/544de694190d0961127503e9e6a1e5a67eb742ae..43a352bd08ac38800f6fa73d48d565f39bca4549:/edit.js diff --git a/edit.js b/edit.js index 88b03e3..1485394 100644 --- a/edit.js +++ b/edit.js @@ -2,17 +2,30 @@ CKEDITOR.plugins.add('inlinesave', { init: function(editor) { editor.addCommand( 'inlinesave', { exec: function (editor) { - var pagename = window.location.pathname.replace(/^\//, '') || 'index'; - var data = 'page='+encodeURIComponent(pagename)+'&body='+encodeURIComponent(editor.getData()); + 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) { + 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'); + }); + // treat standalone placeholders as block elements + body = body.replace(/

(\[\[.*\]\])<\/p>/g, '$1'); + + var data = 'body='+encodeURIComponent(body); ajaxpost = new XMLHttpRequest(); - ajaxpost.open('POST', 'edit.php', true); + ajaxpost.open('POST', '/edit'+pagename, true); ajaxpost.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); ajaxpost.onreadystatechange = function () { if (ajaxpost.readyState != 4) return; // not done yet if (ajaxpost.status != 200) alert('Foutcode '+ajaxpost.status+' bij opslaan: '+ajaxpost.responseText); - //else alert('ok: '+ajaxpost.responseText); + else + editor.resetDirty(); }; ajaxpost.send(data); }, @@ -20,54 +33,105 @@ CKEDITOR.plugins.add('inlinesave', { editor.ui.addButton( 'Inlinesave', { command: 'inlinesave', label: editor.lang.save.toolbar, - icon: this.path + '../save/icons/save.png', + icon: 'save', }); } }); 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; } }); CKEDITOR.on('instanceCreated', function (event) { var editor = event.editor; + var pastefilter = 'h2 h3 p ul ol li blockquote em i strong b; a[!href]; img[alt,!src]'; + + editor.on('paste', function (e) { + var html = e.data.dataValue; + if (!/<[^>]* style="/.test(html) && !/[^]*?/g, '$1'); + CKEDITOR.inline(pagebody); + document.body.className = 'edit'; + return false; + }; + if (window.location.hash == '#edit') { + editlink.onclick(); + } +}