I have the following code but datafilter code seems never to be triggered, the html filter works fine though
CKEDITOR.on('instanceReady', function (ev) {
var dataProcessor = ev.editor.dataProcessor;
var dataFilter = dataProcessor.dataFilter;
var htmlFilter = dataProcessor.htmlFilter;
htmlFilter.addRules({
elements:
{
a: function (element) {
alert('hello');
},
p: function (element) {
alert('hello');
}
}
});
dataFilter.addRules({
elements:
{
a: function (element) {
alert('hello');
}
}
});
});
Re: why does datafilter not work on instanceready
I used the html & data filter section from the placeholder plugin
looks like this in my case:
afterInit: function (editor) { var dataProcessor = editor.dataProcessor, dataFilter = dataProcessor && dataProcessor.dataFilter, htmlFilter = dataProcessor && dataProcessor.htmlFilter; // This rewrites incoming (GET, viewing) data if (dataFilter) { dataFilter.addRules( { text: function (text) { return text.replace(placeholderReplaceRegex, function (match) { return CKEDITOR.plugins.placeholder.createPlaceholder(editor, null, match, 1); }); }, attributes: { // rewrite <idt:templatefield attribs here }, elements: { 'idt:templatefield': function (element) { if (element.attributes && element.attributes['label']) { element.attributes['style'] = templateBGcss; element.attributes['contenteditable'] = 'false'; element.innerHTML = element.attributes['label']; alert(element.tagname); return element; //return CKEDITOR.plugins.placeholder.addFieldFromExisting(editor, element); } }, 'a': function (element) { if (element.attributes && element.attributes['idt:dynamiclink']) { element.attributes['style'] = templateBGcss; element.attributes['contenteditable'] = 'false'; return element; } } } }); } // This strips outgoing HTML (saving) if (htmlFilter) { htmlFilter.addRules( { elements: { 'span': function (element) { if (element.attributes && element.attributes['data-cke-placeholder']) delete element.name; } // don't show templatefields in Source Editor /* 'idt:templatefield': function (element) { if (element.attributes && element.attributes['expression']) delete element; }*/ } }); } }hope that helps, if not, look at the placeholder for a good example of dataprocessing