gpt4 book ai didi

javascript - 将对话框字段值设置为选定文本

转载 作者:行者123 更新时间:2023-11-30 17:52:09 26 4
gpt4 key购买 nike

我想编写 CKEditor 插件。我在面板上添加了按钮,当我按下它时会显示对话框。在此对话框中,我可以设置文本,然后在确定后按下将此文本插入到编辑器中。

但我想添加功能。当我在编辑器中选择文本并按下此按钮时,我想在该对话框字段中看到选定的文本。编辑并按确定后,所选文本必须替换为新文本。

谢谢!

最佳答案

这不是 100% 有效,第一部分是有效的,最后的替换不是..

CKEDITOR.plugins.add( 'example',
{
init: function( editor )
{
editor.addCommand( 'exampleDialog', new CKEDITOR.dialogCommand( 'exampleDialog' ) );

editor.ui.addButton( 'example',
{
label: 'Insert a Link',
command: 'exampleDialog'//,
//icon: this.path + 'images/icon.png'
} );

CKEDITOR.dialog.add( 'exampleDialog', function( editor )
{
return {
title : 'example Properties',
minWidth : 400,
minHeight : 200,
contents :
[
{
id : 'general',
label : 'Settings',
elements :
[
{
type : 'text',
id : 'mystring',
label : 'text',
commit : function( data )
{
data.text = this.getValue();
}
}
]
}
],

onShow : function() {
//this._ranges = editor.getSelection().getRanges()
var mySelection = editor.getSelection().getSelectedText();
this.setValueOf("general","mystring",mySelection);

},

onOk : function()
{
var data = {};
this.commitContent( data );
var txt = data.text;


editor.insertText(txt); //this is not correct, since selection is being cleared...
}
};
});
}
});

关于javascript - 将对话框字段值设置为选定文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18770697/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com