2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
6 CKEDITOR.command = function( editor, commandDefinition )
\r
10 this.exec = function( data )
\r
12 if ( this.state == CKEDITOR.TRISTATE_DISABLED )
\r
15 if ( this.editorFocus ) // Give editor focus if necessary (#4355).
\r
18 return ( commandDefinition.exec.call( this, editor, data ) !== false );
\r
21 CKEDITOR.tools.extend( this, commandDefinition,
\r
24 modes : { wysiwyg : 1 },
\r
26 state : CKEDITOR.TRISTATE_OFF
\r
29 // Call the CKEDITOR.event constructor to initialize this instance.
\r
30 CKEDITOR.event.call( this );
\r
33 CKEDITOR.command.prototype =
\r
37 if ( this.state == CKEDITOR.TRISTATE_DISABLED )
\r
38 this.setState( ( !this.preserveState || ( typeof this.previousState == 'undefined' ) ) ? CKEDITOR.TRISTATE_OFF : this.previousState );
\r
41 disable : function()
\r
43 this.setState( CKEDITOR.TRISTATE_DISABLED );
\r
46 setState : function( newState )
\r
48 // Do nothing if there is no state change.
\r
49 if ( this.state == newState )
\r
52 this.previousState = this.state;
\r
54 // Set the new state.
\r
55 this.state = newState;
\r
57 // Fire the "state" event, so other parts of the code can react to the
\r
59 this.fire( 'state' );
\r
64 toggleState : function()
\r
66 if ( this.state == CKEDITOR.TRISTATE_OFF )
\r
67 this.setState( CKEDITOR.TRISTATE_ON );
\r
68 else if ( this.state == CKEDITOR.TRISTATE_ON )
\r
69 this.setState( CKEDITOR.TRISTATE_OFF );
\r
73 CKEDITOR.event.implementOn( CKEDITOR.command.prototype, true );
\r