@@ -40,11 +40,7 @@ CKEDITOR.command = function( editor, commandDefinition ) {
40
40
* @returns {Boolean } A boolean indicating that the command has been successfully executed.
41
41
*/
42
42
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 ( ) )
48
44
return false ;
49
45
50
46
if ( this . editorFocus ) // Give editor focus if necessary (#4355).
@@ -85,6 +81,23 @@ CKEDITOR.command = function( editor, commandDefinition ) {
85
81
return ( commandDefinition . refresh && commandDefinition . refresh . apply ( this , arguments ) !== false ) ;
86
82
} ;
87
83
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
+
88
101
CKEDITOR . tools . extend ( this , commandDefinition , {
89
102
/**
90
103
* The editor modes within which the command can be executed. The
@@ -136,9 +149,9 @@ CKEDITOR.command = function( editor, commandDefinition ) {
136
149
* if ( command.state == CKEDITOR.TRISTATE_DISABLED )
137
150
* alert( 'This command is disabled' );
138
151
*
139
- * @property {Number } [=CKEDITOR.TRISTATE_OFF ]
152
+ * @property {Number } [=CKEDITOR.TRISTATE_DISABLED ]
140
153
*/
141
- state : CKEDITOR . TRISTATE_OFF
154
+ state : CKEDITOR . TRISTATE_DISABLED
142
155
} ) ;
143
156
144
157
// Call the CKEDITOR.event constructor to initialize this instance.
@@ -154,7 +167,7 @@ CKEDITOR.command.prototype = {
154
167
* command.exec(); // Execute the command.
155
168
*/
156
169
enable : function ( ) {
157
- if ( this . state == CKEDITOR . TRISTATE_DISABLED )
170
+ if ( this . state == CKEDITOR . TRISTATE_DISABLED && this . checkAllowed ( ) )
158
171
this . setState ( ( ! this . preserveState || ( typeof this . previousState == 'undefined' ) ) ? CKEDITOR . TRISTATE_OFF : this . previousState ) ;
159
172
} ,
160
173
@@ -184,7 +197,7 @@ CKEDITOR.command.prototype = {
184
197
*/
185
198
setState : function ( newState ) {
186
199
// Do nothing if there is no state change.
187
- if ( this . state == newState )
200
+ if ( this . state == newState || ! this . checkAllowed ( ) )
188
201
return false ;
189
202
190
203
this . previousState = this . state ;
0 commit comments