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.allowedContent = true;
119 config.entities = false; // keep unicode
120 config.filebrowserImageUploadUrl = '/edit/page?output=ckescript';
121 config.uploadUrl = '/edit/page?output=ckjson';
122 config.image2_alignClasses = ['left', 'center', 'right'];
123 config.image2_disableResizer = true;
125 { name: 'Paginakop', element: 'h2' },
126 { name: 'Paragraafkop', element: 'h3' },
127 { name: 'Alineakop', element: 'h4' },
129 { name: 'Gerelateerd', element: 'aside' },
130 { name: 'Voetnoot', element: 'div', attributes: { 'class': 'right' } },
131 { name: 'Kolom', element: 'div', attributes: { 'class': 'col' } },
132 { name: 'Navigatie', element: 'p', attributes: { 'class': 'nav' } },
133 { name: 'Waarschuwing', element: 'div', attributes: { 'class': 'warn' } },
135 { name: 'Klein', element: 'small' },
136 { name: 'Aanhaling', element: 'q' },
137 { name: 'Doorstreept', element: 's' },
138 { name: 'Gemarkeerd', element: 'mark' },
139 { name: 'Rechts', element: 'span', attributes: { 'class': 'right' } },
140 { name: 'Attributie', element: 'em', attributes: { 'class': 'right' } },
141 { name: 'Ingelogd', element: 'span', attributes: { 'class': 'login' } },
142 { name: 'Uitgelogd', element: 'span', attributes: { 'class': 'logout' } },
144 config.pasteFilter = pastefilter;
145 config.contentsCss = document.styleSheets[0].href;
147 ['Inlinesave', '-', 'Undo', 'Redo'],
148 ['Styles', 'Bold', 'Italic', 'Link'],
149 ['BulletedList', 'NumberedList', 'Blockquote'],
150 ['Table', 'CreateDiv'],
151 ['Image', 'HorizontalRule', 'CreatePlaceholder'],
155 config.toolbarCanCollapse = true;
156 config.floatSpacePreferRight = true;
157 config.floatSpaceDockedOffsetY = 0;
158 config.title = false;
159 config.startupFocus = true;
161 config.disableObjectResizing = true;
162 document.execCommand('enableObjectResizing', false, false); // workaround in inline mode; ff bug?
165 window.onbeforeunload = function () {
166 if (editor.checkDirty()) {
167 return 'Pagina verlaten zonder wijzigingen op te slaan?'; // message ignored in modern browsers
173 // add edit link to menu
174 var editlink = document.querySelector('a[href="#edit"]');
176 editlink.onclick = function (e) {
177 editlink.style.fontWeight = 'bold';
179 editlink.onclick = undefined;
180 document.body.replaceChild(pagebody, editorcontents());
181 pagebody.setAttribute('contenteditable', true);
182 pagebody.querySelectorAll('[data-dyn]').forEach(function (el) {
183 let blockname = el.getAttribute('data-dyn');
188 el.outerHTML = '[[' + blockname + ']]';
190 CKEDITOR.inline(pagebody, { customConfig: '' });
191 document.body.className = 'edit';
194 if (window.location.hash == '#edit') {
201 document.addEventListener('DOMContentLoaded', function (e) {
202 pagebody = editorcontents().cloneNode(true);
203 var editorinc = document.createElement('script');
204 editorinc.addEventListener('load', editorsetup);
205 editorinc.src = ckesrc;
206 document.getElementsByTagName('head')[0].appendChild(editorinc);