Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass parameter in 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 anyone help me about this issue?

Thanks!

like image 433
FlyingCat Avatar asked Nov 12 '13 23:11

FlyingCat


1 Answers

Since the CKEditor is just an object you could just define your own property in the config of the editor and grab it in the plugin since the editor is being 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);
     }
}
like image 97
Xildatin Avatar answered Oct 02 '22 10:10

Xildatin