Sign up for callbacks in the plugin for redactor.js

I want to create a plugin for the redactor.js WYSIWYG editor, but I cannot find a way to subscribe to redactor callbacks from my plugin. I need to use keydownCallback and autosaveCallback .

 RedactorPlugins.myPlugin = { init: function() { //Code } } 
+6
source share
2 answers

I really went with a plugin definition and using callback to call it; this allows you to call several functions / plugins from a callback and also looks like the intended approach.

Plugin:

 RedactorPlugins.advanced = { your_method: function() { // Add code here… } } 

your_method() now available on the redactor object and is simply called through below:

Editor's call:

 $('#redactor').redactor({ keydownCallback: function() { this.your_method(); // Additional keyDownCallbacks: this.another_method(); this.yet_another_method(); } }); 

Original answer:

I know his lateness, but this evening I met this myself.

This worked for me:

 RedactorPlugins.advanced = { init: function() { this.opts.keydownCallback = function(e) { // Add code here… } } } 

It simply calls the parameters and adds keyDownCallback . The only problem is that it can be added with only one plugin (since the last one on the called always overwrites the previous one).

+4
source

Great idea with this.opts in the original roj answer. It should be possible to save the old callback function as follows:

 RedactorPlugins.advanced = { init: function() { var oldKeydownCallback = this.opts.keydownCallback; this.opts.keydownCallback = function(e) { // Add code here… if (oldKeydownCallback) oldKeydownCallback(); } } } 

Explanation: The reference to the old callback will be stored in oldKeydownCallback, which is then included in the closure and available in your own callback, so you can simply call it as soon as your callback function completes its own code.

+2
source

Source: https://habr.com/ru/post/950592/


All Articles