1

我目前正在尝试使用 CKEditor 添加 XML 条目。我修改了示例插件的代码:

CKEDITOR.dialog.add( 'abbrDialog', function( editor ) {
return {
    title: 'Abbreviation Properties',
    minWidth: 400,
    minHeight: 200,
    contents: [
        {
            id: 'tab-basic',
            label: 'Basic Settings',
            elements: [
                {
                    type: 'text',
                    id: 'abbr',
                    label: 'Title',
                    validate: CKEDITOR.dialog.validate.notEmpty( "Title cannot be empty" )
                },
                {
                    type: 'text',
                    id: 'title',
                    label: 'Price',
                    validate: CKEDITOR.dialog.validate.notEmpty( "Price cannot be empty" )
                }    
            ]
        },
        {
            id: 'tab-adv',
            label: 'Advanced Settings',
            elements: [
                {
                    type: 'text',
                    id: 'id',
                    label: 'Id'
                }
            ]
        }
    ],          
    onOk: function() {
        var dialog = this;

        var abbr = editor.document.createElement( 'abbr' );
        abbr.setAttribute( 'title', dialog.getValueOf( 'tab-basic', 'title' ) );
        abbr.setText( dialog.getValueOf( 'tab-basic', 'abbr' ) );

        var id = dialog.getValueOf( 'tab-adv', 'id' );
        if ( id )
            abbr.setAttribute( 'id', id );

        editor.insertElement( abbr );
    }
};

});

但是,当我再次单击编辑器以添加更多项目时,标签变成嵌套的,例如 . 这是不希望的。如何限制另一个标签内没有任何标签?谢谢

4

1 回答 1

1

这将检索插入符号下的元素:

var selectedElement = editor.getSelection().getStartElement();

有了这个,您可以检索特定类型的最接近的上升:

selectedElement.getAscendant( 'abbr', 1 );

基本上,当有一个时,不要插入任何东西和/或更新selectedElement新的属性、属性等。


顺便说一句:如果您希望进行更具体的过滤,这将为您提供一个可迭代的父元素数组(朝向 DOM 根):

selectedElement.getParents();
于 2013-01-23T11:40:07.013 回答