How to pass parameter to ckeditor custom plugin?

I am trying to pass a variable from my plugin.js script to my customTag.js script.

I have the following:

plugin.js

//I want to pass id from my plugin.js to my customTag.js
CKEDITOR.plugins.add('customTag',
    {
      init : function(editor){
          var pluginName = 'customTag';
          var id = editor.config.id;
          CKEDITOR.dialog.add(pluginName, this.path + 'dialogs/customTag.js');
          editor.addCommand(pluginName, new CKEDITOR.dialogCommand(pluginName));
          editor.ui.addButton('customTag', { label : 'customTag', command : pluginName });
      }
    }
);

in my customTag.js

( function(){

  codes...
  console(id) // gives me error.  

})();

Can someone help me on this?

Thanks!

+4
source share
3 answers

Since CKEditor is just an object, you can simply define your own property in the editor configuration and capture it in the plugin, because the editor is passed to the init function.

CKEDITOR.replace('mytextarea', {
    customValues: { name: 'myname' },
    extraPlugins: 'myplugin'
}

and then in the plugin:

CKEDITOR.plugins.add('myplugin',
{
    init: function (editor) {
        console.log(editor.config.customValues.name);
     }
}
+5
source

You can try passing it through localStorage:

  • localStorage.id = JSON.stringify(id);

and:

  • console(localStorage.id);
  • to get the value of c: var id = JSON.parse(localStorage.id);
+1
source

All Articles