简体   繁体   English

如何为ckeditor定义自己的列表样式?

[英]How to define own list styles for ckeditor?

Is there a way to define own list styles for ckeditor.有没有办法为ckeditor定义自己的列表样式。 I have found the plugin http://ckeditor.com/addon/liststyle but it lets me choose only things like circle or square.我找到了插件http://ckeditor.com/addon/liststyle但它让我只能选择圆形或方形之类的东西。

I want to define own css classes for ol or ul in my application that i can use.我想在我可以使用的应用程序中为 ol 或 ul 定义自己的 css 类。 For example a class to define more space between list elements.例如,在列表元素之间定义更多空间的类。 the users of the editor should pick the list class via a context menu like in the nice "liststyle" plugin.编辑器的用户应该通过上下文菜单选择列表类,就像在漂亮的“liststyle”插件中一样。

Is there a way to do this?有没有办法做到这一点?

I am dealing with CKEditor to add custom list styling to the liststyle plugin.我正在处理 CKEditor 以向liststyle插件添加自定义列表样式。

I added one new style (you can add more if you like) using the CSS class.我使用 CSS 类添加了一种新样式(如果您愿意,可以添加更多样式)。

Here's how: in liststyle.js (after de-obfuscating) I insert my .logo class:方法如下:在liststyle.js (去混淆后)我插入我的.logo类:

..........
function e(c,e){
    c.lang.liststyle.logo="My bullet"; // BBoyanov - adding 'My bullet' as title in dropdown list (in current language), otherwise it stay "empty" title
    var b=c.lang.liststyle;
........
style:"width:150px",
items:[[b.notset,""],[b.circle,"circle"],[b.disc,"disc"],[b.square,"square"], 
[b.logo,"logo"]],//BBoyanov - css class 'logo' as Bullet \,[b.logo,"logo"]\
........
commit:function(a){
  var b=this.getValue();b?a.setStyle("list-style-type",b):a.removeStyle("list-style-type");
  "logo"==b?a.setAttribute("class",'logo'):a.removeAttribute("class");//BBoyanv set 'logo' as CSS class
........
h={a:"lower-alpha",A:"upper-alpha",i:"lower-roman",I:"upper-roman", 
1:"decimal", disc:"disc", circle:"circle", square:"square",logo:"logo"};//BBoyanov \,logo:"logo"\
........

You define the CSS class in ckeditor.css (to be visualised in CKEditor) and in your own CSS file.您在ckeditor.css (在 CKEditor 中可视化)和您自己的 CSS 文件中定义 CSS 类。

If you prefer different titles for different languages, you must put translation in the corresponding language .js file of CKEditor.如果你喜欢不同语言的不同标题,你必须把translation放在CKEditor对应语言的.js文件中。

It worked for me.它对我有用。

However, probably this is injection because it takes over the allowedContent - need tests and confirmation.但是,这可能是注入,因为它接管了allowedContent - 需要测试和确认。

Confirmed the approach mentioned above works, I am using Drupal, Ckeditor List Style (plugin) and the Ckeditor List Style module (Drupal module).确认上述方法有效,我正在使用 Drupal、Ckeditor 列表样式(插件)和 Ckeditor 列表样式模块(Drupal 模块)。

I needed to make a change to the lang > en.js file to add the appropriate Title in instead of the function as the OP.我需要对 lang > en.js 文件进行更改以添加适当的标题而不是作为 OP 的函数。

    cute: 'Cute',

Once that was done, inside the liststyle.js file I updated the existing code to this:完成后,在 liststyle.js 文件中,我将现有代码更新为:

Existing code in liststyle.js file: liststyle.js 文件中的现有代码:

                    commit: function(element) {
                        var value = this.getValue();
                        if (value)
                            element.setStyle('list-style-type', value);
                        else
                            element.removeStyle('list-style-type');
                    }

New code:新代码:

                     commit: function(element) {
                        var value = this.getValue();
                        if (value) {
                            if (value == 'cute') {
                                element.setAttribute("class", 'cute');
                                element.removeStyle('list-style-type');
                            } else {
                                element.setStyle('list-style-type', value);
                            }
                        } else {
                            element.removeStyle('list-style-type');
                        }
                     }

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

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