-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added possibility to use custom icons in buttons #1531
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6fac875
Support for custom icons in buttons.
f1ames 03fa88c
Tests: unit tests for custom icons in buttons.
f1ames 310859f
Tests: manual tests for custom icons in buttons.
f1ames d46d4cf
Tests: unit tests adjustments.
f1ames 38cde17
Changelog entry. [skip ci]
f1ames 91ade23
Proper issue reference.
f1ames ec9e32d
Proper 'HiDPI' word formatting as property and in docs.
f1ames 101e5ad
Support for using custom icons instead of defined default ones.
f1ames 088ee32
Tests: unit tests refactoring.
f1ames 28bc688
Tests: ignore some unit tests on build version.
f1ames 0fe9275
Tests: changed sample icon color.
f1ames 3087e08
Make sure icon element has proper class name.
f1ames 0fbe103
Add issue number to the manual test.
Comandeer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,264 @@ | ||
/* bender-tags: editor */ | ||
/* bender-ckeditor-plugins: button,toolbar */ | ||
|
||
( function() { | ||
'use strict'; | ||
|
||
var editorCounter = 0, | ||
originalBasePath = null, | ||
isDev = CKEDITOR.version === '%VERSION%', | ||
isHidpi, | ||
tests; | ||
|
||
function createIconTests( testsObj, tests ) { | ||
CKEDITOR.tools.array.forEach( tests, function( test ) { | ||
testsObj[ test.name ] = function() { | ||
if ( test.ignore ) { | ||
// On a build version icons sprite image is loaded before any test code is execute so we are not able | ||
// to emulate `CKEDITOR.env.hidpi` to force different icons loading. Due to this behaviour some tests | ||
// needs to be ignored in build version. | ||
assert.ignore(); | ||
} else { | ||
CKEDITOR.env.hidpi = test.name.indexOf( 'hidpi' ) !== -1; | ||
assertIcon( test.config, test.button, test.iconPath, test.iconName ); | ||
} | ||
}; | ||
} ); | ||
} | ||
|
||
function assertIcon( editorConfig, btnName, iconPath, iconName ) { | ||
editorCounter++; | ||
bender.editorBot.create( { | ||
name: 'editor' + editorCounter, | ||
config: editorConfig | ||
}, function( bot ) { | ||
var btn = bot.editor.ui.get( btnName ), | ||
btnEl = CKEDITOR.document.getById( btn._.id ), | ||
btnCss = CKEDITOR.tools.parseCssText( btnEl.findOne( '.cke_button_icon' ).getAttribute( 'style' ), true ); | ||
|
||
if ( iconPath === undefined ) { | ||
// Standard icon should be checked. | ||
if ( isDev ) { | ||
var iconFileName = ( iconName || btnName ).toLowerCase(), | ||
hidpi = CKEDITOR.env.hidpi ? 'hidpi\\/' : ''; | ||
|
||
iconPath = new RegExp( 'plugins\\/' + iconFileName + '\\/icons\\/' + hidpi + iconFileName + '\\.png', 'gi' ); | ||
} else { | ||
// In build version all standard icons are inside 'icons.png' sprite. | ||
iconPath = CKEDITOR.env.hidpi ? /plugins\/icons_hidpi\.png/gi : /plugins\/icons\.png/gi; | ||
} | ||
} | ||
|
||
assert.isMatching( iconPath, btnCss[ 'background-image' ] ); | ||
} ); | ||
} | ||
|
||
tests = { | ||
init: function() { | ||
isHidpi = CKEDITOR.env.hidpi; | ||
}, | ||
|
||
tearDown: function() { | ||
// Restore global values modified by tests. | ||
CKEDITOR.env.hidpi = isHidpi; | ||
if ( originalBasePath ) { | ||
CKEDITOR.basePath = originalBasePath; | ||
originalBasePath = null; | ||
} | ||
} | ||
}; | ||
|
||
createIconTests( tests, [ | ||
{ | ||
name: 'test default button icon', | ||
button: 'Link', | ||
config: { | ||
extraPlugins: 'link' | ||
}, | ||
ignore: !isDev && CKEDITOR.env.hidpi | ||
}, { | ||
name: 'test default button icon (hidpi)', | ||
button: 'Find', | ||
config: { | ||
extraPlugins: 'find' | ||
}, | ||
ignore: !isDev && !CKEDITOR.env.hidpi | ||
}, { | ||
name: 'test overwriting default button icon', | ||
button: 'Replace', | ||
iconPath: /tests\/_assets\/sample_icon\.png/gi, | ||
config: { | ||
extraPlugins: 'find', | ||
toolbar: [ [ 'Replace' ] ], | ||
on: { | ||
pluginsLoaded: function( evt ) { | ||
var editor = evt.editor; | ||
editor.ui.addButton( 'Replace', { | ||
label: editor.lang.find.replace, | ||
command: 'replace', | ||
icon: 'tests/_assets/sample_icon.png' | ||
} ); | ||
} | ||
} | ||
} | ||
}, { | ||
name: 'test overwriting default button icon (hidpi)', | ||
button: 'Replace', | ||
iconPath: /tests\/_assets\/sample_icon\.hidpi\.png/gi, | ||
config: { | ||
extraPlugins: 'find', | ||
toolbar: [ [ 'Replace' ] ], | ||
on: { | ||
pluginsLoaded: function( evt ) { | ||
var editor = evt.editor; | ||
editor.ui.addButton( 'Replace', { | ||
label: editor.lang.find.replace, | ||
command: 'replace', | ||
iconHiDpi: 'tests/_assets/sample_icon.hidpi.png' | ||
} ); | ||
} | ||
} | ||
} | ||
}, { | ||
name: 'test button icon from different plugin', | ||
button: 'custom_btn1', | ||
iconName: 'about', | ||
config: { | ||
extraPlugins: 'about', | ||
toolbar: [ [ 'custom_btn1' ] ], | ||
on: { | ||
pluginsLoaded: function( evt ) { | ||
evt.editor.ui.addButton( 'custom_btn1', { | ||
icon: 'about' | ||
} ); | ||
} | ||
} | ||
}, | ||
ignore: !isDev && CKEDITOR.env.hidpi | ||
}, { | ||
name: 'test button icon from different plugin (hidpi)', | ||
button: 'custom_btn2', | ||
iconName: 'blockquote', | ||
config: { | ||
extraPlugins: 'blockquote', | ||
toolbar: [ [ 'custom_btn2' ] ], | ||
on: { | ||
pluginsLoaded: function( evt ) { | ||
evt.editor.ui.addButton( 'custom_btn2', { | ||
icon: 'blockquote' | ||
} ); | ||
} | ||
} | ||
}, | ||
ignore: !isDev && !CKEDITOR.env.hidpi | ||
}, { | ||
name: 'test custom button icon', | ||
button: 'custom_btn3', | ||
iconPath: /tests\/_assets\/sample_icon\.png/gi, | ||
config: { | ||
toolbar: [ [ 'custom_btn3' ] ], | ||
on: { | ||
pluginsLoaded: function( evt ) { | ||
evt.editor.ui.addButton( 'custom_btn3', { | ||
icon: 'tests/_assets/sample_icon.png' | ||
} ); | ||
} | ||
} | ||
} | ||
}, { | ||
name: 'test custom button icon (hidpi)', | ||
button: 'custom_btn4', | ||
iconPath: /tests\/_assets\/sample_icon\.hidpi\.png/gi, | ||
config: { | ||
toolbar: [ [ 'custom_btn4' ] ], | ||
on: { | ||
pluginsLoaded: function( evt ) { | ||
evt.editor.ui.addButton( 'custom_btn4', { | ||
iconHiDpi: 'tests/_assets/sample_icon.hidpi.png' | ||
} ); | ||
} | ||
} | ||
} | ||
}, { | ||
name: 'test custom button icon-only (hidpi)', | ||
button: 'custom_btn5', | ||
iconPath: /tests\/_assets\/sample_icon\.png/gi, | ||
config: { | ||
toolbar: [ [ 'custom_btn5' ] ], | ||
on: { | ||
pluginsLoaded: function( evt ) { | ||
evt.editor.ui.addButton( 'custom_btn5', { | ||
icon: 'tests/_assets/sample_icon.png' | ||
} ); | ||
} | ||
} | ||
} | ||
}, { | ||
name: 'test custom button icon with different basepath', | ||
button: 'custom_btn6', | ||
iconPath: /different\/basepath\/assets\/icons\.sample\.png/gi, | ||
config: { | ||
toolbar: [ [ 'custom_btn6' ] ], | ||
on: { | ||
pluginsLoaded: function( evt ) { | ||
originalBasePath = CKEDITOR.basePath; | ||
CKEDITOR.basePath = '/different/basepath/'; | ||
evt.editor.ui.addButton( 'custom_btn6', { | ||
icon: 'assets/icons.sample.png' | ||
} ); | ||
} | ||
} | ||
} | ||
}, { | ||
name: 'test custom button icon with different basepath (hidpi)', | ||
button: 'custom_btn7', | ||
iconPath: /different\/basepath\/assets\/hidpi\/icons\.sample\.png/gi, | ||
config: { | ||
toolbar: [ [ 'custom_btn7' ] ], | ||
on: { | ||
pluginsLoaded: function( evt ) { | ||
originalBasePath = CKEDITOR.basePath; | ||
CKEDITOR.basePath = '/different/basepath/'; | ||
evt.editor.ui.addButton( 'custom_btn7', { | ||
icon: 'assets/hidpi/icons.sample.png' | ||
} ); | ||
} | ||
} | ||
} | ||
}, { | ||
name: 'test custom button icon with different basepath trailing slash', | ||
button: 'custom_btn8', | ||
iconPath: /['|(]\/assets\/icons\.sample\.png/gi, | ||
config: { | ||
toolbar: [ [ 'custom_btn8' ] ], | ||
on: { | ||
pluginsLoaded: function( evt ) { | ||
originalBasePath = CKEDITOR.basePath; | ||
CKEDITOR.basePath = '/different/basepath/'; | ||
evt.editor.ui.addButton( 'custom_btn8', { | ||
icon: '/assets/icons.sample.png' | ||
} ); | ||
} | ||
} | ||
} | ||
}, { | ||
name: 'test custom button icon with different basepath trailing slash (hidpi)', | ||
button: 'custom_btn9', | ||
iconPath: /['|(]\/assets\/hidpi\/icons\.sample\.png/gi, | ||
config: { | ||
toolbar: [ [ 'custom_btn9' ] ], | ||
on: { | ||
pluginsLoaded: function( evt ) { | ||
originalBasePath = CKEDITOR.basePath; | ||
CKEDITOR.basePath = '/different/basepath/'; | ||
evt.editor.ui.addButton( 'custom_btn9', { | ||
icon: '/assets/hidpi/icons.sample.png' | ||
} ); | ||
} | ||
} | ||
} | ||
} | ||
] ); | ||
|
||
bender.test( tests ); | ||
} )(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no test for adding custom icon for standard buttons (e.g.
Bold
). It should be possible by overwritingbutton.icon
property before rendering.