diff --git a/CHANGES.md b/CHANGES.md index 4b406255173..3e456b50373 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,7 @@ Fixed Issues: * [#13118](http://dev.ckeditor.com/ticket/13118): Fixed: The [`editor.getSelectedHtml()`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-getSelectedHtml) method throws error when called in the source mode. * [#13158](http://dev.ckeditor.com/ticket/13158): Fixed: Error after canceling dialog when creating a widget. * [#13197](http://dev.ckeditor.com/ticket/13197): Fixed: Linked inline image2's alignment class is not transferred to widget wrapper. +* [#13199](http://dev.ckeditor.com/ticket/13199): Fixed: Embedsemantic does not support widget classes. * Toolbar configurators: * [#13185](http://dev.ckeditor.com/ticket/13185): Fixed: Wrong position of the suggestion box if there is not enough space below the caret. * [#13138](http://dev.ckeditor.com/ticket/13138): Fixed: The "Toggle empty elements" button label is unclear. diff --git a/plugins/embedsemantic/plugin.js b/plugins/embedsemantic/plugin.js index 29133ed868c..8323a99ff44 100644 --- a/plugins/embedsemantic/plugin.js +++ b/plugins/embedsemantic/plugin.js @@ -68,14 +68,23 @@ data.loadOnReady = true; div = new CKEDITOR.htmlParser.element( 'div' ); element.replaceWith( div ); + + // Transfer widget classes from data to widget element (#13199). + div.attributes[ 'class' ] = element.attributes[ 'class' ]; + return div; } }, - downcast: function() { + downcast: function( element ) { var ret = new CKEDITOR.htmlParser.element( 'oembed' ); ret.add( new CKEDITOR.htmlParser.text( this.data.url ) ); + // Transfer widget classes from widget element back to data (#13199). + if ( element.attributes[ 'class' ] ) { + ret.attributes[ 'class' ] = element.attributes[ 'class' ]; + } + return ret; } }, true ); diff --git a/tests/plugins/embed/integration.js b/tests/plugins/embed/integration.js index e85bfbdba99..8008ceaa7b7 100644 --- a/tests/plugins/embed/integration.js +++ b/tests/plugins/embed/integration.js @@ -8,13 +8,36 @@ bender.editors = { classic: { name: 'editor_classic', - creator: 'replace' + creator: 'replace', + config: { + extraAllowedContent: 'div(a,b,c)' + } } }; +var obj2Array = widgetTestsTools.obj2Array; +var classes2Array = widgetTestsTools.classes2Array; + embedTools.mockJsonp(); -var tcs = {}; +var tcs = { + 'test support for widget classes': function() { + var bot = this.editorBots.classic, + editor = bot.editor, + data = '
' + + 'image' + + '
'; + + bot.setData( data, function() { + wait( function() { + arrayAssert.itemsAreSame( [ 'a', 'b', 'c' ], + classes2Array( obj2Array( editor.widgets.instances )[ 0 ].getClasses() ).sort(), 'classes transfered from data to widget.element' ); + + assert.areSame( data, bot.getData( 1, 1 ), 'classes transfered from widget.element back to data' ); + }, 100 ); + } ); + } +}; widgetTestsTools.addTests( tcs, { name: 'basic', diff --git a/tests/plugins/embedsemantic/integration.js b/tests/plugins/embedsemantic/integration.js index e21665ed05f..8a577e7f35f 100644 --- a/tests/plugins/embedsemantic/integration.js +++ b/tests/plugins/embedsemantic/integration.js @@ -8,11 +8,15 @@ bender.editors = { classic: { name: 'editor_classic', - creator: 'replace' + creator: 'replace', + config: { + extraAllowedContent: 'oembed(a,b,c)' + } } }; var obj2Array = widgetTestsTools.obj2Array; +var classes2Array = widgetTestsTools.classes2Array; embedTools.mockJsonp(); @@ -81,6 +85,20 @@ var tcs = { assert.isFalse( loadContentSpy.called, 'widget.loadContent was not called on undo' ); }, 100 ); } ); + }, + + 'test support for widget classes': function() { + var bot = this.editorBots.classic, + editor = bot.editor; + + bot.setData( '

x

http://widget/classes

x

', function() { + wait( function() { + arrayAssert.itemsAreSame( [ 'a', 'b', 'c' ], + classes2Array( obj2Array( editor.widgets.instances )[ 0 ].getClasses() ).sort(), 'classes transfered from data to widget.element' ); + + assert.areSame( '

x

http://widget/classes

x

', bot.getData(), 'classes transfered from widget.element back to data' ); + }, 100 ); + } ); } };