2e961768ddfbccf5fcdbbde21df8718248a9c3c8
[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(/\.html$/, '').replace(/\/$/, '/index');
6                                 var data = 'body='+encodeURIComponent(editor.getData());
7                                 ajaxpost = new XMLHttpRequest();
8                                 ajaxpost.open('POST', '/edit.php'+pagename, 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('dialogDefinition', function (event) {
29         if (event.data.name === 'table') {
30                 // override initial attribute values
31                 var infoTab = event.data.definition.getContents('info');
32                 infoTab.get('txtWidth').default = '';
33                 infoTab.get('txtBorder').default = '0';
34                 infoTab.get('txtCellSpace').default = '';
35                 infoTab.get('txtCellPad').default = '';
36         }
37 });
38
39 CKEDITOR.on('instanceCreated', function (event) {
40         var editor = event.editor;
41         editor.on('configLoaded', function () {
42                 var config = editor.config;
43                 config.language = 'nl';
44                 config.extraPlugins = 'sourcedialog,inlinesave';
45                 config.format_tags = 'h2;h3;h4;p';
46                 config.allowedContent = true;
47                 config.entities = false; // keep unicode
48                 config.filebrowserImageUploadUrl = '/edit.php?type=img';
49                 config.forcePasteAsPlainText = true;
50                 config.toolbar = [
51                         ['Inlinesave', '-', 'ShowBlocks', 'Sourcedialog', '-', 'Undo', 'Redo'],
52                         ['Format'],
53                         ['BulletedList', 'NumberedList', '-', 'Blockquote'],
54                         ['Bold', 'Italic', 'Underline', 'Strike', 'RemoveFormat', '-', 'Link'],
55                         ['HorizontalRule', 'Table', 'Image'],
56                 ];
57
58                 config.disableObjectResizing = true;
59                 document.execCommand('enableObjectResizing', false, false); // workaround in inline mode; ff bug?
60         });
61 });
62
63         CKEDITOR.on('instanceReady', function (event) {
64                 var editor = event.editor;
65                 var writer = editor.dataProcessor.writer;
66                 writer.selfClosingEnd = '>';
67                 writer.setRules( 'p', {
68                         breakAfterOpen: true,
69                         breakBeforeClose: true,
70                 });
71         });
72
73 var pagebody = document.getElementsByClassName('article')[0];
74 pagebody.setAttribute('contenteditable', 'true');
75
76 document.body.className = 'edit';
77