Javascript 将对话框字段值设置为选定文本
我想编码CKEditor插件。我已经在面板上添加了按钮,当我按下它时,会显示对话框。在该对话框中,我可以设置文本,并在按下OK键后将文本插入编辑器 但我想增加功能。当我在编辑器中选择文本并按下此按钮时,我希望在该对话框字段中看到所选文本。编辑并按“确定”后,所选文本必须替换为新文本Javascript 将对话框字段值设置为选定文本,javascript,jquery,dialog,ckeditor,Javascript,Jquery,Dialog,Ckeditor,我想编码CKEditor插件。我已经在面板上添加了按钮,当我按下它时,会显示对话框。在该对话框中,我可以设置文本,并在按下OK键后将文本插入编辑器 但我想增加功能。当我在编辑器中选择文本并按下此按钮时,我希望在该对话框字段中看到所选文本。编辑并按“确定”后,所选文本必须替换为新文本 谢谢 这不是100%有效,第一部分有效,最后的更换无效 CKEDITOR.plugins.add( 'example', { init: function( editor ) { ed
谢谢 这不是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...
}
};
});
}
});
这不是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...
}
};
});
}
});
我的解决方案是简单地将其设置在onShow函数中:
onShow: function () {
this.setValueOf('my-tab-id', 'my-element-id', editor.getSelection().getSelectedText());
// ...
},
完整代码框架:
(function () {
CKEDITOR.dialog.add('mySelectorDialog', function (editor) {
return {
contents: [
{
id: 'my-tab-id',
label: 'My Tab Label',
elements: [
{
id: 'my-element-id',
type: 'text',
label: 'My Element Label'
}
// ...
]
}
],
onShow: function () {
this.setValueOf('my-tab-id', 'my-element-id', editor.getSelection().getSelectedText());
// ...
},
onOk: function () {
// ...
}
// ...
};
});
})();
我的解决方案是简单地将其设置在onShow函数中:
onShow: function () {
this.setValueOf('my-tab-id', 'my-element-id', editor.getSelection().getSelectedText());
// ...
},
完整代码框架:
(function () {
CKEDITOR.dialog.add('mySelectorDialog', function (editor) {
return {
contents: [
{
id: 'my-tab-id',
label: 'My Tab Label',
elements: [
{
id: 'my-element-id',
type: 'text',
label: 'My Element Label'
}
// ...
]
}
],
onShow: function () {
this.setValueOf('my-tab-id', 'my-element-id', editor.getSelection().getSelectedText());
// ...
},
onOk: function () {
// ...
}
// ...
};
});
})();
酷,我会写一个基本的对话,几分钟后回来。酷,我会写一个基本的对话,几分钟后回来。谢谢,很好!也许您知道如何在dialog中使用语言变量来支持多种语言?您设置语言文件了吗?它可能是这样的:
editor.lang.example.title
谢谢,很好用!也许您知道如何在dialog中使用语言变量来支持多种语言?您设置语言文件了吗?它类似于:editor.lang.example.title