Skip to content

Commit

Permalink
Merge pull request #346 from cksource/t/16971
Browse files Browse the repository at this point in the history
Improve background color detection in tabletools plugin.
  • Loading branch information
f1ames committed Apr 19, 2017
2 parents 8f388d2 + bea7e76 commit 84d3983
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -5,6 +5,7 @@

New Features:

* [#16971](http://dev.ckeditor.com/ticket/16971): Added a support for color in `background` property containing also other styles for table cells in [Table Tools](http://ckeditor.com/addon/tabletools) plugin.
* [#16847](http://dev.ckeditor.com/ticket/16847): Added a support for parsing and inlining any formatting created using Microsoft Word's style system to the [Paste from Word](http://ckeditor.com/addon/pastefromword) plugin.
* [#16818](http://dev.ckeditor.com/ticket/16818): Added table cell height parsing in the [Paste from Word](http://ckeditor.com/addon/pastefromword) plugin.
* [#16850](http://dev.ckeditor.com/ticket/16850): Added new `config.enableContextMenu` configuration option for enabling and disabling [Context Menu](http://ckeditor.com/addon/contextmenu).
Expand Down
7 changes: 4 additions & 3 deletions plugins/tabletools/plugin.js
Expand Up @@ -644,7 +644,8 @@
CKEDITOR.plugins.tabletools = {
requires: 'table,dialog,contextmenu',
init: function( editor ) {
var lang = editor.lang.table;
var lang = editor.lang.table,
styleParse = CKEDITOR.tools.style.parse;

function createDef( def ) {
return CKEDITOR.tools.extend( def || {}, {
Expand All @@ -665,10 +666,10 @@
contentTransformations: [ [ {
element: 'td',
left: function( element ) {
return element.styles.background && element.styles.background.match( /^(#[a-fA-F0-9]{3,6}|rgb\([\d, ]+\)|\w+)$/ );
return element.styles.background && styleParse.background( element.styles.background ).color;
},
right: function( element ) {
element.styles[ 'background-color' ] = element.styles.background;
element.styles[ 'background-color' ] = styleParse.background( element.styles.background ).color;
}
}, {
element: 'td',
Expand Down
@@ -0,0 +1,7 @@
<div id="editor">
<p></p>
</div>

<script>
CKEDITOR.replace( 'editor' );
</script>
22 changes: 22 additions & 0 deletions tests/plugins/tabletools/manual/transformations/mixedBackground.md
@@ -0,0 +1,22 @@
@bender-tags: 4.7.0, tc, 16971
@bender-ui: collapsed
@bender-ckeditor-plugins: wysiwygarea, toolbar, tabletools, sourcearea

1. Open source area using "Source" button.
1. Insert following HTML:
```html
<table border="1" style="width:300px">
<tbody>
<tr>
<td style="background:#00cc99 no-repeat center">&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
```
1. Go back to wysiwyg mode, by clicking "Source" button again.
**Expected:** Background in the first cell is different than the other.
1. Right click the first cell, and use "Cell / Cell Properties".
**Expected:** "Background Color" property is set.

Note there's an issue that the value in the dialog is displayed in `rgb()` format, it's an unrelated issue. You can verify the transformation by checking source once again.
20 changes: 20 additions & 0 deletions tests/plugins/tabletools/tabletools.html
Expand Up @@ -1472,6 +1472,26 @@
</table>
</textarea>

<textarea id="background-extraction">
<table border="1">
<tbody>
<tr>
<td style="background:no-repeat center #00cc99">&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
=>
<table border="1">
<tbody>
<tr>
<td style="background:no-repeat center #00cc99; background-color: #00cc99">&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
</textarea>

<textarea id="align-conversion">
<table border="1">
<tbody>
Expand Down
14 changes: 14 additions & 0 deletions tests/plugins/tabletools/tabletools.js
Expand Up @@ -192,6 +192,20 @@
} );
},

// (#16971)
'test background color extraction': function() {
var bot = this.editorBot;

bender.tools.testInputOut( 'background-extraction', function( source, expected ) {
if ( CKEDITOR.env.ie && CKEDITOR.env.version === 8 ) {
// Just a regular IE quirks.
expected = expected.replace( 'no-repeat center #00cc99', '#00cc99 no-repeat center 50%' );
}
bot.setHtmlWithSelection( source );
assert.beautified.html( expected, bot.getData( true ) );
} );
},

'test valign conversion': function() {
var bot = this.editorBot;

Expand Down

0 comments on commit 84d3983

Please sign in to comment.