X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/be188ffac98a3d824a1e143e1a5766801130c876..3dd944a535c60c1b25dedda5c942d43fd0b6421e:/edit.js diff --git a/edit.js b/edit.js index 94e84cc..21028dc 100644 --- a/edit.js +++ b/edit.js @@ -2,17 +2,24 @@ 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().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.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 + alert('Pagina is goed opgeslagen'); }; ajaxpost.send(data); }, @@ -20,7 +27,7 @@ CKEDITOR.plugins.add('inlinesave', { editor.ui.addButton( 'Inlinesave', { command: 'inlinesave', label: editor.lang.save.toolbar, - icon: this.path + '../save/icons/save.png', + icon: 'save', }); } }); @@ -41,30 +48,49 @@ CKEDITOR.on('instanceCreated', function (event) { editor.on('configLoaded', function () { var config = editor.config; config.language = 'nl'; - config.extraPlugins = 'sourcedialog,inlinesave'; + config.extraPlugins = 'sourcedialog,inlinesave,placeholder'; config.format_tags = 'h2;h3;h4;p'; config.allowedContent = true; config.entities = false; // keep unicode + config.filebrowserImageUploadUrl = '/edit?type=img'; + config.forcePasteAsPlainText = true; + config.contentsCss = '/excelsior.css'; config.toolbar = [ ['Inlinesave', '-', 'ShowBlocks', 'Sourcedialog', '-', 'Undo', 'Redo'], ['Format'], ['BulletedList', 'NumberedList', '-', 'Blockquote'], - ['Bold', 'Italic', 'Underline', 'Strike', '-', 'Link'], - ['HorizontalRule', 'Table', 'Image'], + ['Bold', 'Italic', 'Underline', 'Strike', 'RemoveFormat', '-', 'Anchor', 'Link'], + ['HorizontalRule', 'Table', 'Image', 'CreatePlaceholder'], ]; + config.toolbarCanCollapse = true; + config.floatSpacePreferRight = true; + config.floatSpaceDockedOffsetY = 0; + config.startupFocus = true; + + config.disableObjectResizing = true; + document.execCommand('enableObjectResizing', false, false); // workaround in inline mode; ff bug? }); }); - CKEDITOR.on('instanceReady', function (event) { - var editor = event.editor; - var writer = editor.dataProcessor.writer; - writer.selfClosingEnd = '>'; - writer.setRules( 'p', { - breakAfterOpen: true, - breakBeforeClose: true, - }); - }); + CKEDITOR.disableAutoInline = true; -var pagebody = document.getElementsByClassName('article')[0]; -pagebody.setAttribute('contenteditable', 'true'); +// add edit link to menu +var pagebody = document.getElementsByClassName('static')[0]; +if (pagebody) { + var editlink = document.querySelector('a[href="#edit"]'); + 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); + document.body.className = 'edit'; + return false; + }; + if (window.location.hash == '#edit') { + editlink.onclick(); + } +}