mediaembedtoolbar.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Copyright (c) 2016 - 2018, CKSource - Frederico Knabben. All rights reserved.
  3. */
  4. /**
  5. * @module media-embed/mediaembedtoolbar
  6. */
  7. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  8. import WidgetToolbarRepository from '@ckeditor/ckeditor5-widget/src/widgettoolbarrepository';
  9. import { getSelectedMediaViewWidget } from './utils';
  10. /**
  11. * The media embed toolbar plugin. It creates a toolbar for media embed that shows up when the media element is selected.
  12. *
  13. * Instances of toolbar components (e.g. buttons) are created based on the
  14. * {@link module:media-embed/mediaembed~MediaEmbedConfig#toolbar `media.toolbar` configuration option}.
  15. *
  16. * @extends module:core/plugin~Plugin
  17. */
  18. export default class MediaEmbedToolbar extends Plugin {
  19. /**
  20. * @inheritDoc
  21. */
  22. static get requires() {
  23. return [ WidgetToolbarRepository ];
  24. }
  25. /**
  26. * @inheritDoc
  27. */
  28. static get pluginName() {
  29. return 'MediaEmbedToolbar';
  30. }
  31. /**
  32. * @inheritDoc
  33. */
  34. afterInit() {
  35. const editor = this.editor;
  36. const widgetToolbarRepository = editor.plugins.get( WidgetToolbarRepository );
  37. widgetToolbarRepository.register( 'mediaEmbed', {
  38. items: editor.config.get( 'mediaEmbed.toolbar' ) || [],
  39. getRelatedElement: getSelectedMediaViewWidget,
  40. } );
  41. }
  42. }
  43. /**
  44. * Items to be placed in the media embed toolbar.
  45. * This option requires adding {@link module:media-embed/mediaembedtoolbar~MediaEmbedToolbar} to the plugin list.
  46. *
  47. * Read more about configuring toolbar in {@link module:core/editor/editorconfig~EditorConfig#toolbar}.
  48. *
  49. * @member {Array.<String>} module:media-embed/mediaembed~MediaEmbedConfig#toolbar
  50. */