ckeditor plugin strinsert:初始化后如何设置自定义字符串

时间:2015-02-11 16:50:33

标签: ckeditor

我正在尝试使用placeholder所述的插件strinserthere来为ckeditor实现固定占位符。

很遗憾,我无法动态更改strings插件strinsert数组。

config.js中的这一行应该有效,但不是:

CKEDITOR.editorConfig = function( config ) {
    config.strinsert_strings = [
        ['[[foo]]']
    ];
};

也许这个插件不支持在init之后改变字符串数组?

如何在不克隆strinsert插件x次的情况下为不同的ckeditor实例中的用户提供不同的占位符?

注意:我正在使用所有这些版本的最新版本。

3 个答案:

答案 0 :(得分:1)

与建议一样,使用占位符rplugin。只需编辑文件ckedit/plugins/placeholder/dialogs/placeholder.js即可。将元素类型更改为select,并将所需值添加到items,如下例所示:

contents: [
            {
                id: 'info',
                label: generalLabel,
                title: generalLabel,
                elements: [
                    // Dialog window UI elements.
                    {
                        id: 'name',
                        type: 'select',
                        style: 'width: 100%;',
                        label: lang.name,
                        items:[
                            ['ONE'],
                            ['TWO'],
                            ['THREE']
                        ],
                        // SNIP...

答案 1 :(得分:0)

您可以使用dialogDefinition事件动态设置自定义占位符。 我是这样做的(html属性data-placeholders"placeholder1,different text to show=placeholder2,another text=placeholder3"

的形式指定有效占位符
  CKEDITOR.on ('dialogDefinition', function (e) {

    // Check if the definition is from the dialog window you are interested in (the "Link" dialog window).
    if (e.data.name == 'placeholder') {
      var $textarea = $(e.editor.element.$),
        placeholders = $textarea.attr("data-placeholders"),
        tab, ff, i, a;

      //placeholders = [['placeholder1'],['Text to show', 'placholdervalue']];
      if (placeholders && placeholders.length) {
        // convert placeholders from desc1=val1,desc2=val2,val3,... format to array(array(desc,val))
        placeholders = placeholders.split(",");
        // ensure placeholders is array of arrays with exact 2 members
        for (i = 0; i < placeholders.length; i++) {
          a = placeholders[i].split("=");
          if (a.length < 1) a[1] = a[0];
          placeholders[i] = a;
        }
        tab = e.data.definition.getContents ('info');

        // Set the default value for the URL field.
        ff = tab.get ('name');
        ff['type'] = 'select';
        ff['items'] = placeholders;
      }
    }
  });

答案 2 :(得分:0)

对于strinsert,我通过编辑它的plugin.js来完成工作,摆脱字符串声明并替换为:

var strings = editor.config.strinsert_strings;

然后在你的html中创建CKEDITOR之前:

CKEDITOR.config.strinsert_strings =  [];
CKEDITOR.config.strinsert_strings.push(['myvalue1', 'myname1', 'mylabel1']);
CKEDITOR.config.strinsert_strings.push(['myvalue2', 'myname2', 'mylabel2']);
CKEDITOR.replace('mytextarea');
相关问题