CKEditor 自定义插件,用于从活动选项卡的下拉列表中插入值
我正在尝试编写一个 CKEditor 自定义插件,但需要一些帮助来确定如何从“活动”选项卡的下拉框中插入值。
我有 4 个选项卡,每个选项卡都有自己的下拉列表。当用户选择选项卡,然后在下拉列表中选择一个值,然后按“确定”按钮时,我希望将“活动选项卡”下拉列表的当前值插入到文档中。
下面的代码正在努力做到这一点,除了我必须对我想要从中获取信息的选项卡进行硬编码。请参阅“onOk”事件的 abbr.setText(dialog.getValueOf( 'tab1', 'tenant_dropdown' ) );
。我想要更像这样的东西: abbr.setText(dialog.getValueOf(activeTab, activeElement ) );
或类似的东西...我找不到这方面的文档...我是傻子吗?
我有什么想法可以做到这一点吗?感谢您的帮助。
这是我的插件代码:
CKEDITOR.plugins.add( 'rz_db',
{
requires : ['richcombo'], //, 'styles' ],
init : function( editor )
{
editor.addCommand( 'abbrDialog', new CKEDITOR.dialogCommand( 'abbrDialog' ) );
editor.ui.addButton( 'Rz Database Field',
{
label: 'Insert Rz Database Field',
command: 'abbrDialog',
icon: this.path + 'images/icon.png'
} );
CKEDITOR.dialog.add( 'abbrDialog', function ( editor )
{
var tenant_fields = []; //new Array();
tenant_fields[0]=["First Name", "$RZ{tenant_first_name}"];
tenant_fields[1]=["Last Name", "$RZ{tenant_first_name}"];
tenant_fields[2]=["Address", "$RZ{tenant_address}"];
return {
title : 'Rz Database Fields',
minWidth : 400,
minHeight : 200,
contents :
[
{
id : 'tab1',
label : 'Tenants',
elements :
[
{
id : 'tenant_dropdown',
type : 'select',
label : 'Select the field you want, then press the "OK" button to insert it into the document.',
'default':'',
items: tenant_fields,
onChange : function( api ) {
// this = CKEDITOR.ui.dialog.select
alert( 'Current value: ' + this.getValue() );
}
}
]
},
{
id : 'tab2',
label : 'Owners',
elements :
[
{
type : 'text',
id : 'id',
label : 'Id'
}
]
},
{
id : 'tab3',
label : 'Vendors',
elements :
[
{
type : 'text',
id : 'id',
label : 'Id'
}
]
},
{
id : 'tab4',
label : 'Other',
elements :
[
{
type : 'text',
id : 'id',
label : 'Id'
}
]
}
],
onOk : function()
{
var dialog = this;
var abbr = editor.document.createElement( 'rz_db' );
abbr.setText( dialog.getValueOf( 'tab1', 'tenant_dropdown' ) );
editor.insertElement( abbr );
}
};
} );
}
});
I have a CKEditor custom plugin I'm trying to write, but need some help figuring out how to insert the value from a dropdown box for the "active" tab.
I have 4 tabs, each has its own dropdown list. When the user selects the tab, then chooses a value in the dropdown list, and then presses the "OK" button, I want the current value of the "Active tab's" dropdown list to be inserted into the document.
The code below is working to do this, except I have to hard code the tab I want to get the information from. See: abbr.setText( dialog.getValueOf( 'tab1', 'tenant_dropdown' ) );
of the "onOk" event. I want something more like: abbr.setText( dialog.getValueOf( activeTab, activeElement ) );
or something like this...I couldn't find the documentation for this...am I daft?
Any ideas how I can accomplish this? Thanks for your help.
Heres my plugin code:
CKEDITOR.plugins.add( 'rz_db',
{
requires : ['richcombo'], //, 'styles' ],
init : function( editor )
{
editor.addCommand( 'abbrDialog', new CKEDITOR.dialogCommand( 'abbrDialog' ) );
editor.ui.addButton( 'Rz Database Field',
{
label: 'Insert Rz Database Field',
command: 'abbrDialog',
icon: this.path + 'images/icon.png'
} );
CKEDITOR.dialog.add( 'abbrDialog', function ( editor )
{
var tenant_fields = []; //new Array();
tenant_fields[0]=["First Name", "$RZ{tenant_first_name}"];
tenant_fields[1]=["Last Name", "$RZ{tenant_first_name}"];
tenant_fields[2]=["Address", "$RZ{tenant_address}"];
return {
title : 'Rz Database Fields',
minWidth : 400,
minHeight : 200,
contents :
[
{
id : 'tab1',
label : 'Tenants',
elements :
[
{
id : 'tenant_dropdown',
type : 'select',
label : 'Select the field you want, then press the "OK" button to insert it into the document.',
'default':'',
items: tenant_fields,
onChange : function( api ) {
// this = CKEDITOR.ui.dialog.select
alert( 'Current value: ' + this.getValue() );
}
}
]
},
{
id : 'tab2',
label : 'Owners',
elements :
[
{
type : 'text',
id : 'id',
label : 'Id'
}
]
},
{
id : 'tab3',
label : 'Vendors',
elements :
[
{
type : 'text',
id : 'id',
label : 'Id'
}
]
},
{
id : 'tab4',
label : 'Other',
elements :
[
{
type : 'text',
id : 'id',
label : 'Id'
}
]
}
],
onOk : function()
{
var dialog = this;
var abbr = editor.document.createElement( 'rz_db' );
abbr.setText( dialog.getValueOf( 'tab1', 'tenant_dropdown' ) );
editor.insertElement( abbr );
}
};
} );
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没关系...我找到了解决方法。如果我设置一个全局变量,然后在“onchange”事件期间分配该值,并在“onOk”事件中使用该全局变量,它就会得到我需要的东西。
never mind...I found a work around. If I set a global variable then assign the value during the "onchange" event and use the global variable in the "onOk" event it gets me what I needed.
我有同样的情况并找到以下解决方案 - 此方法 getContentElement 返回有关元素的完整数据,之后要获取字段值可以使用 getValue() 方法。
I've the same case and find following solution - this method getContentElement return whole data about the element, after that to get field value can use getValue() method.