Thanks again, @mflorea!
I will consider that, if all else fails.
Currently I still don’t want to give up on the client side solution.
From my understanding of the documentation of the paste event it is meant to be used for processing the data. So if I throw away attributes in the listener they should no longer be available OR considered. Correct?
What I observe is that even if I process data in this event xwiki seems to be able to work on the original pasted data or at least retrieve the data.
If I add breakpoints to my paste handler and the toDataFormat function I see that my paste handler gets called first. The call stack at first glance does not show any signs of xwiki code being called. Still in this line var a = CKEDITOR.tools.escapeComment(b.attributes["data-reference"])
the attribute data-reference
has a value although I remove it in the paste handler.
This holds true regardless if the priority of the pastehandler is 2, 10 (default AFAIK) or 100.
From my understanding there are two possibilities:
- I’m doing something badly wrong (please find my current code below).
- The paste event handler does not work as expected in xwiki and it’s usage should be discouraged. I could not find anything in the documentation about this, so it may need to be updated.
Current code of my paste handler:
require(['deferred!ckeditor'], function(ckeditorPromise) {
ckeditorPromise.done(function(ckeditor) {
ckeditor.on('instanceCreated', function(event) {
event.editor.on('paste', function(evt){
console.log(evt.data.dataValue);
var fragment = CKEDITOR.htmlParser.fragment.fromHtml(evt.data.dataValue);
count=0;
fragment.forEach(function(node){
if(node.name!=null && node.name=="img"){
console.log(node);
console.log(node.attributes);
console.log("contains data-reference: " + node.attributes["data-reference"])
if(node.attributes["data-reference"]){
delete node.attributes["data-reference"];
count++;
}
}
}, CKEDITOR.NODE_ELEMENT, true);
if(count>0){
if(confirm("Update image references?")){
var writer = new CKEDITOR.htmlParser.basicWriter();
fragment.writeHtml( writer );
var writtenHTML=writer.getHtml();
console.log(writtenHTML);
evt.data.dataValue = writtenHTML;
}
}
},null,null, 100);
});
});
});