1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import { Command } from 'ckeditor5/src/core';
|
9 |
|
10 |
|
11 |
|
12 | export default class ImageTextAlternativeCommand extends Command {
|
13 | |
14 |
|
15 |
|
16 | refresh() {
|
17 | const editor = this.editor;
|
18 | const imageUtils = editor.plugins.get('ImageUtils');
|
19 | const element = imageUtils.getClosestSelectedImageElement(this.editor.model.document.selection);
|
20 | this.isEnabled = !!element;
|
21 | if (this.isEnabled && element.hasAttribute('alt')) {
|
22 | this.value = element.getAttribute('alt');
|
23 | }
|
24 | else {
|
25 | this.value = false;
|
26 | }
|
27 | }
|
28 | |
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | execute(options) {
|
36 | const editor = this.editor;
|
37 | const imageUtils = editor.plugins.get('ImageUtils');
|
38 | const model = editor.model;
|
39 | const imageElement = imageUtils.getClosestSelectedImageElement(model.document.selection);
|
40 | model.change(writer => {
|
41 | writer.setAttribute('alt', options.newValue, imageElement);
|
42 | });
|
43 | }
|
44 | }
|