2015-02-11 63 views
1

我试图通过使用插件placeholderstrinserthere所述实现固定的占位符ckeditor。ckeditor插件strinsert:如何设置初始化后的自定义字符串

不幸的是,我无法动态改变strings插件strinsert的数组。

此行config.js应该工作,但它并不:

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

也许这个插件不支持改变后初始化字符串数组?

我该怎么做才能在不克隆ligsert插件x次的情况下向不同的ckeditor实例中的用户显示不同的占位符?

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

+0

你找到一个解决方案尚未 – aggsol 2015-03-05 10:22:57

+0

我不再需要这个插件。它也仅适用于占位符 – toshniba 2015-03-16 07:35:29

回答

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