I want to create a plugin for the redactor.js WYSIWYG editor, but I cannot find the way to subscribe to redactor callbacks from my plugin. I need to use keydownCallback
and autosaveCallback
.
RedactorPlugins.myPlugin = {
init: function()
{
//Code
}
}
I actually went with defining the plugin & using the callback to call it; this allows for multiple functions/plugins to be called from the callback and also feels like the intended approach.
Plugin:
RedactorPlugins.advanced = {
your_method: function() {
// Add code here…
}
}
your_method()
is now available on the redactor object & simply callable through the below:
Redactor call:
$('#redactor').redactor({
keydownCallback: function() {
this.your_method();
// Additional keyDownCallbacks:
this.another_method();
this.yet_another_method();
}
});
Original answer:
I know it’s late but came across this my self this evening.
This worked for me:
RedactorPlugins.advanced = {
init: function() {
this.opts.keydownCallback = function(e) {
// Add code here…
}
}
}
It simply calls the options and adds the keyDownCallback
. The only trouble is it can only be added by one plugin (as the last on called always overwrites the previous).
Great idea with this.opts in roj's original answer. It should be possible to preserve the old callback function like this:
RedactorPlugins.advanced = {
init: function() {
var oldKeydownCallback = this.opts.keydownCallback;
this.opts.keydownCallback = function(e) {
// Add code here…
if (oldKeydownCallback)
oldKeydownCallback();
}
}
}
Explanation: Reference to the old callback will be preserved in oldKeydownCallback which is then included in the closure and available within your own callback, so you can just call it once your own callback function has finished executing its own code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With