1 /* 2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. 3 For licensing, see LICENSE.html or http://ckeditor.com/license 4 */ 5 6 CKEDITOR.command = function( editor, commandDefinition ) 7 { 8 this.exec = function( data ) 9 { 10 if ( this.state == CKEDITOR.TRISTATE_DISABLED ) 11 return false; 12 13 return ( commandDefinition.exec.call( this, editor, data ) !== false ); 14 }; 15 16 CKEDITOR.tools.extend( this, commandDefinition, 17 // Defaults 18 { 19 modes : { wysiwyg : 1 }, 20 state : CKEDITOR.TRISTATE_OFF 21 }); 22 23 // Call the CKEDITOR.event constructor to initialize this instance. 24 CKEDITOR.event.call( this ); 25 }; 26 27 CKEDITOR.command.prototype = 28 { 29 setState : function( newState ) 30 { 31 // Do nothing if there is no state change. 32 if ( this.state == newState ) 33 return false; 34 35 // Set the new state. 36 this.state = newState; 37 38 // Fire the "state" event, so other parts of the code can react to the 39 // change. 40 this.fire( 'state' ); 41 42 return true; 43 }, 44 45 toggleState : function() 46 { 47 if ( this.state == CKEDITOR.TRISTATE_OFF ) 48 this.setState( CKEDITOR.TRISTATE_ON ); 49 else if ( this.state == CKEDITOR.TRISTATE_ON ) 50 this.setState( CKEDITOR.TRISTATE_OFF ); 51 } 52 } 53 54 CKEDITOR.event.implementOn( CKEDITOR.command.prototype, true ); 55