代码之家  ›  专栏  ›  技术社区  ›  Barnee Emily

自定义CKeditor 5的下拉按钮

  •  0
  • Barnee Emily  · 技术社区  · 7 年前

    已将自定义下拉按钮添加到工具栏:
    enter image description here 但我不知道如何添加标签或图标。

    import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
    import Model from '@ckeditor/ckeditor5-ui/src/model';
    
    import { createDropdown, addListToDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
    import Collection from '@ckeditor/ckeditor5-utils/src/collection';
    
    import imageIcon from '@ckeditor/ckeditor5-core/theme/icons/image.svg';
    
    export default class ImageDropdown extends Plugin {
        
        static get pluginName() {
            return 'ImageDropdown';
        }
        
        init() {
            const editor = this.editor;
            const t = editor.t;
            const defaultTitle = t('Add image');
            const dropdownTooltip = t('Image');
    
            // Register UI component
            editor.ui.componentFactory.add('imageDropdown', locale => {
    
                const dropdownView = createDropdown( locale );
    
                dropdownView.set({
                    label: 'Image',
                    tooltip: true
                });
                dropdownView.buttonView.set( {
    				isOn: false,
    				withText: true,
    				tooltip: dropdownTooltip
                });
                dropdownView.extendTemplate( {
    				attributes: {
    					class: [
    						'ck-image-dropdown'
    					]
    				}
    			});
    
                // The collection of the list items.
                const items = new Collection();
    
                items.add( {
                    type: 'button',
                    model: new Model( {
                        label: 'Uppload image',
                        icon: imageIcon
                    })
                });
    
                items.add( {
                    type: 'button',
                    model: new Model( {
                        label: 'Image URL',
                        icon: imageIcon
                    })
                });
    
                // Create a dropdown with a list inside the panel.
                addListToDropdown( dropdownView, items );
    
                return dropdownView;
            });
        }
    }
    1 回复  |  直到 7 年前
        1
  •  1
  •   Maciej Bukowski    7 年前

    为下拉按钮设置标签、图标等应在下拉列表的视图实例上进行:

    dropdownView.buttonView.set({
        label: 'some-label',
        icon: 'path/to/some/icon'
        tooltip: true
    });
    

    请注意,这些属性是 observable ObservableMixin#bind

    https://github.com/ckeditor/ckeditor5-alignment/blob/894745ecb1e8bd94286b4089eb16079034eb8a0b/src/alignmentui.js#L107-L124