2 Copyright (c) 2003-2009, 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
8 this.exec = function( data )
\r
10 if ( this.state == CKEDITOR.TRISTATE_DISABLED )
\r
13 // The editor will always have the focus when executing a command.
\r
16 return ( commandDefinition.exec.call( this, editor, data ) !== false );
\r
19 CKEDITOR.tools.extend( this, commandDefinition,
\r
22 modes : { wysiwyg : 1 },
\r
23 state : CKEDITOR.TRISTATE_OFF
\r
26 // Call the CKEDITOR.event constructor to initialize this instance.
\r
27 CKEDITOR.event.call( this );
\r
30 CKEDITOR.command.prototype =
\r
34 if ( this.state == CKEDITOR.TRISTATE_DISABLED )
\r
35 this.setState( ( !this.preserveState || ( typeof this.previousState == 'undefined' ) ) ? CKEDITOR.TRISTATE_OFF : this.previousState );
\r
38 disable : function()
\r
40 this.setState( CKEDITOR.TRISTATE_DISABLED );
\r
43 setState : function( newState )
\r
45 // Do nothing if there is no state change.
\r
46 if ( this.state == newState )
\r
49 this.previousState = this.state;
\r
51 // Set the new state.
\r
52 this.state = newState;
\r
54 // Fire the "state" event, so other parts of the code can react to the
\r
56 this.fire( 'state' );
\r
61 toggleState : function()
\r
63 if ( this.state == CKEDITOR.TRISTATE_OFF )
\r
64 this.setState( CKEDITOR.TRISTATE_ON );
\r
65 else if ( this.state == CKEDITOR.TRISTATE_ON )
\r
66 this.setState( CKEDITOR.TRISTATE_OFF );
\r
70 CKEDITOR.event.implementOn( CKEDITOR.command.prototype, true );
\r