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