Skip to content

Commit 013be3c

Browse files
committed
Merge branch 't/10072' into major
2 parents 493f477 + 866b50f commit 013be3c

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

core/command.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ CKEDITOR.command = function( editor, commandDefinition ) {
4040
* @returns {Boolean} A boolean indicating that the command has been successfully executed.
4141
*/
4242
this.exec = function( data ) {
43-
if ( this.state == CKEDITOR.TRISTATE_DISABLED )
44-
return false;
45-
46-
// Test if this command is allowed.
47-
if ( !editor.filter.checkFeature( this ) )
43+
if ( this.state == CKEDITOR.TRISTATE_DISABLED || !this.checkAllowed() )
4844
return false;
4945

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

84+
var allowed;
85+
86+
/**
87+
* Checks whether this command is allowed by the allowed
88+
* content filter ({@link CKEDITOR.filter}). This means
89+
* that if command implements Feature interface it will be tested
90+
* by {@link CKEDITOR.filter.checkFeature}.
91+
*
92+
* @returns {Boolean} Whether command is allowed.
93+
*/
94+
this.checkAllowed = function() {
95+
if ( typeof allowed == 'boolean' )
96+
return allowed;
97+
98+
return allowed = editor.filter.checkFeature( this );
99+
};
100+
88101
CKEDITOR.tools.extend( this, commandDefinition, {
89102
/**
90103
* The editor modes within which the command can be executed. The
@@ -136,9 +149,9 @@ CKEDITOR.command = function( editor, commandDefinition ) {
136149
* if ( command.state == CKEDITOR.TRISTATE_DISABLED )
137150
* alert( 'This command is disabled' );
138151
*
139-
* @property {Number} [=CKEDITOR.TRISTATE_OFF]
152+
* @property {Number} [=CKEDITOR.TRISTATE_DISABLED]
140153
*/
141-
state: CKEDITOR.TRISTATE_OFF
154+
state: CKEDITOR.TRISTATE_DISABLED
142155
});
143156

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

@@ -184,7 +197,7 @@ CKEDITOR.command.prototype = {
184197
*/
185198
setState: function( newState ) {
186199
// Do nothing if there is no state change.
187-
if ( this.state == newState )
200+
if ( this.state == newState || !this.checkAllowed() )
188201
return false;
189202

190203
this.previousState = this.state;

0 commit comments

Comments
 (0)