[英]How do I add styles using CKEditor Custom drop down plugin
因此,我添加了此插件,该插件为我提供了在CKeditor工具栏上具有下拉菜单的代码,该菜单包含单击时可应用的所有样式。 看到代码:
CKEDITOR.plugins.add( 'tokens',
{
requires : ['richcombo'], //, 'styles' ],
init : function( editor )
{
var config = editor.config,
lang = editor.lang.format;
// Gets the list of tags from the settings.
var tags = []; //new Array();
//this.add('value', 'drop_text', 'drop_label');
tags[0]=["[contact_name]", "Name", "Name"];
tags[1]=["[contact_email]", "email", "email"];
tags[2]=["[contact_user_name]", "User name", "User name"];
// Create style objects for all defined styles.
editor.ui.addRichCombo( 'tokens',
{
label : "Insert tokens",
title :"Insert tokens",
voiceLabel : "Insert tokens",
className : 'cke_format',
multiSelect : false,
panel :
{
css : [ config.contentsCss, CKEDITOR.getUrl( editor.skinPath + 'editor.css' ) ],
voiceLabel : lang.panelVoiceLabel
},
init : function()
{
this.startGroup( "Tokens" );
//this.add('value', 'drop_text', 'drop_label');
for (var this_tag in tags){
this.add(tags[this_tag][0], tags[this_tag][1], tags[this_tag][2]);
}
},
onClick : function( value )
{
editor.focus();
editor.fire( 'saveSnapshot' );
editor.insertHtml(value);
editor.fire( 'saveSnapshot' );
}
});
}
});
因此,此代码的作用是仅在标签[“ [contact_name”]中插入任何内容,因此,当您在下拉列表中单击“名称”时,它只会在文本编辑器中删除[contact_name]。 我想知道如何使每个标签具有特定功能,从而将css添加到在文本编辑器中选择的内容。 例如,有一个名为“红色字体”的函数,无论存在什么<p>字体,它都会变成红色。
CKEDITOR.replace( 'editorId', {
extraPlugins: 'tokens'
});
添加此代码,然后用您的编辑器ID替换编辑器ID。 而已。
CKEDITOR.replace( 'editor', {
extraPlugins: 'tokens' // why tokens see below
});
因为你给了
CKEDITOR.plugins.add( 'tokens',
{
requires : ['richcombo']
..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.