X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/502945bc14e9fdd9f4268103227462af442c0560..42d01534123ab54ae8d2ceee5fe9357605b5e637:/edit.js diff --git a/edit.js b/edit.js index 78bf6dc..c5d6ce3 100644 --- a/edit.js +++ b/edit.js @@ -2,10 +2,10 @@ CKEDITOR.plugins.add('inlinesave', { init: function(editor) { editor.addCommand( 'inlinesave', { exec: function (editor) { - var pagename = window.location.pathname.replace(/\.html$/, '').replace(/\/$/, '/index'); + var pagename = window.location.pathname.replace(/\/$/, '/index'); var data = 'body='+encodeURIComponent(editor.getData()); ajaxpost = new XMLHttpRequest(); - ajaxpost.open('POST', '/edit.php'+pagename, true); + ajaxpost.open('POST', '/edit'+pagename, true); ajaxpost.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); ajaxpost.onreadystatechange = function () { if (ajaxpost.readyState != 4) @@ -21,7 +21,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', }); } }); @@ -46,13 +46,14 @@ CKEDITOR.on('instanceCreated', function (event) { config.format_tags = 'h2;h3;h4;p'; config.allowedContent = true; config.entities = false; // keep unicode - config.filebrowserImageUploadUrl = '/edit.php?type=img'; + 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', 'RemoveFormat', '-', 'Link'], + ['Bold', 'Italic', 'Underline', 'Strike', 'RemoveFormat', '-', 'Anchor', 'Link'], ['HorizontalRule', 'Table', 'Image'], ]; @@ -71,8 +72,30 @@ CKEDITOR.on('instanceCreated', function (event) { }); }); -var pagebody = document.getElementsByClassName('article')[0]; -pagebody.setAttribute('contenteditable', 'true'); + CKEDITOR.disableAutoInline = true; -document.body.className = 'edit'; +// add edit link to menu +var pagebody = document.getElementsByClassName('static')[0]; +if (pagebody) { + var editlink = document.createElement('a'); + editlink.style.cursor = 'pointer'; + editlink.appendChild(document.createTextNode('Wijzig')); + editlink.onclick = function (e) { + var toggled = editlink.style.fontWeight; + editlink.style.fontWeight = toggled ? '' : 'bold'; + pagebody.setAttribute('contenteditable', !toggled); + if (toggled) { + for (name in CKEDITOR.instances) { + CKEDITOR.instances[name].destroy() + } + } + else { + CKEDITOR.inline(pagebody); + pagebody.focus(); + } + document.body.className = toggled ? '' : 'edit'; + return false; + }; + document.querySelector('header ul').appendChild(editlink); +}