CKEditor格式类
我正在编写一个 CKEditor 插件来将特定的类应用于元素。基本上这个班 正在将文本颜色设置为特定的红色。
不管怎样,我不知道如何为包装文本定义一个类。
请查看我的插件代码:
CKEDITOR.plugins.add( 'red',
{
init: function( editor )
{
editor.addCommand( 'red',
{
exec : function( editor )
{
var format = {
element : 'span'
};
var style = new CKEDITOR.style(format);
style.apply(editor.document);
}
});
editor.ui.addButton( 'red',
{
label: 'red',
command: 'red',
icon: this.path + 'images/red.png'
} );
}
} );
基本上我想要一个类似的输出:
<span class="red">This is now a red text</span>
非常感谢您提前帮助我。
我到目前为止所使用的资源: http://docs.cksource.com/CKEditor_3.x/Howto http://docs.cksource.com/CKEditor_3.x/Tutorials/Timestamp_Plugin http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.command .html#exec
也许我读过了那里的一些东西,但对我来说,那里似乎没有提到这种事情?请证明我错了:)
I am writing a CKEditor plugin to apply a specific class to an element. Basically this class
is setting the text colour to a specific redish colour.
Anyways, I am not getting how to define a class for the wrapped text.
Please look at my plugin code:
CKEDITOR.plugins.add( 'red',
{
init: function( editor )
{
editor.addCommand( 'red',
{
exec : function( editor )
{
var format = {
element : 'span'
};
var style = new CKEDITOR.style(format);
style.apply(editor.document);
}
});
editor.ui.addButton( 'red',
{
label: 'red',
command: 'red',
icon: this.path + 'images/red.png'
} );
}
} );
Basically I want to have an output like:
<span class="red">This is now a red text</span>
Thank you very much in advance for helping me.
The sources I have used to get this far:
http://docs.cksource.com/CKEditor_3.x/Howto
http://docs.cksource.com/CKEditor_3.x/Tutorials/Timestamp_Plugin
http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.command.html#exec
Maybe I overread something there, but for me it does not seem that this kind of things are mentioned there ? Please proof me wrong : )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用“basicstyles”插件作为模板,它创建各种样式按钮(粗体、斜体等):
ckeditor/_source/plugins/basicstyles/plugin.js
这是您的插件的代码(基于 basicstyles 插件),它将是位于此处的 plugin.js 文件的内容:
ckeditor/plugins/red/plugin.js
按钮的图标位于此处:
ckeditor/plugins/red/images
除了常规样式表之外,还将“red”类的样式添加到 ckeditorcontents.css 文件中(除非您将常规表作为自定义 css 文件加载到 ckeditor 中)。
在配置文件中添加新插件:
并将按钮添加到工具栏
'Red'
对于标签,您可以创建一个数组,其中分配给每种语言代码的不同标签,并根据活动语言代码。使用
editor.langCode
获取活动语言代码。如果您想避免添加按钮,可以向“格式”选择器添加一个新条目。它是带有标题的选择器。
祝你好运,
乔
You can use the the "basicstyles" plugin as a template, it creates the various style buttons (bold, italic, etc):
ckeditor/_source/plugins/basicstyles/plugin.js
Here's the code for your plugin (based on the basicstyles plugin), it would be the contents of the plugin.js file located here:
ckeditor/plugins/red/plugin.js
The icon for the button would be located here:
ckeditor/plugins/red/images
Add the style for the "red" class to the ckeditor contents.css file in addition to your regular style sheet (unless you load the regular sheet as a custom css file in ckeditor).
Add the new plugin in your config file:
And add the button to your toolbar
'Red'
For the label, you could create an array with different labels assigned to each language code and pull the correct version based on the active language code. Use
editor.langCode
to get the active language code.If you'd like to avoid adding a button, you could add a new entry to the "Format" Selector instead. It's the selector with the headings.
Be Well,
Joe