From 618497356274a899c7e89dc82950c3231f02c388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Kup=C5=9B?= Date: Fri, 16 Oct 2015 15:10:09 +0200 Subject: [PATCH 1/9] Added cke_widget_ css class to widget wrapper. --- plugins/widget/plugin.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/widget/plugin.js b/plugins/widget/plugin.js index 4b6f10c275c..966e1dbed18 100644 --- a/plugins/widget/plugin.js +++ b/plugins/widget/plugin.js @@ -645,7 +645,7 @@ isInline = isWidgetInline( widgetDef, element.getName() ); wrapper = new CKEDITOR.dom.element( isInline ? 'span' : 'div' ); - wrapper.setAttributes( getWrapperAttributes( isInline ) ); + wrapper.setAttributes( getWrapperAttributes( isInline, widgetName ) ); wrapper.data( 'cke-display-name', widgetDef.pathName ? widgetDef.pathName : element.getName() ); @@ -671,7 +671,7 @@ isInline = isWidgetInline( widgetDef, element.name ); - wrapper = new CKEDITOR.htmlParser.element( isInline ? 'span' : 'div', getWrapperAttributes( isInline ) ); + wrapper = new CKEDITOR.htmlParser.element( isInline ? 'span' : 'div', getWrapperAttributes( isInline, widgetName ) ); wrapper.attributes[ 'data-cke-display-name' ] = widgetDef.pathName ? widgetDef.pathName : element.name; @@ -2199,7 +2199,7 @@ return false; } - function getWrapperAttributes( inlineWidget ) { + function getWrapperAttributes( inlineWidget, name ) { return { // tabindex="-1" means that it can receive focus by code. tabindex: -1, @@ -2208,7 +2208,8 @@ 'data-cke-filter': 'off', // Class cke_widget_new marks widgets which haven't been initialized yet. 'class': 'cke_widget_wrapper cke_widget_new cke_widget_' + - ( inlineWidget ? 'inline' : 'block' ) + ( inlineWidget ? 'inline' : 'block' ) + + ( name ? ' cke_widget_' + name : '' ) }; } From 8c2c8d3793bb88a53b29fe880f4dcc1f35a7784f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Kup=C5=9B?= Date: Mon, 19 Oct 2015 10:23:45 +0200 Subject: [PATCH 2/9] Added tests checking if widget wrapper has css class based on widget's name. --- tests/plugins/widget/_helpers/tools.js | 6 +++--- tests/plugins/widget/widgetsrepoapi.js | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/plugins/widget/_helpers/tools.js b/tests/plugins/widget/_helpers/tools.js index e27de89c78e..6ba72d8c169 100644 --- a/tests/plugins/widget/_helpers/tools.js +++ b/tests/plugins/widget/_helpers/tools.js @@ -373,7 +373,7 @@ var widgetTestsTools = ( function() { assertWidget: assertWidget, widgetInitedWrapperAttributes: - 'class="cke_widget_wrapper cke_widget_(?:inline|block)" ' + + 'class="cke_widget_wrapper cke_widget_(?:inline|block)(?: cke_widget_test_upcasted_pasting)?" ' + 'contenteditable="false" ' + '(?:data-cke-display-name="[a-z0-9]+" )?' + '(?:data-cke-expando="[0-9]+" )?' + @@ -382,7 +382,7 @@ var widgetTestsTools = ( function() { 'data-cke-widget-wrapper="1" ' + 'tabindex="-1"', widgetWrapperAttributes: - 'class="cke_widget_wrapper cke_widget_new cke_widget_(?:inline|block)" ' + + 'class="cke_widget_wrapper cke_widget_new cke_widget_(?:inline|block)(?: cke_widget_test)?" ' + 'contenteditable="false" ' + '(?:data-cke-display-name="[a-z0-9]+" )?' + '(?:data-cke-expando="[0-9]+" )?' + @@ -403,4 +403,4 @@ var widgetTestsTools = ( function() { '' }; -} )(); \ No newline at end of file +} )(); diff --git a/tests/plugins/widget/widgetsrepoapi.js b/tests/plugins/widget/widgetsrepoapi.js index 7f36e7362c4..358251c497a 100644 --- a/tests/plugins/widget/widgetsrepoapi.js +++ b/tests/plugins/widget/widgetsrepoapi.js @@ -275,6 +275,7 @@ assert.areSame( 'span', wrapper.getName(), 'inline wrapper name' ); assert.areSame( el, wrapper.getFirst(), 'inline wrapper first child' ); + assert.isTrue( wrapper.hasClass( 'cke_widget_test' ), 'Wrapper should have css class based on widget name.' ); assert.isMatching( new RegExp( '^

foofoobar(
)?

$' ), fixHtml( editor.editable().getHtml() ) @@ -332,6 +333,7 @@ var wrapper = this.editor.widgets.wrapElement( el, 'test' ); assert.areSame( 'span', wrapper.name, 'inline wrapper name' ); + assert.isTrue( wrapper.hasClass( 'cke_widget_test' ), 'Wrapper should have css class based on widget name.' ); assert.areSame( el, wrapper.children[ 0 ], 'inline wrapper first child' ); assert.isMatching( new RegExp( '^

foofoobar

$' ), writeFrag( frag ) ); }, From 3b59092e8a0162adef4a17748f1361254064f8da Mon Sep 17 00:00:00 2001 From: "m.lewandowski" Date: Tue, 20 Oct 2015 16:12:04 +0200 Subject: [PATCH 3/9] Adjusted assert messages. --- tests/plugins/widget/widgetsrepoapi.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/plugins/widget/widgetsrepoapi.js b/tests/plugins/widget/widgetsrepoapi.js index 358251c497a..604f26ea182 100644 --- a/tests/plugins/widget/widgetsrepoapi.js +++ b/tests/plugins/widget/widgetsrepoapi.js @@ -275,7 +275,7 @@ assert.areSame( 'span', wrapper.getName(), 'inline wrapper name' ); assert.areSame( el, wrapper.getFirst(), 'inline wrapper first child' ); - assert.isTrue( wrapper.hasClass( 'cke_widget_test' ), 'Wrapper should have css class based on widget name.' ); + assert.isTrue( wrapper.hasClass( 'cke_widget_test' ), 'wrapper has css class based on widget name' ); assert.isMatching( new RegExp( '^

foofoobar(
)?

$' ), fixHtml( editor.editable().getHtml() ) @@ -333,7 +333,7 @@ var wrapper = this.editor.widgets.wrapElement( el, 'test' ); assert.areSame( 'span', wrapper.name, 'inline wrapper name' ); - assert.isTrue( wrapper.hasClass( 'cke_widget_test' ), 'Wrapper should have css class based on widget name.' ); + assert.isTrue( wrapper.hasClass( 'cke_widget_test' ), 'wrapper has css class based on widget name' ); assert.areSame( el, wrapper.children[ 0 ], 'inline wrapper first child' ); assert.isMatching( new RegExp( '^

foofoobar

$' ), writeFrag( frag ) ); }, From 40eb65e84f398ea834292117c1aded7fb7ded095 Mon Sep 17 00:00:00 2001 From: "m.lewandowski" Date: Tue, 20 Oct 2015 18:04:43 +0200 Subject: [PATCH 4/9] Fixed a case when correct widget wrapper class would not be applied if CKEDITOR.plugins.widget.repository#wrapElement did not get widgetName parameter. --- plugins/widget/plugin.js | 8 ++++++-- tests/plugins/widget/_helpers/tools.js | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/widget/plugin.js b/plugins/widget/plugin.js index 966e1dbed18..e90586fd592 100644 --- a/plugins/widget/plugin.js +++ b/plugins/widget/plugin.js @@ -627,7 +627,9 @@ isInline; if ( element instanceof CKEDITOR.dom.element ) { - widgetDef = this.registered[ widgetName || element.data( 'widget' ) ]; + widgetName = widgetName || element.data( 'widget' ); + widgetDef = this.registered[ widgetName ]; + if ( !widgetDef ) return null; @@ -655,7 +657,9 @@ element.appendTo( wrapper ); } else if ( element instanceof CKEDITOR.htmlParser.element ) { - widgetDef = this.registered[ widgetName || element.attributes[ 'data-widget' ] ]; + widgetName = widgetName || element.attributes[ 'data-widget' ]; + widgetDef = this.registered[ widgetName ]; + if ( !widgetDef ) return null; diff --git a/tests/plugins/widget/_helpers/tools.js b/tests/plugins/widget/_helpers/tools.js index 6ba72d8c169..b1d54fc3ea0 100644 --- a/tests/plugins/widget/_helpers/tools.js +++ b/tests/plugins/widget/_helpers/tools.js @@ -373,7 +373,7 @@ var widgetTestsTools = ( function() { assertWidget: assertWidget, widgetInitedWrapperAttributes: - 'class="cke_widget_wrapper cke_widget_(?:inline|block)(?: cke_widget_test_upcasted_pasting)?" ' + + 'class="cke_widget_wrapper cke_widget_(?:inline|block) cke_widget_test(?:_upcasted_pasting|inline|block)" ' + 'contenteditable="false" ' + '(?:data-cke-display-name="[a-z0-9]+" )?' + '(?:data-cke-expando="[0-9]+" )?' + @@ -382,7 +382,7 @@ var widgetTestsTools = ( function() { 'data-cke-widget-wrapper="1" ' + 'tabindex="-1"', widgetWrapperAttributes: - 'class="cke_widget_wrapper cke_widget_new cke_widget_(?:inline|block)(?: cke_widget_test)?" ' + + 'class="cke_widget_wrapper cke_widget_new cke_widget_(?:inline|block) cke_widget_test(?:inline|block)?" ' + 'contenteditable="false" ' + '(?:data-cke-display-name="[a-z0-9]+" )?' + '(?:data-cke-expando="[0-9]+" )?' + From 0d5c3a9a275e8b826eb2810ce7dbf1df92b0f936 Mon Sep 17 00:00:00 2001 From: "m.lewandowski" Date: Tue, 20 Oct 2015 18:06:05 +0200 Subject: [PATCH 5/9] More assertions. --- tests/plugins/widget/widgetsrepoapi.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/plugins/widget/widgetsrepoapi.js b/tests/plugins/widget/widgetsrepoapi.js index 604f26ea182..3634029abb7 100644 --- a/tests/plugins/widget/widgetsrepoapi.js +++ b/tests/plugins/widget/widgetsrepoapi.js @@ -229,6 +229,7 @@ assert.areSame( 'span', wrapper.getName(), 'inline wrapper name' ); assert.areSame( el, wrapper.getFirst(), 'inline wrapper first child' ); + assert.isTrue( wrapper.hasClass( 'cke_widget_test' ), 'wrapper has css class based on widget name' ); assert.isMatching( new RegExp( '^

foofoobar(
)?

$' ), fixHtml( editor.editable().getHtml() ) @@ -248,6 +249,7 @@ assert.areSame( 'div', wrapper.getName(), 'block wrapper name' ); assert.areSame( el, wrapper.getFirst(), 'block wrapper first child' ); + assert.isTrue( wrapper.hasClass( 'cke_widget_test' ), 'wrapper has css class based on widget name' ); assert.isMatching( new RegExp( '^

foo(
)?

foo

bar(
)?

$' ), fixHtml( editor.editable().getHtml() ), 'HTML after 1st wrapElement()' From ec8bc3d671ef7b5dea9b745d1eef7283e2dea051 Mon Sep 17 00:00:00 2001 From: "m.lewandowski" Date: Tue, 20 Oct 2015 18:06:22 +0200 Subject: [PATCH 6/9] Codestyle fix. --- plugins/widget/plugin.js | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/widget/plugin.js b/plugins/widget/plugin.js index e90586fd592..43e0e0002c1 100644 --- a/plugins/widget/plugin.js +++ b/plugins/widget/plugin.js @@ -676,7 +676,6 @@ isInline = isWidgetInline( widgetDef, element.name ); wrapper = new CKEDITOR.htmlParser.element( isInline ? 'span' : 'div', getWrapperAttributes( isInline, widgetName ) ); - wrapper.attributes[ 'data-cke-display-name' ] = widgetDef.pathName ? widgetDef.pathName : element.name; var parent = element.parent, From ed22237b0c9ab5178ab82a85709ae46b5b0d9c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Kup=C5=9B?= Date: Fri, 23 Oct 2015 13:02:11 +0200 Subject: [PATCH 7/9] Changed regexp in widget test tools to also match tests in widgetsintegration.js --- tests/plugins/widget/_helpers/tools.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plugins/widget/_helpers/tools.js b/tests/plugins/widget/_helpers/tools.js index b1d54fc3ea0..b2a1c53f479 100644 --- a/tests/plugins/widget/_helpers/tools.js +++ b/tests/plugins/widget/_helpers/tools.js @@ -382,7 +382,7 @@ var widgetTestsTools = ( function() { 'data-cke-widget-wrapper="1" ' + 'tabindex="-1"', widgetWrapperAttributes: - 'class="cke_widget_wrapper cke_widget_new cke_widget_(?:inline|block) cke_widget_test(?:inline|block)?" ' + + 'class="cke_widget_wrapper cke_widget_new cke_widget_(?:inline|block) cke_widget_test(?:1|2|inline|block)?" ' + 'contenteditable="false" ' + '(?:data-cke-display-name="[a-z0-9]+" )?' + '(?:data-cke-expando="[0-9]+" )?' + From a9dc80a1548d00bc3e26789b6581be2f3d6225d8 Mon Sep 17 00:00:00 2001 From: Tadeusz Piskozub Date: Thu, 19 May 2016 14:23:38 +0200 Subject: [PATCH 8/9] Remove always-true condition --- plugins/widget/plugin.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/widget/plugin.js b/plugins/widget/plugin.js index 43e0e0002c1..5bd8933f6b6 100644 --- a/plugins/widget/plugin.js +++ b/plugins/widget/plugin.js @@ -641,8 +641,8 @@ // If attribute isn't already set (e.g. for pasted widget), set it. if ( !element.hasAttribute( 'data-cke-widget-keep-attr' ) ) element.data( 'cke-widget-keep-attr', element.data( 'widget' ) ? 1 : 0 ); - if ( widgetName ) - element.data( 'widget', widgetName ); + + element.data( 'widget', widgetName ); isInline = isWidgetInline( widgetDef, element.getName() ); From c397a13a3fafb1e81f20f69f2e765e90cb43d4ee Mon Sep 17 00:00:00 2001 From: Tadeusz Piskozub Date: Thu, 19 May 2016 14:33:00 +0200 Subject: [PATCH 9/9] Changelog entry. --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 607442071c1..eba5fb1c5ce 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ CKEditor 4 Changelog New Features: +* [#13829](http://dev.ckeditor.com/ticket/13829): Fixed: No class in [Widget](http://ckeditor.com/addon/widget) wrapper that would identify the widget type. * [#14449](http://dev.ckeditor.com/ticket/14449): Introduced the [Balloon Panel](http://ckeditor.com/addon/balloonpanel) plugin. * [#12077](https://dev.ckeditor.com/ticket/12077): Added support for the HTML5 `download` attribute in link (``) elements. Thanks to [sbusse](https://github.com/sbusse)! * [#13518](http://dev.ckeditor.com/ticket/13518): Introduced [`additionalRequestParameters`](http://docs.ckeditor.com/#!/api/CKEDITOR.fileTools.uploadWidgetDefinition-property-additionalRequestParameters) property.