最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to pass parameter in ckeditor custom plugin? - Stack Overflow

programmeradmin3浏览0评论

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', mand : pluginName });
      }
    }
);

in my customTag.js

( function(){

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

})();

Can anyone help me about this issue?

Thanks!

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', mand : pluginName });
      }
    }
);

in my customTag.js

( function(){

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

})();

Can anyone help me about this issue?

Thanks!

Share Improve this question asked Nov 12, 2013 at 23:04 FlyingCatFlyingCat 14.3k36 gold badges125 silver badges201 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 10

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);
     }
}

You can try to pass it via the localStorage :

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

and :

  • console(localStorage.id);
  • to get the value ofc it's : var id = JSON.parse(localStorage.id);

There isn't a way to do that out of the box at the moment, but you can try this patch from CKEditor and it might help achieve your goal:

http://dev.ckeditor./ticket/8749

发布评论

评论列表(0)

  1. 暂无评论