1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | import { Plugin } from 'ckeditor5/src/core';
|
11 | import ImageLoadObserver from './imageloadobserver';
|
12 | import InsertImageCommand from './insertimagecommand';
|
13 | import ImageUtils from '../imageutils';
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | export default class ImageEditing extends Plugin {
|
25 | |
26 |
|
27 |
|
28 | static get requires() {
|
29 | return [ ImageUtils ];
|
30 | }
|
31 |
|
32 | |
33 |
|
34 |
|
35 | static get pluginName() {
|
36 | return 'ImageEditing';
|
37 | }
|
38 |
|
39 | |
40 |
|
41 |
|
42 | init() {
|
43 | const editor = this.editor;
|
44 | const conversion = editor.conversion;
|
45 |
|
46 |
|
47 | editor.editing.view.addObserver( ImageLoadObserver );
|
48 |
|
49 | conversion.for( 'upcast' )
|
50 | .attributeToAttribute( {
|
51 | view: {
|
52 | name: 'img',
|
53 | key: 'alt'
|
54 | },
|
55 | model: 'alt'
|
56 | } )
|
57 | .attributeToAttribute( {
|
58 | view: {
|
59 | name: 'img',
|
60 | key: 'srcset'
|
61 | },
|
62 | model: {
|
63 | key: 'srcset',
|
64 | value: viewImage => {
|
65 | const value = {
|
66 | data: viewImage.getAttribute( 'srcset' )
|
67 | };
|
68 |
|
69 | if ( viewImage.hasAttribute( 'width' ) ) {
|
70 | value.width = viewImage.getAttribute( 'width' );
|
71 | }
|
72 |
|
73 | return value;
|
74 | }
|
75 | }
|
76 | } );
|
77 |
|
78 | const insertImageCommand = new InsertImageCommand( editor );
|
79 |
|
80 |
|
81 | editor.commands.add( 'insertImage', insertImageCommand );
|
82 | editor.commands.add( 'imageInsert', insertImageCommand );
|
83 | }
|
84 | }
|