简体   繁体   English

禁用CKEditor缩进插件

[英]disable CKEditor indentation plugin

I need to disable the indentation of ordered and unordered lists ( <ul> , <ol> ) in CKEditor (4.2 or 4.3) entirely, because i need to convert (a very limited subset of) HTML into another markup language which does not support indentation. 我需要完全禁用CKEditor(4.2或4.3)中有序和无序列表( <ul><ol> )的缩进,因为我需要将HTML的(非常有限的子集)转换成另一种不支持的标记语言缩进。

I've tried several approaches, but didn't have any luck: 我尝试了几种方法,但是没有运气:

Try 1: Remove plugin via configuration 尝试1:通过配置删除插件

config.removePlugins = 'indent,indentlist,indentblock';

I guess that is not working because these plugins seem to be required - you can't remove them when building a CKEditor package from the website. 我猜这是行不通的,因为似乎需要这些插件-在从网站构建CKEditor软件包时,您无法删除它们。

When viewing CKEDITOR.plugins via the FireBug console, those plugins are still there. 通过FireBug控制台查看CKEDITOR.plugins ,这些插件仍然存在。 There doesn't even exist an own plugin folder - seems they are builtin to the core. 甚至不存在自己的插件文件夹-似乎它们是内置的。

Try 2: Override TAB key 尝试2:覆盖TAB键

I created a new plugin disableTab that does entirely nothing (except return true; on execution). 我创建了一个新插件disableTab ,该插件完全不执行任何操作(执行时return true;除外)。

The plugin is registered as a handler for keystroke of the TAB key: 该插件已注册为TAB键击键的处理程序:

config.keystrokes = [
     [ 9, 'disableTab' ] // disable TAB key to avoid nesting!
];

Unfortunately, the plugin doesn't work when pressing tab on the first level of a list ( <li> or <ol> ). 不幸的是,在列表的第一级( <li><ol> )上按tab时,该插件不起作用。 Interestingly, it works when pressing TAB in the second level of a list ( ol > li > ol > li ), it does not produce more nested lists below the second level. 有趣的是,当在列表的第二级( ol > li > ol > li )中按TAB时,它可以工作,但在第二级以下不会产生更多的嵌套列表。 I know for sure my plugin is executed, because i inserted an alert() in my plugin for testing. 我知道我的插件已执行,因为我在我的插件中插入了alert()进行测试。 At least, this is what happens in my Firefox. 至少,这就是我的Firefox中发生的情况。

But i need to disable indentation entirely, not only above level > 2. 但是我需要完全禁用缩进,不仅限于> 2以上的级别。

Try 3: Block keystroke via blockedKeystrokes in editor configuration: 尝试3:在编辑器配置中通过blockedKeystrokes阻止按键:

Doesn't work, even though it should according to the documentation: 不起作用,即使它应该根据文档:

config.blockedKeystrokes = [ 9 ];

Try 4: Remove keystroke during runtime 尝试4:在运行时删除击键

According to the API documentation this code should disable the keystroke, but it doesn't work for some reason: 根据API文档,此代码应禁用按键,但是由于某些原因它不起作用:

for (instance in CKEDITOR.instances) {
    var editor = CKEDITOR.instances[instance];
    editor.setKeystroke(9, false);
}

Any idea how to remove the indentation of lists in CKEditor? 任何想法如何在CKEditor中删除列表的缩进?

I don't understand why none of these approaches work. 我不明白为什么这些方法都不起作用。 If you know why, please let me know. 如果您知道原因,请告诉我。

Update: 更新:

Interestingly, this code greets me for almost every key event, except pressing the TAB key: 有趣的是,除了按下TAB键外,几乎所有的按键事件都向我致意:

editor.on('key', function(e) { alert ("hi"); return false; });

So it seems my setup (LinuxMint 13 [Gnome 2] + Firefox 18 + CKEditor 4.2) does not fire the key event handler for the TAB key. 因此,看来我的设置(LinuxMint 13 [Gnome 2] + Firefox 18 + CKEditor 4.2)没有触发TAB键的键事件处理程序。 Maybe the indent plugin uses some other event? 也许缩进插件使用其他事件? Blur? 模糊?

Update 2: 更新2:

This is a Firefox (maybe linux only) issue. 这是Firefox(也许只有linux)的问题。 Several approaches work fine with Chrome or Internet Explorer. Chrome或Internet Explorer可以使用几种方法。

I just checked quickly and it looks like although indentlist is required by the list plugin, if you: 我只是快速检查了一下,尽管list插件需要indentlist list ,但是如果您:

0) Download CKEditor sources from http://github.com/ckeditor/ckeditor-dev 0)从http://github.com/ckeditor/ckeditor-dev下载CKEditor来源

1) Remove 1)移除

requires: 'indentlist',

from plugins/list/plugin.js 来自plugins/list/plugin.js

2) Remove 2)移除

indentlist: 1,  
indentblock: 1,

from dev/builder/build-config.js 来自dev/builder/build-config.js

3) Build release package with dev/builder/build.sh (on Windows use "Git Bash" shell) 3)使用dev/builder/build.sh构建发行包(在Windows上使用“ Git Bash” shell)

You will find in the dev/builder/release/ckeditor folder the release version that you need. 您将在dev/builder/release/ckeditor文件夹中找到所需的发行版本。

(it's rather uncommon that a required plugin is not really required, but it's uncommon as well that one do not need indentation for lists ;-) ) (并不真正需要一个必需的插件是很不常见的,但是不需要列表的缩进也很不常见;-))

try changing your code to: 尝试将您的代码更改为:

editor = CKEDITOR.replace( 'element_name' );

editor.on('key', function(e) {
var key = e.data.keyCode;      
if(key==9) {
return false;
}

that should work, just change 'element_name' to the textarea that you are replacing with ckeditor 那应该起作用,只需将“ element_name”更改为要用ckeditor替换的文本区域

The built-in indentlist plugin cancels the event bubbling when it is processed, so a standard event listener for the tab key isn't being fired. 内置的indentlist插件在处理事件时会取消事件冒泡,因此不会触发Tab键的标准事件侦听器。 If you prioritize your event to run first, you can capture the tab key event and stop it from indenting your lists. 如果您将事件的优先级设置为首先运行,则可以捕获Tab键事件并阻止其缩进列表。

Ex: 例如:

editor.on('key', function (evt) {
    if (editor.mode != 'wysiwyg') {
        return false;
    }

    if (evt.data.keyCode == this.indentKey || evt.data.keyCode == 9) {
        evt.cancel();
        return false;
    }
}, null, null, 1);

If you want to only block the indentation on numbered lists, you can add these conditionals: 如果只想限制编号列表上的缩进,则可以添加以下条件:

editor.on('key', function (evt) {
    var path = editor.elementPath();

    if (editor.mode != 'wysiwyg') {
        return false;
    }

    if (evt.data.keyCode == this.indentKey || evt.data.keyCode == 9 && path.contains('ol')) {
        evt.cancel();
        return false;
    }
}, null, null, 1);

The event priority is outlined in the documentation here: https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_event.html#method-on 在此处的文档中概述了事件优先级: https : //ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_event.html#method-on

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

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