X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/769e3ba9e234db9019a096e1d6590f902b5560e0..a92a5dd241cdcf08d3378a393a54d0a24a07b48e:/edit.js diff --git a/edit.js b/edit.js index c32bd5b..f6df1e5 100644 --- a/edit.js +++ b/edit.js @@ -3,7 +3,15 @@ CKEDITOR.plugins.add('inlinesave', { editor.addCommand( 'inlinesave', { exec: function (editor) { var pagename = window.location.pathname.replace(/\/$/, '/index'); - var data = 'body='+encodeURIComponent(editor.getData()); + var body = editor.getData(); + body = body.replace(/
\s*
/g, '

'); + 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 + return line.replace(wrap, '$1\n'+indent+'\t'); + }); + var data = 'body='+encodeURIComponent(body); ajaxpost = new XMLHttpRequest(); ajaxpost.open('POST', '/edit'+pagename, true); ajaxpost.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); @@ -13,7 +21,7 @@ CKEDITOR.plugins.add('inlinesave', { if (ajaxpost.status != 200) alert('Foutcode '+ajaxpost.status+' bij opslaan: '+ajaxpost.responseText); else - alert('Pagina is goed opgeslagen'); + editor.resetDirty(); }; ajaxpost.send(data); }, @@ -27,34 +35,63 @@ 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; } }); 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) && !/