Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #368 from cksource/t/17027
Commands event data should be initialized as an empty object
  • Loading branch information
mlewand committed May 12, 2017
2 parents 30ddd76 + b6ba3b1 commit abb2c09
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
12 changes: 6 additions & 6 deletions core/editor.js
Expand Up @@ -885,18 +885,18 @@
*
* editorInstance.execCommand( 'bold' );
*
* @param {String} commandName The indentifier name of the command.
* @param {Object} [data] The data to be passed to the command.
* @returns {Boolean} `true` if the command was executed
* successfully, otherwise `false`.
* @param {String} commandName The identifier name of the command.
* @param {Object} [data] The data to be passed to the command. It defaults to
* an empty object starting from 4.7.0.
* @returns {Boolean} `true` if the command was executed successfully, `false` otherwise.
* @see CKEDITOR.editor#addCommand
*/
execCommand: function( commandName, data ) {
var command = this.getCommand( commandName );

var eventData = {
name: commandName,
commandData: data,
commandData: data || {},
command: command
};

Expand Down Expand Up @@ -1572,7 +1572,7 @@ CKEDITOR.ELEMENT_MODE_INLINE = 3;
* @member CKEDITOR.config
*/

/**
/**
* Customizes the {@link CKEDITOR.editor#title human-readable title} of this editor. This title is displayed in
* tooltips and impacts various [accessibility aspects](#!/guide/dev_a11y-section-announcing-the-editor-on-the-page),
* e.g. it is commonly used by screen readers for distinguishing editor instances and for navigation.
Expand Down
25 changes: 24 additions & 1 deletion tests/core/command/events.js
Expand Up @@ -34,6 +34,29 @@

this.editor.execCommand( 'mockupCommand' );
assert.isTrue( cmdCalled, 'Command should be called' );
},

// #17027
'test default event data value': function() {
var beforeExecData;

this.editor.once( 'beforeCommandExec', function( evt ) {
beforeExecData = evt.data.commandData;

assert.isObject( beforeExecData, 'Event data is initialized as an empty object' );
} );

this.editor.once( 'afterCommandExec', function( evt ) {
assert.areSame( beforeExecData, evt.data.commandData, 'The same object is passed to afterCommandExec' );
} );

this.editor.addCommand( 'dataFlow', {
exec: function( editor, data ) {
assert.areSame( beforeExecData, data, 'Same object is given as data' );
}
} );

this.editor.execCommand( 'dataFlow' );
}
} );
} )();
} )();

0 comments on commit abb2c09

Please sign in to comment.