CKEDITOR.plugins.add('spacing', {
    init: function(editor) {
        // 添加段前间距命令
        editor.addCommand('setSpacingBefore', {
            exec: function(editor) {
                var style = new CKEDITOR.style({
                    element: 'p',
                    attributes: {
                        'style': 'margin-top: ' + this.value + ';line-height: 1;'
                    }
                });
                editor.applyStyle(style);
            }
        });

        // 添加段后间距命令
        editor.addCommand('setSpacingAfter', {
            exec: function(editor) {
                var style = new CKEDITOR.style({
                    element: 'p',
                    attributes: {
                        'style': 'margin-bottom: ' + this.value + ';line-height: 1;'
                    }
                });
                editor.applyStyle(style);
            }
        });

        // 创建段前间距下拉菜单
        editor.ui.addRichCombo('SpacingBefore', {
            label: '段前间距',
            title: '设置段前间距',
            panel: {
                css: [CKEDITOR.skin.getPath('editor')].concat(editor.config.contentsCss)
            },
            init: function() {
                this.startGroup('段前间距');
                this.add('0', '0行');
                this.add('1em', '1行');
                this.add('1.5em', '1.5行');
                this.add('2em', '2行');
            },
            onClick: function(value) {
                editor.execCommand('setSpacingBefore', { value: value });
            }
        });

        // 创建段后间距下拉菜单
        editor.ui.addRichCombo('SpacingAfter', {
            label: '段后间距',
            title: '设置段后间距',
            panel: {
                css: [CKEDITOR.skin.getPath('editor')].concat(editor.config.contentsCss)
            },
            init: function() {
                this.startGroup('段后间距');
                this.add('0', '0行');
                this.add('1em', '1行');
                this.add('1.5em', '1.5行');
                this.add('2em', '2行');
            },
            onClick: function(value) {
                editor.execCommand('setSpacingAfter', { value: value });
            }
        });
    }
}); 