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.get('txtWidth').default = '';
56 infoTab.get('txtBorder').default = '0';
57 infoTab.get('txtCellSpace').default = '';
58 infoTab.get('txtCellPad').default = '';
61 //TODO: remove unneeded widgets from the Link Info tab
62 var infotab = event.data.definition.getContents('info');
67 CKEDITOR.on('instanceCreated', function (event) {
68 var editor = event.editor;
69 var pastefilter = 'h2 h3 p ul ol li blockquote em i strong b; a[!href]; img[alt,!src]';
71 editor.on('paste', function (e) {
72 var html = e.data.dataValue;
73 if (!/<[^>]* style="/.test(html) && !/<font/.test(html)) return;
75 // force pasteFilter on contents containing styling attributes
76 var filter = new CKEDITOR.filter(pastefilter),
77 fragment = CKEDITOR.htmlParser.fragment.fromHtml(html),
78 writer = new CKEDITOR.htmlParser.basicWriter();
79 filter.applyTo(fragment);
80 fragment.writeHtml(writer);
81 e.data.dataValue = writer.getHtml();
84 editor.on('configLoaded', function () {
85 var config = editor.config;
86 config.language = 'nl';
87 config.extraPlugins = 'inlinesave,placeholder,image2,uploadimage';
88 config.format_tags = 'h2;h3;h4;p';
89 config.allowedContent = true;
90 config.entities = false; // keep unicode
91 config.filebrowserImageUploadUrl = '/edit/page?output=ckescript';
92 config.uploadUrl = '/edit/page?output=ckjson';
93 config.image2_alignClasses = ['left', 'center', 'right'];
94 config.image2_disableResizer = true;
96 { name: 'Kolom', element: 'div', attributes: { 'class': 'col' } },
97 { name: 'Rechts', element: 'div', attributes: { 'class': 'right' } },
99 config.pasteFilter = pastefilter;
100 config.contentsCss = document.styleSheets[0].href;
102 ['Inlinesave', '-', 'Undo', 'Redo'],
104 ['Bold', 'Italic', 'Link'],
105 ['BulletedList', 'NumberedList', 'Blockquote'],
106 ['Table', 'CreateDiv'],
107 ['Image', 'HorizontalRule', 'CreatePlaceholder'],
111 config.toolbarCanCollapse = true;
112 config.floatSpacePreferRight = true;
113 config.floatSpaceDockedOffsetY = 0;
114 config.startupFocus = true;
116 config.disableObjectResizing = true;
117 document.execCommand('enableObjectResizing', false, false); // workaround in inline mode; ff bug?
120 window.onbeforeunload = function () {
121 if (editor.checkDirty()) {
122 return 'Pagina verlaten zonder wijzigingen op te slaan?'; // message ignored in modern browsers
127 CKEDITOR.disableAutoInline = true;
129 // add edit link to menu
130 var pagebody = document.getElementsByClassName('static')[0];
132 var editlink = document.querySelector('a[href="#edit"]');
134 editlink.onclick = function (e) {
135 editlink.style.fontWeight = 'bold';
137 editlink.onclick = undefined;
138 pagebody.setAttribute('contenteditable', true);
139 pagebody.innerHTML = pagebody.innerHTML
140 .replace(/<!--BLOCK:(.*?)-->[^]*?<!--\/-->/g, '$1');
141 CKEDITOR.inline(pagebody, { customConfig: '' });
142 document.body.className = 'edit';
145 if (window.location.hash == '#edit') {