3 function editorcontents() {
4 return document.getElementsByClassName('static')[0];
7 function editorsetup() {
9 CKEDITOR.disableAutoInline = true;
11 CKEDITOR.plugins.add('inlinesave', {
12 init: function(editor) {
13 editor.addCommand( 'inlinesave', {
14 exec: function (editor) {
15 var pagename = window.location.pathname;
16 var body = editor.getData();
17 // trim trailing whitespace in non-empty paragraphs
18 body = body.replace(/((?!<p>).{3})(?:\s|\u200B)+(?=<\/p>)/g, '$1');
19 // empty line is equivalent to a paragraph break
20 body = body.replace(/<br \/>\s*<br \/>/g, '<p>');
21 // keep names and preceding abbreviations together
22 body = body.replace(/\b((?:dhr|mw|me?vr|mr?s?)\.)\s+(?=[A-Z])/ig, '$1 ');
23 // wrap long line after each sentence
24 body = body.replace(/^(\t*).{73,}/mg, function (line, indent) {
25 var dots = '(?:.{24,72}|.{73,}?)'; // chars before punctuation
26 var wrap = new RegExp('('+dots+'[.:!?]) (?=[A-Z(<])', 'g'); // separate lines
27 return line.replace(wrap, '$1\n'+indent+'\t');
29 // treat standalone placeholders as block elements
30 body = body.replace(/<p>(\[\[.*\]\])<\/p>/g, '$1');
32 var data = 'body='+encodeURIComponent(body);
33 var ajaxpost = new XMLHttpRequest();
34 ajaxpost.open('POST', '/edit/page'+pagename, true);
35 ajaxpost.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
36 ajaxpost.onreadystatechange = function () {
37 if (ajaxpost.readyState != 4)
38 return; // not done yet
39 if (ajaxpost.status == 200) {
41 new CKEDITOR.plugins.notification(editor, {
42 message: 'Pagina is succesvol opgeslagen',
47 new CKEDITOR.plugins.notification(editor, {
48 message: 'Foutcode '+ajaxpost.status+' bij opslaan: '+ajaxpost.responseText,
56 editor.setKeystroke(CKEDITOR.CTRL + 83 /*S*/, 'inlinesave');
57 editor.ui.addButton( 'Inlinesave', {
58 command: 'inlinesave',
59 label: editor.lang.save.toolbar,
65 CKEDITOR.on('dialogDefinition', function (event) {
66 switch (event.data.name) {
68 // override initial attribute values
69 var infotab = event.data.definition.getContents('info');
70 infotab.remove('txtWidth');
71 infotab.remove('txtHeight');
72 infotab.remove('txtBorder');
73 infotab.remove('txtCellSpace');
74 infotab.remove('txtCellPad');
75 infotab.remove('cmbAlign');
77 // horizontal repositioning of existing elements
81 children: [ infotab.get('txtCols'), infotab.get('txtRows') ],
83 infotab.add(hbox, 'selHeaders');
84 infotab.remove('txtCols');
85 infotab.remove('txtRows');
89 // hide unneeded widgets from the Link Info tab
90 event.data.definition.getContents('info').get('linkType').hidden = true;
91 let linktarget = event.data.definition.getContents('target').get('linkTargetType');
92 linktarget.items = [ linktarget.items[0], linktarget.items[3] ]; // only _blank
97 CKEDITOR.on('instanceCreated', function (event) {
98 var editor = event.editor;
99 var pastefilter = 'h2 h3 p ul ol li blockquote em i strong b; a[!href]; img[alt,!src]';
101 editor.on('paste', function (e) {
102 var html = e.data.dataValue;
103 if (!/<[^>]* style="/.test(html) && !/<font/.test(html)) return;
105 // force pasteFilter on contents containing styling attributes
106 var filter = new CKEDITOR.filter(pastefilter),
107 fragment = CKEDITOR.htmlParser.fragment.fromHtml(html),
108 writer = new CKEDITOR.htmlParser.basicWriter();
109 filter.applyTo(fragment);
110 fragment.writeHtml(writer);
111 e.data.dataValue = writer.getHtml();
114 editor.on('configLoaded', function () {
115 var config = editor.config;
116 config.language = 'nl';
117 config.extraPlugins = 'inlinesave,placeholder,image2,uploadimage';
118 config.format_tags = 'h2;h3;h4;p';
119 config.allowedContent = true;
120 config.entities = false; // keep unicode
121 config.filebrowserImageUploadUrl = '/edit/page?output=ckescript';
122 config.uploadUrl = '/edit/page?output=ckjson';
123 config.image2_alignClasses = ['left', 'center', 'right'];
124 config.image2_disableResizer = true;
126 { name: 'Klein', element: 'small' },
127 { name: 'Zijkant', element: 'span', attributes: { 'class': 'right' } },
128 { name: 'Attributie', element: 'em', attributes: { 'class': 'right' } },
129 { name: 'Quote', element: 'q' },
130 { name: 'Gemarkeerd', element: 'span', styles: { 'background-color': 'Yellow' } },
131 { name: 'Ingelogd', element: 'span', attributes: { 'class': 'login' } },
132 { name: 'Uitgelogd', element: 'span', attributes: { 'class': 'logout' } },
134 { name: 'Kadertekst', element: 'aside' },
135 { name: 'Uitgelijnd', element: 'div', attributes: { 'class': 'right' } },
136 { name: 'Kolom', element: 'div', attributes: { 'class': 'col' } },
137 { name: 'Waarschuwing', element: 'div', attributes: { 'class': 'warn' } },
139 config.pasteFilter = pastefilter;
140 config.contentsCss = document.styleSheets[0].href;
142 ['Inlinesave', '-', 'Undo', 'Redo'],
143 ['Format', 'Styles'],
144 ['Bold', 'Italic', 'Link'],
145 ['BulletedList', 'NumberedList', 'Blockquote'],
146 ['Table', 'CreateDiv'],
147 ['Image', 'HorizontalRule', 'CreatePlaceholder'],
151 config.toolbarCanCollapse = true;
152 config.floatSpacePreferRight = true;
153 config.floatSpaceDockedOffsetY = 0;
154 config.title = false;
155 config.startupFocus = true;
157 config.disableObjectResizing = true;
158 document.execCommand('enableObjectResizing', false, false); // workaround in inline mode; ff bug?
161 window.onbeforeunload = function () {
162 if (editor.checkDirty()) {
163 return 'Pagina verlaten zonder wijzigingen op te slaan?'; // message ignored in modern browsers
169 // add edit link to menu
170 var editlink = document.querySelector('a[href="#edit"]');
172 editlink.onclick = function (e) {
173 editlink.style.fontWeight = 'bold';
175 editlink.onclick = undefined;
176 document.body.replaceChild(pagebody, editorcontents());
177 pagebody.setAttribute('contenteditable', true);
178 pagebody.querySelectorAll('[data-dyn]').forEach(function (el) {
179 let blockname = el.getAttribute('data-dyn');
184 el.outerHTML = '[[' + blockname + ']]';
186 CKEDITOR.inline(pagebody, { customConfig: '' });
187 document.body.className = 'edit';
190 if (window.location.hash == '#edit') {
197 document.addEventListener('DOMContentLoaded', function (e) {
198 pagebody = editorcontents().cloneNode(true);
199 var editorinc = document.createElement('script');
200 editorinc.addEventListener('load', editorsetup);
201 editorinc.src = ckesrc;
202 document.getElementsByTagName('head')[0].appendChild(editorinc);