- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
如果我在 CKEDITOR-textarea 中编辑一个链接,光标总是跳到顶部,在内容的第一个字母之前。此问题仅出现在 IE 中,但仅出现在我的页面上。如果我转到 CKEDITOR-demopage,它会按要求工作。
我一直在寻找类似的问题,但没有找到任何东西。有人知道这个的解决方案吗?
编辑:我发现了问题:我有一个自定义插件来更改我的链接,这个插件使用 element.setValue()
来替换链接的值,这个函数会跳转到顶部。我也尝试过 setHtml() 和 setText(),但这是同样的问题。
编辑 2:忘记添加我的代码:plugin.js
CKEDITOR.plugins.add('previewLink', {
icons: 'previewLink',
init: function(editor){
editor.addCommand('previewLinkDialog', new CKEDITOR.dialogCommand('previewLinkDialog'));
editor.ui.addButton('previewLink', {
label: 'Preview Link einfügen',
command: 'previewLinkDialog',
toolbar: 'insert'
});
CKEDITOR.dialog.add('previewLinkDialog', this.path + 'dialogs/previewLink.js');
editor.on('doubleclick', function(evt){
var element = evt.data.element;
if(!element.isReadOnly()){
if(element.is('a')){
editor.openDialog('previewLinkDialog');
}
}
});
}
});
dialogs/previewLink.js
CKEDITOR.dialog.add('previewLinkDialog', function(editor){
return {
title: 'Preview Link einfügen',
minWidth: 400,
minHeight: 200,
contents: [
{
id: 'tab-basic',
label: 'Basic Settings',
elements: [
{
type: 'text',
id: 'text',
label: 'Text',
validate: CKEDITOR.dialog.validate.notEmpty("Bitte füllen Sie das Text-Feld aus"),
setup: function(element){
this.setValue(element.getText());
},
commit: function(element){
// The problem happens here
element.setText(this.getValue());
}
},
{
type: 'text',
id: 'link',
label: 'Link',
validate: CKEDITOR.dialog.validate.notEmpty("Bitte füllen Sie das Link-Feld aus"),
setup: function(element){
//this.setValue(element.getAttribute('data-cke-pa-onclick'));
this.setValue(element.getAttribute('data-cke-saved-href'));
},
commit: function(element){
//element.setAttribute('data-cke-pa-onclick', this.getValue());
element.setAttribute('data-cke-saved-href', this.getValue());
}
},
{
type : 'checkbox',
id : 'popup',
label : 'In Popup öffnen',
'default' : 'checked',
onclickString: "openPopUp(this.href, '', iScreen.windowWidth, iScreen.windowHeight, 0, 0, 0, 1, 1, 0, 0, 0, 0); return false;",
setup: function(element){
this.setValue(element.getAttribute('data-cke-pa-onclick') == this.onclickString);
},
commit: function(element){
if(this.getValue() === true){
var onclick = this.onclickString;
element.setAttribute('data-cke-pa-onclick', this.onclickString);
}
else {
element.removeAttribute('data-cke-pa-onclick');
}
}
}
]
}
],
onShow: function() {
var selection = editor.getSelection(),
element = selection.getStartElement();
if (element)
element = element.getAscendant('a', true);
if (!element || element.getName() != 'a' || element.data('cke-realelement')){
element = editor.document.createElement('a');
this.insertMode = true;
}
else
this.insertMode = false;
this.element = element;
if (!this.insertMode)
this.setupContent( this.element );
},
onOk: function() {
var dialog = this,
link = this.element;
this.commitContent(link);
if (this.insertMode)
editor.insertElement(link);
}
};
});
最佳答案
这个问题的原因是 setText
调用您正在删除保留选择的节点。作为回退,IE 会将选择移动到开头,这会导致您的编辑器滚动。
这里有几个选项。
在你的对话框提交函数中,确保选择被放置在你想要被选中的元素上。你可以用一行来完成。
commit: function(element){
// The problem happens here
element.setText(this.getValue());
editor.getSelection().selectElement( element );
}
请注意,尽管您最初的插入符位置,但它始终会更改为选择整个链接。不过,这是我推荐的解决方案,因为它很简单。
如果精确的插入符号位置对您来说至关重要,那么您可以在修改 DOM 之前使用书签来存储所选内容的“快照”,以便稍后恢复。
在这种特殊情况下,您需要使用 bookmark2
API(标准书签会被 DOM 操作删除)。
commit: function(element){
// The problem happens here.
var sel = editor.getSelection(),
// Create a bookmark of selection before node modification.
bookmark = sel.getRanges().createBookmarks2( false ),
rng;
// Update element inner text.
element.setText(this.getValue());
try {
// Attempt to restore the bookmark.
sel.selectBookmarks( bookmark );
} catch ( e ) {
// It might fail in case when we had sth like: "<a>foo bar ^baz<a>" and the new node text is shorter than the former
// caret offset, it will throw IndexSizeError in this case. If so we want to
// manually put it at the end of the string.
if ( e.name == 'IndexSizeError' ) {
rng = editor.createRange();
rng.setStartAt( element, CKEDITOR.POSITION_BEFORE_END );
rng.setEndAt( element, CKEDITOR.POSITION_BEFORE_END );
sel.selectRanges( [ rng ] );
}
}
}
关于javascript - CKEDITOR 编辑链接后跳到顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34988256/
我正在构建一个使用 javascript 向页面动态添加元素的 Web 应用程序,然后可以使用 contentEditable="true" 对其进行编辑和 CKEditor . 目前,如果我使用 c
目前我遇到以下问题,我正在使用 CKEDITOR 4.x 中的 applyStyle 方法应用 span 标签。但是当一个跨度被部分选中并且我执行 applyStyle 方法时,一个新的跨度将被选择,
我在内联模式下使用CKEDITOR,每页有多个编辑器。为了创建它们,我使用 HTML 中的标签,然后运行执行 CKEDITOR.inline() 的脚本网页加载后立即针对它们中的每一个进行操作。 只
如何在加载编辑器上设置文本方向 [rtl]? 最佳答案 根据文档,应该这样做: CKEDITOR.config.contentsLangDirection in the CKSource manual
在 CKEditor 中,我添加了自定义图像按钮,它直接触发文件输入。但是,只有在使用 Image 插件时才能渲染图像。 我不想在工具栏上有 2 个图像按钮,有没有办法隐藏图像按钮,但仍然使用它(如显
我有一个使用 CKeditor 的 Rails 4 应用程序。在开发模式下它工作正常,但在生产中 ckeditor 不会出现,并且文本区域的位置有一个空格。 根据日志,缺少以下文件: ActionCo
如何在选择图像时启用或禁用 CKEditor 的段落按钮。我不想完全删除它。我目前使用 ckeditor 版本 4.4 最佳答案 使用editor.getCommand() + CKEDITOR.co
我在内联模式下使用CKEDITOR,每页有多个编辑器。为了创建它们,我使用 HTML 中的标签,然后运行执行 CKEDITOR.inline() 的脚本网页加载后立即针对它们中的每一个进行操作。 只
乍一看,我需要做一件简单的事情——在 CKEditor 中添加一个带有行号的栏。主要思想是作者在讨论文本时可以引用特定段落。 我试图找到一个插件,试图找到另一个带有行号的 WYSIWYG 编辑器,但没
在 CKEditor 中,我添加了自定义图像按钮,它直接触发文件输入。但是,只有在使用 Image 插件时才能渲染图像。 我不想在工具栏上有 2 个图像按钮,有没有办法隐藏图像按钮,但仍然使用它(如显
我试图修改this repo 来自定义我想在我的 Strapi 项目中使用的 CKEditor。我添加了更多插件,这就是我的 ckeditor.js 文件的样子: import ClassicEdit
当自定义 div 内部发生变化时是否会触发任何事件?我不想监听 editor.on('change'),而只是检测发生变化的 dom 元素, (删除或插入的字符)。例如: var template
我有一个像 ckeditor 一样的 textarea。 在编辑器中有一个按钮可以将内容查看为 source/html。 我在 textarea 上方有一个输入按钮,可以将 textarea 内容预览
我正在使用 2amigos ckeditor plugins在 yii2 中,我能够从 plugin_sdk_sample 创建一个示例插件,它在原始项目中工作正常,但是当我将其放入 yii2 项目时
我在我的应用程序中使用 CKEditor 5,供用户输入包含图像、媒体、表格和样式文本的文档。用户存储文档后,我会再次将其拉出进行显示。过去当我只有最通用的样式时,我会这样显示内容: 这是一个
有谁知道如何修改CKEditor右键单击上下文菜单? 我想弄清楚如何从右键单击菜单中删除“剪切、复制、粘贴、编辑 DIV”,并尝试向其中添加“插入图像、插入表格”。 最佳答案 3.6.1 版在其 AP
我一直在为此寻找解决方案有一段时间了,我发现的唯一修复只会影响文本在编辑器本身中的显示方式,而不影响生成的文本在发送/保存到其他地方时的外观。我说的是 CSS 修复之类的东西。 我正在使用 CKEdi
我需要动态更改 CKEditor 配置中的一个配置设置。 我正在编写一个插件,它将复选框添加到 CKEditor 工具栏并在选中/取消选中它时 - forcePasteAsPlainText 被更改为
如何动态更改 CKEditor 工具栏(不使用预定义的工具栏)? CKEditor Developer's Guide只告诉您如何在初始化期间设置工具栏。 我正在使用 CKEditor 3.6.4。
我使用 CKeditor 来编辑丰富的 HTML 页面,但是一些 javascript 功能依赖于 的特殊属性。触发它们的标签。 这些是极少数情况,只有 5000 多条记录的数据库中的几条记录需要触
我是一名优秀的程序员,十分优秀!