Ckeditor 自定义插件 - 带单选按钮的对话框
Ckeditor custom plugin - dialog with radio buttons
我正在尝试在 CKEditor 中构建自定义插件,在其中选择单选按钮列表中的元素会更改所选元素的 class。示例:
选择 BIG
将添加 class big
、MEDIUM
=> med
和 SMALL
=> sml
.
我在必须检索所选元素的值的部分受阻。其他一切都很好,我在下面的代码中设法将 class "MYCLASS" 应用到最近的 li
标签。
问题 : 如何在 CKeditor 的 dialog
元素中获取所选单选按钮的值?
代码如下:
CKEDITOR.dialog.add( 'MyDialog', function ( editor ) {
function getListElement( editor, listTag ) {
var range;
try {
range = editor.getSelection().getRanges()[ 0 ];
} catch ( e ) {
return null;
}
range.shrink( CKEDITOR.SHRINK_TEXT );
return editor.elementPath( range.getCommonAncestor() ).contains( listTag, 1 );
}
return {
title: 'Size of the element',
minWidth: 400,
minHeight: 200,
contents: [
{
id: 'tab-basic',
label: 'Size of an element',
elements: [
{
type: 'radio',
id: 'bullet-size',
label: 'Size of the bullets',
items: [ [ 'BIG', 'big' ], [ 'MEDIUM', 'mdm' ],[ 'SMALL', 'sml' ] ],
style: 'color: green',
'default': 'big',
},
]
},
],
onOk: function() {
var editor = this.getParentEditor(),
element = getListElement( editor, 'ul' ),
dialog = this,
config = editor.config,
lang = editor.lang,
style = new CKEDITOR.style(config.coreStyles_alpha);
editor.attachStyleStateChange(style, function(state) {
!editor.readOnly;
});
count = element.getChildren().count();
for(k=1; k <= count; k++){
element.getChild(k-1).setAttribute('class', 'MyClass');
}
}
}
});
获取值的方法如下。 onOk
函数内部:
var my_variable = this.getVazlueOf(Id_of_you_tab, id_of_the_radio_list);
我正在尝试在 CKEditor 中构建自定义插件,在其中选择单选按钮列表中的元素会更改所选元素的 class。示例:
选择 BIG
将添加 class big
、MEDIUM
=> med
和 SMALL
=> sml
.
我在必须检索所选元素的值的部分受阻。其他一切都很好,我在下面的代码中设法将 class "MYCLASS" 应用到最近的 li
标签。
问题 : 如何在 CKeditor 的 dialog
元素中获取所选单选按钮的值?
代码如下:
CKEDITOR.dialog.add( 'MyDialog', function ( editor ) {
function getListElement( editor, listTag ) {
var range;
try {
range = editor.getSelection().getRanges()[ 0 ];
} catch ( e ) {
return null;
}
range.shrink( CKEDITOR.SHRINK_TEXT );
return editor.elementPath( range.getCommonAncestor() ).contains( listTag, 1 );
}
return {
title: 'Size of the element',
minWidth: 400,
minHeight: 200,
contents: [
{
id: 'tab-basic',
label: 'Size of an element',
elements: [
{
type: 'radio',
id: 'bullet-size',
label: 'Size of the bullets',
items: [ [ 'BIG', 'big' ], [ 'MEDIUM', 'mdm' ],[ 'SMALL', 'sml' ] ],
style: 'color: green',
'default': 'big',
},
]
},
],
onOk: function() {
var editor = this.getParentEditor(),
element = getListElement( editor, 'ul' ),
dialog = this,
config = editor.config,
lang = editor.lang,
style = new CKEDITOR.style(config.coreStyles_alpha);
editor.attachStyleStateChange(style, function(state) {
!editor.readOnly;
});
count = element.getChildren().count();
for(k=1; k <= count; k++){
element.getChild(k-1).setAttribute('class', 'MyClass');
}
}
}
});
获取值的方法如下。 onOk
函数内部:
var my_variable = this.getVazlueOf(Id_of_you_tab, id_of_the_radio_list);