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();
7 // empty line is equivalent to a paragraph break
8 body = body.replace(/<br \/>\s*<br \/>/g, '<p>');
9 // wrap long line after each sentence
10 body = body.replace(/^(\t*).{73,}/mg, function (line, indent) {
11 var dots = '(?:.{24,72}|.{73,}?)'; // chars before punctuation
12 var wrap = new RegExp('('+dots+'[.:!?]) (?=[A-Z(<])', 'g'); // separate lines
13 return line.replace(wrap, '$1\n'+indent+'\t');
15 // treat standalone placeholders as block elements
16 body = body.replace(/<p>(\[\[.*\]\])<\/p>/g, '$1');
18 var data = 'body='+encodeURIComponent(body);
19 ajaxpost = new XMLHttpRequest();
20 ajaxpost.open('POST', '/edit'+pagename, true);
21 ajaxpost.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
22 ajaxpost.onreadystatechange = function () {
23 if (ajaxpost.readyState != 4)
24 return; // not done yet
25 if (ajaxpost.status != 200)
26 alert('Foutcode '+ajaxpost.status+' bij opslaan: '+ajaxpost.responseText);
33 editor.ui.addButton( 'Inlinesave', {
34 command: 'inlinesave',
35 label: editor.lang.save.toolbar,
41 CKEDITOR.on('dialogDefinition', function (event) {
42 switch (event.data.name) {
44 // override initial attribute values
45 var infoTab = event.data.definition.getContents('info');
46 infoTab.get('txtWidth').default = '';
47 infoTab.get('txtBorder').default = '0';
48 infoTab.get('txtCellSpace').default = '';
49 infoTab.get('txtCellPad').default = '';
52 // remove unneeded widgets from the Link Info tab
53 var infotab = event.data.definition.getContents('info');
54 infotab.remove('linkType');
59 CKEDITOR.on('instanceCreated', function (event) {
60 var editor = event.editor;
61 var pastefilter = 'h2 h3 p ul ol li blockquote em i strong b; a[!href]; img[alt,!src]';
63 editor.on('paste', function (e) {
64 var html = e.data.dataValue;
65 if (!/<[^>]* style="/.test(html) && !/<font/.test(html)) return;
67 // force pasteFilter on contents containing styling attributes
68 var filter = new CKEDITOR.filter(pastefilter),
69 fragment = CKEDITOR.htmlParser.fragment.fromHtml(html),
70 writer = new CKEDITOR.htmlParser.basicWriter();
71 filter.applyTo(fragment);
72 fragment.writeHtml(writer);
73 e.data.dataValue = writer.getHtml();
76 editor.on('configLoaded', function () {
77 var config = editor.config;
78 config.language = 'nl';
79 config.extraPlugins = 'inlinesave,placeholder,image2,uploadimage';
80 config.format_tags = 'h2;h3;h4;p';
81 config.allowedContent = true;
82 config.entities = false; // keep unicode
83 config.filebrowserImageUploadUrl = '/edit?output=ckescript';
84 config.uploadUrl = '/edit?output=ckjson';
85 config.image2_alignClasses = ['left', 'center', 'right'];
86 config.image2_disableResizer = true;
88 { name: 'Kolom', element: 'div', attributes: { 'class': 'col' } },
89 { name: 'Rechts', element: 'div', attributes: { 'class': 'right' } },
91 config.pasteFilter = pastefilter;
92 config.contentsCss = document.styleSheets[0].href;
94 ['Inlinesave', '-', 'Undo', 'Redo'],
96 ['Bold', 'Italic', 'Link'],
97 ['BulletedList', 'NumberedList', 'Blockquote'],
98 ['Table', 'CreateDiv'],
99 ['Image', 'HorizontalRule', 'CreatePlaceholder'],
103 config.toolbarCanCollapse = true;
104 config.floatSpacePreferRight = true;
105 config.floatSpaceDockedOffsetY = 0;
106 config.startupFocus = true;
108 config.disableObjectResizing = true;
109 document.execCommand('enableObjectResizing', false, false); // workaround in inline mode; ff bug?
112 window.onbeforeunload = function () {
113 if (editor.checkDirty()) {
114 return 'Pagina verlaten zonder wijzigingen op te slaan?'; // message ignored in modern browsers
119 CKEDITOR.disableAutoInline = true;
121 // add edit link to menu
122 var pagebody = document.getElementsByClassName('static')[0];
124 var editlink = document.querySelector('a[href="#edit"]');
126 editlink.onclick = function (e) {
127 editlink.style.fontWeight = 'bold';
129 editlink.onclick = undefined;
130 pagebody.setAttribute('contenteditable', true);
131 pagebody.innerHTML = pagebody.innerHTML
132 .replace(/<!--BLOCK:(.*?)-->[^]*?<!--\/-->/g, '$1');
133 CKEDITOR.inline(pagebody, { customConfig: '' });
134 document.body.className = 'edit';
137 if (window.location.hash == '#edit') {