Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
- import {createDropdown, addListToDropdown} from "@ckeditor/ckeditor5-ui/src/dropdown/utils";
- import Collection from "@ckeditor/ckeditor5-utils/src/collection";
- import Model from "@ckeditor/ckeditor5-engine/src/model/model";
- import SplitButtonView from "@ckeditor/ckeditor5-ui/src/dropdown/button/splitbuttonview";
- export default class Preset extends Plugin {
- static get pluginName() {
- return 'Preset';
- }
- init() {
- const editor = this.editor;
- editor.ui.componentFactory.add('Preset', locale => {
- const dropdownView = createDropdown(locale);
- dropdownView.buttonView.set({
- label: 'Translate',
- withText: true,
- });
- const items = new Collection();
- items.add( {
- type: 'button',
- model: new Model({
- id: 'en',
- withText: true,
- label: 'English',
- })
- } );
- items.add( {
- type: 'button',
- model: new Model({
- id: 'es',
- withText: true,
- label: 'Spanish'
- })
- } );
- addListToDropdown(dropdownView, items);
- dropdownView.on('execute', (eventInfo) => {
- const { id, label } = eventInfo.source;
- if ( id === 'en' ) {
- console.log('Object (en):', label);
- } else if ( id === 'es' ) {
- console.log('Object (es):', label);
- }
- });
- return dropdownView;
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment