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');
31 // strip redundant domain in relative urls
32 var hostlink = 'https?://' + window.location.hostname.replace(/\W/g, '\\$&');
33 hostlink = new RegExp('(<a [^>]*href="|<img [^>]*src=")' + hostlink + '(?=/)', 'gi');
34 body = body.replace(hostlink, '$1');
36 var data = 'body='+encodeURIComponent(body);
37 var ajaxpost = new XMLHttpRequest();
38 ajaxpost.open('POST', '/edit/page'+pagename, true);
39 ajaxpost.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
40 ajaxpost.onreadystatechange = function () {
41 if (ajaxpost.readyState != 4)
42 return; // not done yet
43 if (ajaxpost.status == 200) {
45 new CKEDITOR.plugins.notification(editor, {
46 message: 'Pagina is succesvol opgeslagen',
51 new CKEDITOR.plugins.notification(editor, {
52 message: 'Foutcode '+ajaxpost.status+' bij opslaan: '+ajaxpost.responseText,
60 editor.setKeystroke(CKEDITOR.CTRL + 83 /*S*/, 'inlinesave');
61 editor.ui.addButton( 'Inlinesave', {
62 command: 'inlinesave',
63 label: editor.lang.save.toolbar,
69 CKEDITOR.on('dialogDefinition', function (event) {
70 switch (event.data.name) {
72 // override initial attribute values
73 var infotab = event.data.definition.getContents('info');
74 infotab.remove('txtWidth');
75 infotab.remove('txtHeight');
76 infotab.remove('txtBorder');
77 infotab.remove('txtCellSpace');
78 infotab.remove('txtCellPad');
79 infotab.remove('cmbAlign');
81 // horizontal repositioning of existing elements
85 children: [ infotab.get('txtCols'), infotab.get('txtRows') ],
87 infotab.add(hbox, 'selHeaders');
88 infotab.remove('txtCols');
89 infotab.remove('txtRows');
93 // hide unneeded widgets from the Link Info tab
94 event.data.definition.getContents('info').get('linkType').hidden = true;
95 let linktarget = event.data.definition.getContents('target').get('linkTargetType');
96 linktarget.items = [ linktarget.items[0], linktarget.items[3] ]; // only _blank
101 CKEDITOR.on('instanceCreated', function (event) {
102 var editor = event.editor;
103 var pastefilter = 'h2 h3 p ul ol li blockquote em i strong b; a[!href]; img[alt,!src]';
105 editor.on('paste', function (e) {
106 var html = e.data.dataValue;
107 if (!/<[^>]* style="/.test(html) && !/<font/.test(html)) return;
109 // force pasteFilter on contents containing styling attributes
110 var filter = new CKEDITOR.filter(pastefilter),
111 fragment = CKEDITOR.htmlParser.fragment.fromHtml(html),
112 writer = new CKEDITOR.htmlParser.basicWriter();
113 filter.applyTo(fragment);
114 fragment.writeHtml(writer);
115 e.data.dataValue = writer.getHtml();
118 editor.on('configLoaded', function () {
119 var config = editor.config;
120 config.language = 'nl';
121 config.extraPlugins = 'inlinesave,placeholder,image2,uploadimage';
122 config.allowedContent = true;
123 config.entities = false; // keep unicode
124 config.filebrowserImageUploadUrl = '/edit/page?output=ckescript';
125 config.uploadUrl = '/edit/page?output=ckjson';
126 config.image2_alignClasses = ['left', 'center', 'right'];
127 config.image2_disableResizer = true;
129 { name: 'Paginakop', element: 'h2' },
130 { name: 'Paragraafkop', element: 'h3' },
131 { name: 'Alineakop', element: 'h4' },
133 { name: 'Gerelateerd', element: 'aside' },
134 { name: 'Voetnoot', element: 'div', attributes: { 'class': 'right' } },
135 { name: 'Kolom', element: 'div', attributes: { 'class': 'col' } },
136 { name: 'Navigatie', element: 'p', attributes: { 'class': 'nav' } },
137 { name: 'Waarschuwing', element: 'div', attributes: { 'class': 'warn' } },
139 { name: 'Klein', element: 'small' },
140 { name: 'Aanhaling', element: 'q' },
141 { name: 'Doorstreept', element: 's' },
142 { name: 'Gemarkeerd', element: 'mark' },
143 { name: 'Rechts', element: 'span', attributes: { 'class': 'right' } },
144 { name: 'Attributie', element: 'em', attributes: { 'class': 'right' } },
145 { name: 'Ingelogd', element: 'span', attributes: { 'class': 'login' } },
146 { name: 'Uitgelogd', element: 'span', attributes: { 'class': 'logout' } },
148 config.pasteFilter = pastefilter;
149 config.contentsCss = document.styleSheets[0].href;
151 ['Inlinesave', '-', 'Undo', 'Redo'],
152 ['Styles', 'Bold', 'Italic', 'Link'],
153 ['BulletedList', 'NumberedList', 'Blockquote'],
154 ['Table', 'CreateDiv'],
155 ['Image', 'HorizontalRule', 'CreatePlaceholder'],
159 config.toolbarCanCollapse = true;
160 config.floatSpacePreferRight = true;
161 config.floatSpaceDockedOffsetY = 0;
162 config.title = false;
163 config.startupFocus = true;
165 config.disableObjectResizing = true;
166 document.execCommand('enableObjectResizing', false, false); // workaround in inline mode; ff bug?
169 window.onbeforeunload = function () {
170 if (editor.checkDirty()) {
171 return 'Pagina verlaten zonder wijzigingen op te slaan?'; // message ignored in modern browsers
177 // add edit link to menu
178 var editlink = document.querySelector('a[href="#edit"]');
180 editlink.onclick = function (e) {
181 editlink.style.fontWeight = 'bold';
183 editlink.onclick = undefined;
184 document.body.replaceChild(pagebody, editorcontents());
185 pagebody.setAttribute('contenteditable', true);
186 pagebody.querySelectorAll('[data-dyn]').forEach(function (el) {
187 let blockname = el.getAttribute('data-dyn');
192 el.outerHTML = '[[' + blockname + ']]';
194 CKEDITOR.inline(pagebody, { customConfig: '' });
195 document.body.className = 'edit';
198 if (window.location.hash == '#edit') {
205 document.addEventListener('DOMContentLoaded', function (e) {
206 pagebody = editorcontents().cloneNode(true);
207 var editorinc = document.createElement('script');
208 editorinc.addEventListener('load', editorsetup);
209 editorinc.src = ckesrc;
210 document.getElementsByTagName('head')[0].appendChild(editorinc);