|
|
@@ -100,14 +100,32 @@ export function modelToViewSelection( t ) {
|
|
|
* @param {module:engine/model/element~Element} modelElement
|
|
|
* @return {module:engine/view/containerelement~ContainerElement}
|
|
|
*/
|
|
|
-export function modelToViewImage( modelElement ) {
|
|
|
- const viewImg = new ViewEmptyElement( 'img', {
|
|
|
- src: modelElement.getAttribute( 'src' )
|
|
|
- } );
|
|
|
+export function modelToViewImage() {
|
|
|
+ return new ViewContainerElement( 'figure', { class: 'image' }, new ViewEmptyElement( 'img' ) );
|
|
|
+}
|
|
|
|
|
|
- if ( modelElement.hasAttribute( 'alt' ) ) {
|
|
|
- viewImg.setAttribute( 'alt', modelElement.getAttribute( 'alt' ) );
|
|
|
+export function imageAttributeToView( dispatchers, attributeName ) {
|
|
|
+ for ( let dispatcher of dispatchers ) {
|
|
|
+ dispatcher.on( `addAttribute:${ attributeName }:image`, imageAttributeConverter );
|
|
|
+ dispatcher.on( `changeAttribute:${ attributeName }:image`, imageAttributeConverter );
|
|
|
+ dispatcher.on( `removeAttribute:${ attributeName }:image`, imageAttributeConverter );
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
- return new ViewContainerElement( 'figure', { class: 'image' }, viewImg );
|
|
|
+function imageAttributeConverter( evt, data, consumable, conversionApi ) {
|
|
|
+ const parts = evt.name.split( ':' );
|
|
|
+ const consumableType = parts[ 0 ] + ':' + parts[ 1 ];
|
|
|
+
|
|
|
+ if ( !consumable.consume( data.item, consumableType ) ) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const figure = conversionApi.mapper.toViewElement( data.item );
|
|
|
+ const img = figure.getChild( 0 );
|
|
|
+
|
|
|
+ if ( parts[ 0 ] == 'removeAttribute' ) {
|
|
|
+ img.removeAttribute( data.attributeKey );
|
|
|
+ } else {
|
|
|
+ img.setAttribute( data.attributeKey, data.attributeNewValue );
|
|
|
+ }
|
|
|
}
|