Skip to content

Commit

Permalink
Implemented example multiple upcast support for easyimage, using exis…
Browse files Browse the repository at this point in the history
…ting `upcast/upcasts` API.
  • Loading branch information
mlewand committed Oct 27, 2017
1 parent 6232b54 commit b31e9d4
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions plugins/easyimage/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,33 @@

requiredContent: 'figure(!' + config.easyimage_class + ')',

upcasts: {
img: function( element ) {
if ( !this._isValidImageElement( element ) ) {
return;
}

return true;
},
figure: function( element ) {
return element.name === 'figure' && element.hasClass( config.easyimage_class );
},
a: function( element ) {
var children = element.children;

if ( children.length === 1 && children[ 0 ].name && this.upcasts[ children[ 0 ].name ] ) {
return this.upcasts[ children[ 0 ].name ].call( this, element );
}
}
},

upcast: function( element ) {
if ( !this._isValidImageElement( element ) ) {
return;
// Workaround until #1094 is fixed.
if ( element.name && this.upcasts[ element.name ] ) {
return this.upcasts[ element.name ].call( this, element );
}

return element.name === 'figure' && element.hasClass( config.easyimage_class );
return false;
},

init: function() {
Expand Down

0 comments on commit b31e9d4

Please sign in to comment.