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