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 ajaxpost = new XMLHttpRequest();
20 ajaxpost.open('POST', '/edit'+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)
26 alert('Foutcode '+ajaxpost.status+' bij opslaan: '+ajaxpost.responseText);
33 editor.ui.addButton( 'Inlinesave', {
34 command: 'inlinesave',
35 label: editor.lang.save.toolbar,
41 CKEDITOR.on('dialogDefinition', function (event) {
42 switch (event.data.name) {
44 // override initial attribute values
45 var infoTab = event.data.definition.getContents('info');
46 infoTab.get('txtWidth').default = '';
47 infoTab.get('txtBorder').default = '0';
48 infoTab.get('txtCellSpace').default = '';
49 infoTab.get('txtCellPad').default = '';
52 // remove unneeded widgets from the Link Info tab
53 var infotab = event.data.definition.getContents('info');
54 infotab.remove('linkType');
59 CKEDITOR.on('instanceCreated', function (event) {
60 var editor = event.editor;
61 var pastefilter = 'h2 h3 p ul ol li blockquote em i strong b; a[!href]; img[alt,!src]';
63 editor.on('paste', function (e) {
64 var html = e.data.dataValue;
65 if (!/<[^>]* style="/.test(html) && !/<font/.test(html)) return;
67 // force pasteFilter on contents containing styling attributes
68 var filter = new CKEDITOR.filter(pastefilter),
69 fragment = CKEDITOR.htmlParser.fragment.fromHtml(html),
70 writer = new CKEDITOR.htmlParser.basicWriter();
71 filter.applyTo(fragment);
72 fragment.writeHtml(writer);
73 e.data.dataValue = writer.getHtml();
76 editor.on('configLoaded', function () {
77 var config = editor.config;
78 config.language = 'nl';
79 config.extraPlugins = 'sourcedialog,inlinesave,placeholder,image2,uploadimage';
80 config.format_tags = 'h2;h3;h4;p';
81 config.allowedContent = true;
82 config.entities = false; // keep unicode
83 config.filebrowserImageUploadUrl = '/edit?output=ckescript';
84 config.uploadUrl = '/edit?output=ckjson';
85 config.image2_alignClasses = ['left', 'center', 'right'];
86 config.image2_disableResizer = true;
88 { name: 'Kolom', element: 'div', attributes: { 'class': 'col' } },
89 { name: 'Rechts', element: 'div', attributes: { 'class': 'right' } },
91 config.pasteFilter = pastefilter;
92 config.contentsCss = document.styleSheets[0].href;
94 ['Inlinesave', '-', 'Undo', 'Redo'],
95 ['Format', 'BulletedList', 'NumberedList', 'CreateDiv', 'Table', 'Blockquote'],
96 ['HorizontalRule', 'CreatePlaceholder', 'Image'],
97 ['Bold', 'Italic', 'Link'],
100 config.toolbarCanCollapse = true;
101 config.floatSpacePreferRight = true;
102 config.floatSpaceDockedOffsetY = 0;
103 config.startupFocus = true;
105 config.disableObjectResizing = true;
106 document.execCommand('enableObjectResizing', false, false); // workaround in inline mode; ff bug?
109 window.onbeforeunload = function () {
110 if (editor.checkDirty()) {
111 return 'Pagina verlaten zonder wijzigingen op te slaan?'; // message ignored in modern browsers
116 CKEDITOR.disableAutoInline = true;
118 // add edit link to menu
119 var pagebody = document.getElementsByClassName('static')[0];
121 var editlink = document.querySelector('a[href="#edit"]');
123 editlink.onclick = function (e) {
124 editlink.style.fontWeight = 'bold';
126 editlink.onclick = undefined;
127 pagebody.setAttribute('contenteditable', true);
128 pagebody.innerHTML = pagebody.innerHTML
129 .replace(/<!--BLOCK:([^-]*)-->[^]*?<!--\/-->/g, '$1');
130 CKEDITOR.inline(pagebody);
131 document.body.className = 'edit';
134 if (window.location.hash == '#edit') {