-
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
Balloon toolbar on destroy doesn't destroy its content #1482
Conversation
CHANGES.md
Outdated
@@ -24,6 +24,7 @@ Fixed Issues: | |||
* [#1356](https://github.com/ckeditor/ckeditor-dev/issues/1356): Fixed: [Border parse function](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.tools.style.parse-method-border) should allow spaces in the color value. | |||
* [#1426](https://github.com/ckeditor/ckeditor-dev/issues/1426): [IE8-9] Fixed: Missing balloon toolbar background in Kama skin. Thanks to [Christian Elmer](https://github.com/keinkurt)! | |||
* [#1010](https://github.com/ckeditor/ckeditor-dev/issues/1010): Fixed: CSS `border` shorthand property was incorrectly expanded ignoring `border-color` style. | |||
* [#1477](https://github.com/ckeditor/ckeditor-dev/issues/1477): Fixed: Balloon toolbar on destroy doesn't destroy its content. |
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.
Please link plugin.
plugins/balloontoolbar/plugin.js
Outdated
@@ -131,6 +131,7 @@ | |||
* @param {CKEDITOR.ui.button/CKEDITOR.ui.richCombo} element Instance of ui element. | |||
*/ | |||
CKEDITOR.ui.balloonToolbar.prototype.addItem = function( name, element ) { | |||
// console.log( this._items[ name ] ); |
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.
What's this? 😛
plugins/balloontoolbar/plugin.js
Outdated
* Hides the toolbar and removes it from the DOM. | ||
* Cleares Balloon Toolbar from each menu items. | ||
* | ||
* @since 4.9.0 |
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.
Please update version tag.
plugins/richcombo/plugin.js
Outdated
/** | ||
* Removes all listeners from richCombo element. | ||
* | ||
* @since 4.9.0 |
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.
Please update version tag.
@@ -0,0 +1,49 @@ | |||
/* bender-tags: balloontoolbar, 1477, 4.9.0 */ |
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.
Please update version tag.
@@ -0,0 +1,15 @@ | |||
@bender-ui: collapsed | |||
@bender-tags: 4.9.0 bug, 1477, balloontoolbar |
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.
Please update version tag.
plugins/balloontoolbar/plugin.js
Outdated
@@ -169,9 +170,24 @@ | |||
}; | |||
|
|||
/** | |||
* Hides the toolbar and removes it from the DOM. | |||
* Cleares Balloon Toolbar from each menu items. |
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.
Some better API docs would be nice, e.g. note that it invokes destroy
method of every item.
plugins/balloontoolbar/plugin.js
Outdated
* | ||
* @since 4.9.0 | ||
*/ | ||
CKEDITOR.ui.balloonToolbar.prototype.clearItems = function() { |
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.
I'm wondering if this method should be public. I don't see any real use-cases for it except of destroying the toolbar.
plugins/richcombo/plugin.js
Outdated
* @since 4.9.0 | ||
*/ | ||
destroy: function() { | ||
if ( this._listeners.length ) { |
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.
IMO this check is totally unnecessary. forEach
loop would work totally fine with empty array.
|
||
## Unexpected: | ||
|
||
1. Console throws an error. |
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.
If we use console here, it's nice to include opening console inside the procedure. Also it makes this test mobile unfriendly, so it should be ignored in mobile environments.
9996246
to
19d88d2
Compare
} | ||
panel.destroy(); | ||
|
||
items.forEach( function( item ) { |
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.
IMO such condition could be nicer expressed using CKEDITOR.tools.array.every
:
var listenersDeleted = CKEDITOR.tools.array.every( items, function( item ) {
return !( item instanceof CKEDITOR.ui.richCombo ) || item._listeners.length === 0;
};
assert.isTrue( listenersDeleted, 'All listeners are deleted' );
Please also note the move of the assertion itself. In fact we are interested in deleting all listeners, not individual ones.
*/ | ||
CKEDITOR.ui.balloonToolbar.prototype.destroy = function() { | ||
for ( var key in this._items ) { |
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.
Maybe I'm already a bit biased, but CKEDITOR.tools.forEach
+ CKEDITOR.tools.objectKeys
looks better to me.
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.
Actually I adapted your suggestion in other place. However I think for in
loop is fine here.
plugins/richcombo/plugin.js
Outdated
@@ -96,6 +96,8 @@ CKEDITOR.plugins.add( 'richcombo', { | |||
panelDefinition: panelDefinition, | |||
items: {} | |||
}; | |||
|
|||
this._listeners = []; |
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.
IMO it'd be nice to add some API docs for this private property.
@@ -0,0 +1,16 @@ | |||
@bender-ui: collapsed | |||
@bender-tags: 4.11.0 bug, 1477, balloontoolbar |
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.
Missing comma after version tag.
19d88d2
to
2903d65
Compare
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.
LGTM, there is only one thing I miss: unit test for richcombo. At the moment it's tested only inside balloon toolbar.
plugins/richcombo/plugin.js
Outdated
* Array containing richCombos registered listeners. | ||
* | ||
* @private | ||
*/ |
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 missing type of this property. It'd be ideal to use dedicated type (see #2383), but some more generic approach would be also enough.
52d55c9
to
d18afa9
Compare
plugins/richcombo/plugin.js
Outdated
* @type {Array} | ||
* @private | ||
*/ | ||
this._listeners = []; |
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.
I didn't notice it earlier 😐 but we don't need new _
-variable as we already have _
namespace here to put private stuff inside. In such case we could even omit the docs. Please update the code from _listeners
to _.listeners
. And sorry for not noticing it earlier 😞
7c01738
to
11a1214
Compare
}; | ||
|
||
var tests = { | ||
'test destroy toolbar with richcombo': function() { |
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.
This test does not test anything. Array passed to CKEDITOR.tools.array.every
is empty, therefore test always passes.
panel.destroy(); | ||
|
||
var listenersDeleted = CKEDITOR.tools.array.every( items, function( item ) { | ||
return !( item instanceof CKEDITOR.ui.richCombo ) || item._listeners.length === 0; |
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.
I discovered it by this typo: instead of item._listeners
item._.listeners
.
tests/plugins/richcombo/richcombo.js
Outdated
@@ -38,5 +38,21 @@ bender.test( { | |||
anchorEl = CKEDITOR.document.getById( 'cke_' + combo.id ).findOne( 'a' ); | |||
|
|||
assert.areEqual( anchorEl.getAttribute( 'aria-haspopup' ), 'listbox' ); | |||
}, | |||
'test destroy removes combo listeners': function() { |
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.
Please add issue reference.
plugins/richcombo/plugin.js
Outdated
* @type {Array} | ||
* @private | ||
*/ | ||
this._.listeners = []; |
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.
If we add it to _
namespace, API docs are not needed. It would be even weird to document only one property of it. Let's just add listeners
array to the object literal above.
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.
I guess every piece of extra information might be helpful in future especially if it's already written, but I guess this property is so obvious we can drop docs, and move it to the object literal.
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.
LGTM!
What is the purpose of this pull request?
Bugfix
Does your PR contain necessary tests?
All patches which change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.
This PR contains
What changes did you make?
I've made balloonToolbar
destroy
to call alsodestroy
on each of its_items
. And addeddestroy
method to richCombo, which removes all listeners from it.Closes #1477