Ckeditor 自定义插件 - 带有单选按钮的对话框

Ckeditor custom plugin - dialog with radio buttons

本文关键字:单选按钮 对话框 自定义 插件 Ckeditor      更新时间:2023-09-26

我正在尝试在 CKEditor 中构建一个自定义插件,其中单选按钮列表中的元素选择会更改所选元素的类。例:

选择BIG将添加类bigMEDIUM => medSMALL => sml

我在必须检索所选元素的值的部分被阻止。其他事情进展顺利,我设法在下面的代码中将类"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);