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 = '/excelsior.css';
59 ['Inlinesave', '-', 'ShowBlocks', 'Sourcedialog', '-', 'Undo', 'Redo'],
61 ['BulletedList', 'NumberedList', '-', 'Blockquote'],
62 ['Bold', 'Italic', 'Underline', 'Strike', 'RemoveFormat', '-', 'Anchor', 'Link'],
63 ['HorizontalRule', 'Table', 'Image', 'CreatePlaceholder'],
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.createElement('a');
81 editlink.style.cursor = 'pointer';
82 editlink.appendChild(document.createTextNode('Wijzig'));
83 editlink.href = '#edit';
84 editlink.onclick = function (e) {
85 editlink.style.fontWeight = 'bold';
87 editlink.onclick = undefined;
88 pagebody.setAttribute('contenteditable', true);
89 pagebody.innerHTML = pagebody.innerHTML
90 .replace(/<!--BLOCK:([^-]*)-->[^]*?<!--\/-->/g, '$1');
91 CKEDITOR.inline(pagebody);
92 document.body.className = 'edit';
95 if (window.location.hash == '#edit') {
98 document.querySelector('header ul').appendChild(editlink);