1 CKEDITOR.plugins.add('inlinesave', {
2 init: function(editor) {
3 editor.addCommand( 'inlinesave', {
4 exec: function (editor) {
5 var pagename = window.location.pathname;
6 var body = editor.getData();
7 // trim trailing whitespace in non-empty paragraphs
8 body = body.replace(/((?!<p>).{3})(?:\s|\u200B)+(?=<\/p>)/g, '$1');
9 // empty line is equivalent to a paragraph break
10 body = body.replace(/<br \/>\s*<br \/>/g, '<p>');
11 // keep names and preceding abbreviations together
12 body = body.replace(/\b((?:dhr|mw|me?vr|mr?s?)\.)\s+(?=[A-Z])/ig, '$1 ');
13 // wrap long line after each sentence
14 body = body.replace(/^(\t*).{73,}/mg, function (line, indent) {
15 var dots = '(?:.{24,72}|.{73,}?)'; // chars before punctuation
16 var wrap = new RegExp('('+dots+'[.:!?]) (?=[A-Z(<])', 'g'); // separate lines
17 return line.replace(wrap, '$1\n'+indent+'\t');
19 // treat standalone placeholders as block elements
20 body = body.replace(/<p>(\[\[.*\]\])<\/p>/g, '$1');
22 var data = 'body='+encodeURIComponent(body);
23 var ajaxpost = new XMLHttpRequest();
24 ajaxpost.open('POST', '/edit/page'+pagename, true);
25 ajaxpost.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
26 ajaxpost.onreadystatechange = function () {
27 if (ajaxpost.readyState != 4)
28 return; // not done yet
29 if (ajaxpost.status == 200) {
31 new CKEDITOR.plugins.notification(editor, {
32 message: 'Pagina is succesvol opgeslagen',
37 new CKEDITOR.plugins.notification(editor, {
38 message: 'Foutcode '+ajaxpost.status+' bij opslaan: '+ajaxpost.responseText,
46 editor.setKeystroke(CKEDITOR.CTRL + 83 /*S*/, 'inlinesave');
47 editor.ui.addButton( 'Inlinesave', {
48 command: 'inlinesave',
49 label: editor.lang.save.toolbar,
55 CKEDITOR.on('dialogDefinition', function (event) {
56 switch (event.data.name) {
58 // override initial attribute values
59 var infotab = event.data.definition.getContents('info');
60 infotab.remove('txtWidth');
61 infotab.remove('txtHeight');
62 infotab.remove('txtBorder');
63 infotab.remove('txtCellSpace');
64 infotab.remove('txtCellPad');
65 infotab.remove('cmbAlign');
67 // horizontal repositioning of existing elements
71 children: [ infotab.get('txtCols'), infotab.get('txtRows') ],
73 infotab.add(hbox, 'selHeaders');
74 infotab.remove('txtCols');
75 infotab.remove('txtRows');
79 // hide unneeded widgets from the Link Info tab
80 event.data.definition.getContents('info').get('linkType').hidden = true;
81 let linktarget = event.data.definition.getContents('target').get('linkTargetType');
82 linktarget.items = [ linktarget.items[0], linktarget.items[3] ]; // only _blank
87 CKEDITOR.on('instanceCreated', function (event) {
88 var editor = event.editor;
89 var pastefilter = 'h2 h3 p ul ol li blockquote em i strong b; a[!href]; img[alt,!src]';
91 editor.on('paste', function (e) {
92 var html = e.data.dataValue;
93 if (!/<[^>]* style="/.test(html) && !/<font/.test(html)) return;
95 // force pasteFilter on contents containing styling attributes
96 var filter = new CKEDITOR.filter(pastefilter),
97 fragment = CKEDITOR.htmlParser.fragment.fromHtml(html),
98 writer = new CKEDITOR.htmlParser.basicWriter();
99 filter.applyTo(fragment);
100 fragment.writeHtml(writer);
101 e.data.dataValue = writer.getHtml();
104 editor.on('configLoaded', function () {
105 var config = editor.config;
106 config.language = 'nl';
107 config.extraPlugins = 'inlinesave,placeholder,image2,uploadimage';
108 config.format_tags = 'h2;h3;h4;p';
109 config.allowedContent = true;
110 config.entities = false; // keep unicode
111 config.filebrowserImageUploadUrl = '/edit/page?output=ckescript';
112 config.uploadUrl = '/edit/page?output=ckjson';
113 config.image2_alignClasses = ['left', 'center', 'right'];
114 config.image2_disableResizer = true;
116 { name: 'Klein', element: 'small' },
117 { name: 'Zijkant', element: 'span', attributes: { 'class': 'right' } },
118 { name: 'Attributie', element: 'em', attributes: { 'class': 'right' } },
119 { name: 'Quote', element: 'q' },
120 { name: 'Gemarkeerd', element: 'span', styles: { 'background-color': 'Yellow' } },
122 { name: 'Kadertekst', element: 'aside' },
123 { name: 'Uitgelijnd', element: 'div', attributes: { 'class': 'right' } },
124 { name: 'Kolom', element: 'div', attributes: { 'class': 'col' } },
125 { name: 'Waarschuwing', element: 'div', attributes: { 'class': 'warn' } },
127 config.pasteFilter = pastefilter;
128 config.contentsCss = document.styleSheets[0].href;
130 ['Inlinesave', '-', 'Undo', 'Redo'],
131 ['Format', 'Styles'],
132 ['Bold', 'Italic', 'Link'],
133 ['BulletedList', 'NumberedList', 'Blockquote'],
134 ['Table', 'CreateDiv'],
135 ['Image', 'HorizontalRule', 'CreatePlaceholder'],
139 config.toolbarCanCollapse = true;
140 config.floatSpacePreferRight = true;
141 config.floatSpaceDockedOffsetY = 0;
142 config.title = false;
143 config.startupFocus = true;
145 config.disableObjectResizing = true;
146 document.execCommand('enableObjectResizing', false, false); // workaround in inline mode; ff bug?
149 window.onbeforeunload = function () {
150 if (editor.checkDirty()) {
151 return 'Pagina verlaten zonder wijzigingen op te slaan?'; // message ignored in modern browsers
156 CKEDITOR.disableAutoInline = true;
158 // add edit link to menu
159 var pagebody = document.getElementsByClassName('static')[0];
161 var editlink = document.querySelector('a[href="#edit"]');
163 editlink.onclick = function (e) {
164 editlink.style.fontWeight = 'bold';
166 editlink.onclick = undefined;
167 pagebody.setAttribute('contenteditable', true);
168 pagebody.querySelectorAll('[data-dyn]').forEach(function (el) {
169 let blockname = el.getAttribute('data-dyn');
174 el.outerHTML = '[[' + blockname + ']]';
176 CKEDITOR.inline(pagebody, { customConfig: '' });
177 document.body.className = 'edit';
180 if (window.location.hash == '#edit') {