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 // 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 var ajaxpost = new XMLHttpRequest();
20 ajaxpost.open('POST', '/edit/page'+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) {
27 new CKEDITOR.plugins.notification(editor, {
28 message: 'Pagina is succesvol opgeslagen',
33 new CKEDITOR.plugins.notification(editor, {
34 message: 'Foutcode '+ajaxpost.status+' bij opslaan: '+ajaxpost.responseText,
42 editor.setKeystroke(CKEDITOR.CTRL + 83 /*S*/, 'inlinesave');
43 editor.ui.addButton( 'Inlinesave', {
44 command: 'inlinesave',
45 label: editor.lang.save.toolbar,
51 CKEDITOR.on('dialogDefinition', function (event) {
52 switch (event.data.name) {
54 // override initial attribute values
55 var infotab = event.data.definition.getContents('info');
56 infotab.remove('txtWidth');
57 infotab.remove('txtHeight');
58 infotab.remove('txtBorder');
59 infotab.remove('txtCellSpace');
60 infotab.remove('txtCellPad');
61 infotab.remove('cmbAlign');
63 // horizontal repositioning of existing elements
67 children: [ infotab.get('txtCols'), infotab.get('txtRows') ],
69 infotab.add(hbox, 'selHeaders');
70 infotab.remove('txtCols');
71 infotab.remove('txtRows');
75 // hide unneeded widgets from the Link Info tab
76 event.data.definition.getContents('info').get('linkType').hidden = true;
77 let linktarget = event.data.definition.getContents('target').get('linkTargetType');
78 linktarget.items = [ linktarget.items[0], linktarget.items[3] ]; // only _blank
83 CKEDITOR.on('instanceCreated', function (event) {
84 var editor = event.editor;
85 var pastefilter = 'h2 h3 p ul ol li blockquote em i strong b; a[!href]; img[alt,!src]';
87 editor.on('paste', function (e) {
88 var html = e.data.dataValue;
89 if (!/<[^>]* style="/.test(html) && !/<font/.test(html)) return;
91 // force pasteFilter on contents containing styling attributes
92 var filter = new CKEDITOR.filter(pastefilter),
93 fragment = CKEDITOR.htmlParser.fragment.fromHtml(html),
94 writer = new CKEDITOR.htmlParser.basicWriter();
95 filter.applyTo(fragment);
96 fragment.writeHtml(writer);
97 e.data.dataValue = writer.getHtml();
100 editor.on('configLoaded', function () {
101 var config = editor.config;
102 config.language = 'nl';
103 config.extraPlugins = 'inlinesave,placeholder,image2,uploadimage';
104 config.format_tags = 'h2;h3;h4;p';
105 config.allowedContent = true;
106 config.entities = false; // keep unicode
107 config.filebrowserImageUploadUrl = '/edit/page?output=ckescript';
108 config.uploadUrl = '/edit/page?output=ckjson';
109 config.image2_alignClasses = ['left', 'center', 'right'];
110 config.image2_disableResizer = true;
112 { name: 'Klein', element: 'small' },
113 { name: 'Zijkant', element: 'span', attributes: { 'class': 'right' } },
114 { name: 'Attributie', element: 'em', attributes: { 'class': 'right' } },
115 { name: 'Quote', element: 'q' },
116 { name: 'Gemarkeerd', element: 'span', styles: { 'background-color': 'Yellow' } },
118 { name: 'Kadertekst', element: 'aside' },
119 { name: 'Uitgelijnd', element: 'div', attributes: { 'class': 'right' } },
120 { name: 'Kolom', element: 'div', attributes: { 'class': 'col' } },
121 { name: 'Waarschuwing', element: 'div', attributes: { 'class': 'warn' } },
123 config.pasteFilter = pastefilter;
124 config.contentsCss = document.styleSheets[0].href;
126 ['Inlinesave', '-', 'Undo', 'Redo'],
127 ['Format', 'Styles'],
128 ['Bold', 'Italic', 'Link'],
129 ['BulletedList', 'NumberedList', 'Blockquote'],
130 ['Table', 'CreateDiv'],
131 ['Image', 'HorizontalRule', 'CreatePlaceholder'],
135 config.toolbarCanCollapse = true;
136 config.floatSpacePreferRight = true;
137 config.floatSpaceDockedOffsetY = 0;
138 config.title = false;
139 config.startupFocus = true;
141 config.disableObjectResizing = true;
142 document.execCommand('enableObjectResizing', false, false); // workaround in inline mode; ff bug?
145 window.onbeforeunload = function () {
146 if (editor.checkDirty()) {
147 return 'Pagina verlaten zonder wijzigingen op te slaan?'; // message ignored in modern browsers
152 CKEDITOR.disableAutoInline = true;
154 // add edit link to menu
155 var pagebody = document.getElementsByClassName('static')[0];
157 var editlink = document.querySelector('a[href="#edit"]');
159 editlink.onclick = function (e) {
160 editlink.style.fontWeight = 'bold';
162 editlink.onclick = undefined;
163 pagebody.setAttribute('contenteditable', true);
164 pagebody.innerHTML = pagebody.innerHTML
165 .replace(/<!--BLOCK:(.*?)-->[^]*?<!--\/-->/g, '$1');
166 CKEDITOR.inline(pagebody, { customConfig: '' });
167 document.body.className = 'edit';
170 if (window.location.hash == '#edit') {