首页 文章

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

提问于
浏览
0

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

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

我被阻止在我必须检索所选元素的值的部分 . 其他东西也没关系,我在下面的代码中设法将类"MYCLASS"应用到最接近的 li 标签 .

Question :如何获取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');
         }
     }
    }
});

1 回答

  • 1

    这是获得 Value 的方法 . 在 onOk 函数内:

    var my_variable = this.getVazlueOf(Id_of_you_tab, id_of_the_radio_list);
    

相关问题