Skip to content

Commit

Permalink
Merge branch 't/12440'
Browse files Browse the repository at this point in the history
  • Loading branch information
mlewand committed Mar 29, 2016
2 parents 12f0de3 + 6c5453a commit 7c87fba
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -5,6 +5,7 @@ CKEditor 4 Changelog

Other Changes:

* [#12440](http://dev.ckeditor.com/ticket/12440): Added the [`config.colorButton_enableAutomatic`](http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-colorButton_enableAutomatic) option to allow hiding the "Automatic" option in the color picker.
* [#13756](http://dev.ckeditor.com/ticket/13756): Fixed: Context menus are cut-off in Microsoft Edge.
* [#12707](http://dev.ckeditor.com/ticket/12707): Fixed: The order of table elements does not meet the HTML specification.

Expand Down
47 changes: 30 additions & 17 deletions plugins/colorbutton/plugin.js
Expand Up @@ -91,7 +91,9 @@ CKEDITOR.plugins.add( 'colorbutton', {
if ( !color || color == 'transparent' )
color = '#ffffff';

this._.panel._.iframe.getFrameDocument().getById( colorBoxId ).setStyle( 'background-color', color );
if ( config.colorButton_enableAutomatic !== false ) {
this._.panel._.iframe.getFrameDocument().getById( colorBoxId ).setStyle( 'background-color', color );
}

return color;
}
Expand Down Expand Up @@ -153,22 +155,24 @@ CKEDITOR.plugins.add( 'colorbutton', {
editor.fire( 'saveSnapshot' );
} );

// Render the "Automatic" button.
output.push( '<a class="cke_colorauto" _cke_focus=1 hidefocus=true' +
' title="', lang.auto, '"' +
' onclick="CKEDITOR.tools.callFunction(', clickFn, ',null,\'', type, '\');return false;"' +
' href="javascript:void(\'', lang.auto, '\')"' +
' role="option" aria-posinset="1" aria-setsize="', total, '">' +
'<table role="presentation" cellspacing=0 cellpadding=0 width="100%">' +
'<tr>' +
'<td>' +
'<span class="cke_colorbox" id="', colorBoxId, '"></span>' +
'</td>' +
'<td colspan=7 align=center>', lang.auto, '</td>' +
'</tr>' +
'</table>' +
'</a>' +
'<table role="presentation" cellspacing=0 cellpadding=0 width="100%">' );
if ( config.colorButton_enableAutomatic !== false ) {
// Render the "Automatic" button.
output.push( '<a class="cke_colorauto" _cke_focus=1 hidefocus=true' +
' title="', lang.auto, '"' +
' onclick="CKEDITOR.tools.callFunction(', clickFn, ',null,\'', type, '\');return false;"' +
' href="javascript:void(\'', lang.auto, '\')"' +
' role="option" aria-posinset="1" aria-setsize="', total, '">' +
'<table role="presentation" cellspacing=0 cellpadding=0 width="100%">' +
'<tr>' +
'<td>' +
'<span class="cke_colorbox" id="', colorBoxId, '"></span>' +
'</td>' +
'<td colspan=7 align=center>', lang.auto, '</td>' +
'</tr>' +
'</table>' +
'</a>' );
}
output.push( '<table role="presentation" cellspacing=0 cellpadding=0 width="100%">' );

// Render the color boxes.
for ( var i = 0; i < colors.length; i++ ) {
Expand Down Expand Up @@ -299,3 +303,12 @@ CKEDITOR.config.colorButton_backStyle = {
element: 'span',
styles: { 'background-color': '#(color)' }
};

/**
* Whether to enable the **Automatic** button in the color selectors.
*
* config.colorButton_enableAutomatic = false;
*
* @cfg {Boolean} [colorButton_enableAutomatic=true]
* @member CKEDITOR.config
*/
40 changes: 39 additions & 1 deletion tests/plugins/colorbutton/colorbutton.js
Expand Up @@ -36,6 +36,44 @@
} );

wait();
},

'test enableAutomatic=true option': function() {
bender.editorBot.create( {
name: 'editor1',
config: {
colorButton_enableAutomatic: true
}
}, function( bot ) {
var editor = bot.editor,
txtColorBtn = editor.ui.get( 'TextColor' ),
bgColorBtn = editor.ui.get( 'BGColor' );

txtColorBtn.click( editor );
assert.areEqual( 1, txtColorBtn._.panel.getBlock( txtColorBtn._.id ).element.find( '.cke_colorauto' ).count(), 'Automatic button should be visible.' );

bgColorBtn.click( editor );
assert.areEqual( 1, bgColorBtn._.panel.getBlock( bgColorBtn._.id ).element.find( '.cke_colorauto' ).count(), 'Automatic button should be visible.' );
} );
},

'test enableAutomatic=false option': function() {
bender.editorBot.create( {
name: 'editor2',
config: {
colorButton_enableAutomatic: false
}
}, function( bot ) {
var editor = bot.editor,
txtColorBtn = editor.ui.get( 'TextColor' ),
bgColorBtn = editor.ui.get( 'BGColor' );

txtColorBtn.click( editor );
assert.areEqual( 0, txtColorBtn._.panel.getBlock( txtColorBtn._.id ).element.find( '.cke_colorauto' ).count(), 'Automatic button should not be visible.' );

bgColorBtn.click( editor );
assert.areEqual( 0, bgColorBtn._.panel.getBlock( bgColorBtn._.id ).element.find( '.cke_colorauto' ).count(), 'Automatic button should not be visible.' );
} );
}
} );
} )();
} )();

0 comments on commit 7c87fba

Please sign in to comment.