简体   繁体   English

需要有关将类添加到HTML编辑器元素的帮助

[英]Need help with adding Classes to HTML Editor Elements

I'm using a WYSIWYG Editor called CKEditor and its really awesome. 我正在使用名为CKEditor的WYSIWYG编辑器,它非常棒。 Inside the editor, whenever I add a new Heading/Text/DIV/Image/ anything else for that matter, I want it to stay attached with a class: 在编辑器中,每当我为此添加新的标题/文本/ DIV /图像/其他任何内容时,我希望它与类保持一致:

Like 喜欢

<h2 class="blah">Sample Text</h2>

<img src="/abc.png" class="blah1" />

Here's a reference link: http://docs.cksource.com/CKEditor_3.x/Developers_Guide 这是一个参考链接: http//docs.cksource.com/CKEditor_3.x/Developers_Guide

I'm not good with Javascript, if anyone can help me out, I would be really Grateful! 我不擅长Javascript,如果有人能帮助我,我会非常感激!

Thank you. 谢谢。

take a look at answers for this question . 看看这个问题的答案。

customize the dialogs during the define, add a "class" field and then set and get the contents in the setup and commit functions. 在定义期间自定义对话框,添加“类”字段,然后设置并获取设置和提交功能中的内容。

look at ckeditor/_samples/api_dialog.html for background on modifying dialogs. 有关修改对话框的背景,请参阅ckeditor / _samples / api_dialog.html。

for the Headings you'd have to look at modifying the commands. 对于标题,你必须看看修改命令。 Those don't have dialogs. 那些没有对话框。

There's probably a way to always apply the same class based on the particular tag in the "data processor". 可能有一种方法可以始终根据“数据处理器”中的特定标记应用相同的类。 Do you want to always set the same class everytime or allow the user to choose the class, that's important because it changes your options quite a bit. 您是否希望每次都设置相同的类或允许用户选择类,这很重要,因为它会更改您的选项。

For example, the following code will ensure that elements will have their "alt" attribute filled: 例如,以下代码将确保元素将填充其“alt”属性:

editor.dataProcessor.htmlFilter.addRules(
{
    elements :
    {
        img : function( element )
        {
            if ( !element.attributes.alt )
                element.attributes.alt = 'An image';
        }
    }
});

Read the Overview (http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Data_Processor) this example was taken from there. 阅读概述(http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Data_Processor)这个例子就是从那里获取的。

You can do the same for "class". 您可以为“课程”做同样的事情。 Take a look at the existing output, then either add "class" if it's missing or replace them if that's your intent. 看看现有的输出,然后添加“class”(如果它丢失)或替换它们,如果这是你的意图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM