mediaembedtoolbar.js 1.7 KB

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