Skip to content

Commit

Permalink
Merge branch 't/10072' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Feb 20, 2013
2 parents 493f477 + 866b50f commit 013be3c
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions core/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ CKEDITOR.command = function( editor, commandDefinition ) {
* @returns {Boolean} A boolean indicating that the command has been successfully executed.
*/
this.exec = function( data ) {
if ( this.state == CKEDITOR.TRISTATE_DISABLED )
return false;

// Test if this command is allowed.
if ( !editor.filter.checkFeature( this ) )
if ( this.state == CKEDITOR.TRISTATE_DISABLED || !this.checkAllowed() )
return false;

if ( this.editorFocus ) // Give editor focus if necessary (#4355).
Expand Down Expand Up @@ -85,6 +81,23 @@ CKEDITOR.command = function( editor, commandDefinition ) {
return ( commandDefinition.refresh && commandDefinition.refresh.apply( this, arguments ) !== false );
};

var allowed;

/**
* Checks whether this command is allowed by the allowed
* content filter ({@link CKEDITOR.filter}). This means
* that if command implements Feature interface it will be tested
* by {@link CKEDITOR.filter.checkFeature}.
*
* @returns {Boolean} Whether command is allowed.
*/
this.checkAllowed = function() {
if ( typeof allowed == 'boolean' )
return allowed;

return allowed = editor.filter.checkFeature( this );
};

CKEDITOR.tools.extend( this, commandDefinition, {
/**
* The editor modes within which the command can be executed. The
Expand Down Expand Up @@ -136,9 +149,9 @@ CKEDITOR.command = function( editor, commandDefinition ) {
* if ( command.state == CKEDITOR.TRISTATE_DISABLED )
* alert( 'This command is disabled' );
*
* @property {Number} [=CKEDITOR.TRISTATE_OFF]
* @property {Number} [=CKEDITOR.TRISTATE_DISABLED]
*/
state: CKEDITOR.TRISTATE_OFF
state: CKEDITOR.TRISTATE_DISABLED
});

// Call the CKEDITOR.event constructor to initialize this instance.
Expand All @@ -154,7 +167,7 @@ CKEDITOR.command.prototype = {
* command.exec(); // Execute the command.
*/
enable: function() {
if ( this.state == CKEDITOR.TRISTATE_DISABLED )
if ( this.state == CKEDITOR.TRISTATE_DISABLED && this.checkAllowed() )
this.setState( ( !this.preserveState || ( typeof this.previousState == 'undefined' ) ) ? CKEDITOR.TRISTATE_OFF : this.previousState );
},

Expand Down Expand Up @@ -184,7 +197,7 @@ CKEDITOR.command.prototype = {
*/
setState: function( newState ) {
// Do nothing if there is no state change.
if ( this.state == newState )
if ( this.state == newState || !this.checkAllowed() )
return false;

this.previousState = this.state;
Expand Down

0 comments on commit 013be3c

Please sign in to comment.