Guest User

Untitled

a guest
Dec 16th, 2020
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  2. import {createDropdown, addListToDropdown} from "@ckeditor/ckeditor5-ui/src/dropdown/utils";
  3. import Collection from "@ckeditor/ckeditor5-utils/src/collection";
  4. import Model from "@ckeditor/ckeditor5-engine/src/model/model";
  5. import SplitButtonView from "@ckeditor/ckeditor5-ui/src/dropdown/button/splitbuttonview";
  6.  
  7. export default class Preset extends Plugin {
  8.  
  9.     static get pluginName() {
  10.         return 'Preset';
  11.     }
  12.  
  13.     init() {
  14.         const editor = this.editor;
  15.  
  16.         editor.ui.componentFactory.add('Preset', locale => {
  17.             const dropdownView = createDropdown(locale);
  18.             dropdownView.buttonView.set({
  19.                 label: 'Translate',
  20.                 withText: true,
  21.             });
  22.  
  23.             const items = new Collection();
  24.             items.add( {
  25.                 type: 'button',
  26.                 model: new Model({
  27.                     id: 'en',
  28.                     withText: true,
  29.                     label: 'English',
  30.                 })
  31.             } );
  32.             items.add( {
  33.                 type: 'button',
  34.                 model: new Model({
  35.                     id: 'es',
  36.                     withText: true,
  37.                     label: 'Spanish'
  38.                 })
  39.             } );
  40.  
  41.             addListToDropdown(dropdownView, items);
  42.  
  43.             dropdownView.on('execute', (eventInfo) => {
  44.                 const { id, label } = eventInfo.source;
  45.  
  46.                 if ( id === 'en' ) {
  47.                     console.log('Object (en):', label);
  48.                 } else if ( id === 'es' ) {
  49.                     console.log('Object (es):', label);
  50.                 }
  51.             });
  52.  
  53.             return dropdownView;
  54.         });
  55.     }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment