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 body = editor.getData().replace(/^(\t*).{73,}/mg, function (line, indent) {
7 // wrap long line after each sentence
8 var dots = '(?:.{24,72}|.{73,}?)'; // chars before punctuation
9 var wrap = new RegExp('('+dots+'[.;:!?]) (?=[A-Z(<])', 'g'); // separate lines
10 return line.replace(wrap, '$1\n'+indent+'\t');
12 var data = 'body='+encodeURIComponent(body);
13 ajaxpost = new XMLHttpRequest();
14 ajaxpost.open('POST', '/edit'+pagename, true);
15 ajaxpost.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
16 ajaxpost.onreadystatechange = function () {
17 if (ajaxpost.readyState != 4)
18 return; // not done yet
19 if (ajaxpost.status != 200)
20 alert('Foutcode '+ajaxpost.status+' bij opslaan: '+ajaxpost.responseText);
22 alert('Pagina is goed opgeslagen');
27 editor.ui.addButton( 'Inlinesave', {
28 command: 'inlinesave',
29 label: editor.lang.save.toolbar,
35 CKEDITOR.on('dialogDefinition', function (event) {
36 if (event.data.name === 'table') {
37 // override initial attribute values
38 var infoTab = event.data.definition.getContents('info');
39 infoTab.get('txtWidth').default = '';
40 infoTab.get('txtBorder').default = '0';
41 infoTab.get('txtCellSpace').default = '';
42 infoTab.get('txtCellPad').default = '';
46 CKEDITOR.on('instanceCreated', function (event) {
47 var editor = event.editor;
48 editor.on('configLoaded', function () {
49 var config = editor.config;
50 config.language = 'nl';
51 config.extraPlugins = 'sourcedialog,inlinesave,placeholder';
52 config.format_tags = 'h2;h3;h4;p';
53 config.allowedContent = true;
54 config.entities = false; // keep unicode
55 config.filebrowserImageUploadUrl = '/edit?type=img';
56 config.forcePasteAsPlainText = true;
57 config.contentsCss = document.styleSheets[0].href;
59 ['Inlinesave', '-', 'Undo', 'Redo'],
60 ['Format', 'BulletedList', 'NumberedList', 'Blockquote'],
61 ['Bold', 'Italic', 'Link'],
62 ['HorizontalRule', 'Table', 'Image'],
63 ['CreatePlaceholder', 'Sourcedialog'],
65 config.toolbarCanCollapse = true;
66 config.floatSpacePreferRight = true;
67 config.floatSpaceDockedOffsetY = 0;
68 config.startupFocus = true;
70 config.disableObjectResizing = true;
71 document.execCommand('enableObjectResizing', false, false); // workaround in inline mode; ff bug?
75 CKEDITOR.disableAutoInline = true;
77 // add edit link to menu
78 var pagebody = document.getElementsByClassName('static')[0];
80 var editlink = document.querySelector('a[href="#edit"]');
81 editlink.onclick = function (e) {
82 editlink.style.fontWeight = 'bold';
84 editlink.onclick = undefined;
85 pagebody.setAttribute('contenteditable', true);
86 pagebody.innerHTML = pagebody.innerHTML
87 .replace(/<!--BLOCK:([^-]*)-->[^]*?<!--\/-->/g, '$1');
88 CKEDITOR.inline(pagebody);
89 document.body.className = 'edit';
92 if (window.location.hash == '#edit') {