Extending kupu's initialization with a Javascript wrapper decorator
In particular, I was trying to adjust the default kupu configuration without overriding kupuploneinit.js to add commands directly to the initPloneKupu method. Here's the snippet that got me there:
var augmentKupuInit = function(orig_fn) {
return function(){
var editor = orig_fn.apply(this, arguments);
// do what you need to on the editor object here.
// For example, I was trying to prevent kupu from
// filtering the 'fb:fan' tag of Facebook's "Fan Box"
// widget, like so:
editor.xhtmlvalid.tagAttributes['fb:fan'] = ['*'];
return editor;
};
};
initPloneKupu = augmentKupuInit(initPloneKupu);This defines a decorator function called augmentKupuInit that can be used to wrap another function. Then it uses it to wrap the original initPloneKupu method, calling the newly generated function initPloneKupu. As long as this snippet is registered in such a way that it loads after kupuploneinit.js and before the initPloneKupu method is called, it works like a charm!
(Many thanks to http://stackoverflow.com/questions/326596/how-do-i-wrap-a-function-in-javascript, which finally pointed me in the right direction.)
Anonymous on Extending kupu's initialization with a Javascript wrapper decorator