edit: page editor and php save handler
[minimedit.git] / edit.js
1 CKEDITOR.plugins.add('inlinesave', {
2         init: function(editor) {
3                 editor.addCommand( 'inlinesave', {
4                         exec: function (editor) {
5                                 var pagename = window.location.pathname.replace(/^\//, '') || 'index';
6                                 var data = 'page='+encodeURIComponent(pagename)+'&body='+encodeURIComponent(editor.getData());
7                                 ajaxpost = new XMLHttpRequest();
8                                 ajaxpost.open('POST', 'edit.php', true);
9                                 ajaxpost.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
10                                 ajaxpost.onreadystatechange = function () {
11                                         if (ajaxpost.readyState != 4)
12                                                 return; // not done yet
13                                         if (ajaxpost.status != 200)
14                                                 alert('Foutcode '+ajaxpost.status+' bij opslaan: '+ajaxpost.responseText);
15                                         //else alert('ok: '+ajaxpost.responseText);
16                                 };
17                                 ajaxpost.send(data);
18                         },
19                 });
20                 editor.ui.addButton( 'Inlinesave', {
21                         command: 'inlinesave',
22                         label: editor.lang.save.toolbar,
23                         icon: this.path + '../save/icons/save.png',
24                 });
25         }
26 });
27
28 CKEDITOR.on('instanceCreated', function (event) {
29         var editor = event.editor;
30         editor.on('configLoaded', function () {
31                 var config = editor.config;
32                 config.language = 'nl';
33                 config.extraPlugins = 'sourcedialog,inlinesave';
34                 config.format_tags = 'h2;h3;h4;p';
35                 config.allowedContent = true;
36                 config.entities = false; // keep unicode
37                 config.toolbar = [
38                         ['Inlinesave', '-', 'ShowBlocks', 'Sourcedialog', '-', 'Undo', 'Redo'],
39                         ['Format'],
40                         ['BulletedList', 'NumberedList', '-', 'Blockquote'],
41                         ['Bold', 'Italic', 'Underline', 'Strike', '-', 'Link'],
42                         ['HorizontalRule', 'Table', 'Image'],
43                 ];
44                 config.enterMode = CKEDITOR.ENTER_BR; // results in <p>; ENTER_P does it twice
45         });
46 });
47
48 var pagebody = document.getElementsByClassName('article')[0];
49 pagebody.setAttribute('contenteditable', 'true');
50