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.uiItems = [];
|
---|
9 |
|
---|
10 | this.exec = function( data )
|
---|
11 | {
|
---|
12 | if ( this.state == CKEDITOR.TRISTATE_DISABLED )
|
---|
13 | return false;
|
---|
14 |
|
---|
15 | if( this.editorFocus ) // Give editor focus if necessary (#4355).
|
---|
16 | editor.focus();
|
---|
17 |
|
---|
18 | return ( commandDefinition.exec.call( this, editor, data ) !== false );
|
---|
19 | };
|
---|
20 |
|
---|
21 | CKEDITOR.tools.extend( this, commandDefinition,
|
---|
22 | // Defaults
|
---|
23 | {
|
---|
24 | modes : { wysiwyg : 1 },
|
---|
25 | editorFocus : true,
|
---|
26 | state : CKEDITOR.TRISTATE_OFF
|
---|
27 | });
|
---|
28 |
|
---|
29 | // Call the CKEDITOR.event constructor to initialize this instance.
|
---|
30 | CKEDITOR.event.call( this );
|
---|
31 | };
|
---|
32 |
|
---|
33 | CKEDITOR.command.prototype =
|
---|
34 | {
|
---|
35 | enable : function()
|
---|
36 | {
|
---|
37 | if ( this.state == CKEDITOR.TRISTATE_DISABLED )
|
---|
38 | this.setState( ( !this.preserveState || ( typeof this.previousState == 'undefined' ) ) ? CKEDITOR.TRISTATE_OFF : this.previousState );
|
---|
39 | },
|
---|
40 |
|
---|
41 | disable : function()
|
---|
42 | {
|
---|
43 | this.setState( CKEDITOR.TRISTATE_DISABLED );
|
---|
44 | },
|
---|
45 |
|
---|
46 | setState : function( newState )
|
---|
47 | {
|
---|
48 | // Do nothing if there is no state change.
|
---|
49 | if ( this.state == newState )
|
---|
50 | return false;
|
---|
51 |
|
---|
52 | this.previousState = this.state;
|
---|
53 |
|
---|
54 | // Set the new state.
|
---|
55 | this.state = newState;
|
---|
56 |
|
---|
57 | // Fire the "state" event, so other parts of the code can react to the
|
---|
58 | // change.
|
---|
59 | this.fire( 'state' );
|
---|
60 |
|
---|
61 | return true;
|
---|
62 | },
|
---|
63 |
|
---|
64 | toggleState : function()
|
---|
65 | {
|
---|
66 | if ( this.state == CKEDITOR.TRISTATE_OFF )
|
---|
67 | this.setState( CKEDITOR.TRISTATE_ON );
|
---|
68 | else if ( this.state == CKEDITOR.TRISTATE_ON )
|
---|
69 | this.setState( CKEDITOR.TRISTATE_OFF );
|
---|
70 | }
|
---|
71 | };
|
---|
72 |
|
---|
73 | CKEDITOR.event.implementOn( CKEDITOR.command.prototype, true );
|
---|