/*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
For licensing, see LICENSE.html or http://ckeditor.com/license\r
*/\r
\r
+/**\r
+ * Creates a command class instance.\r
+ * @class Represents a command that can be executed on an editor instance.\r
+ * @param {CKEDITOR.editor} editor The editor instance this command will be\r
+ * related to.\r
+ * @param {CKEDITOR.commandDefinition} commandDefinition The command\r
+ * definition.\r
+ * @augments CKEDITOR.event\r
+ * @example\r
+ * var command = new CKEDITOR.command( editor,\r
+ * {\r
+ * exec : function( editor )\r
+ * {\r
+ * alert( editor.document.getBody().getHtml() );\r
+ * }\r
+ * });\r
+ */\r
CKEDITOR.command = function( editor, commandDefinition )\r
{\r
+ /**\r
+ * Lists UI items that are associated to this command. This list can be\r
+ * used to interact with the UI on command execution (by the execution code\r
+ * itself, for example).\r
+ * @type Array\r
+ * @example\r
+ * alert( 'Number of UI items associated to this command: ' + command.<b>uiItems</b>.length );\r
+ */\r
this.uiItems = [];\r
\r
+ /**\r
+ * Executes the command.\r
+ * @param {Object} [data] Any data to pass to the command. Depends on the\r
+ * command implementation and requirements.\r
+ * @returns {Boolean} A boolean indicating that the command has been\r
+ * successfully executed.\r
+ * @example\r
+ * command.<b>exec()</b>; // The command gets executed.\r
+ */\r
this.exec = function( data )\r
{\r
if ( this.state == CKEDITOR.TRISTATE_DISABLED )\r
return false;\r
\r
- if( this.editorFocus ) // Give editor focus if necessary (#4355).\r
+ if ( this.editorFocus ) // Give editor focus if necessary (#4355).\r
editor.focus();\r
\r
return ( commandDefinition.exec.call( this, editor, data ) !== false );\r
\r
CKEDITOR.tools.extend( this, commandDefinition,\r
// Defaults\r
+ /** @lends CKEDITOR.command.prototype */\r
{\r
+ /**\r
+ * The editor modes within which the command can be executed. The\r
+ * execution will have no action if the current mode is not listed\r
+ * in this property.\r
+ * @type Object\r
+ * @default { wysiwyg : 1 }\r
+ * @see CKEDITOR.editor.prototype.mode\r
+ * @example\r
+ * // Enable the command in both WYSIWYG and Source modes.\r
+ * command.<b>modes</b> = { wysiwyg : 1, source : 1 };\r
+ * @example\r
+ * // Enable the command in Source mode only.\r
+ * command.<b>modes</b> = { source : 1 };\r
+ */\r
modes : { wysiwyg : 1 },\r
- editorFocus : true,\r
+\r
+ /**\r
+ * Indicates that the editor will get the focus before executing\r
+ * the command.\r
+ * @type Boolean\r
+ * @default true\r
+ * @example\r
+ * // Do not force the editor to have focus when executing the command.\r
+ * command.<b>editorFocus</b> = false;\r
+ */\r
+ editorFocus : 1,\r
+\r
+ /**\r
+ * Indicates the editor state. Possible values are:\r
+ * <ul>\r
+ * <li>{@link CKEDITOR.TRISTATE_DISABLED}: the command is\r
+ * disabled. It's execution will have no effect. Same as\r
+ * {@link disable}.</li>\r
+ * <li>{@link CKEDITOR.TRISTATE_ON}: the command is enabled\r
+ * and currently active in the editor (for context sensitive commands,\r
+ * for example).</li>\r
+ * <li>{@link CKEDITOR.TRISTATE_OFF}: the command is enabled\r
+ * and currently inactive in the editor (for context sensitive\r
+ * commands, for example).</li>\r
+ * </ul>\r
+ * Do not set this property directly, using the {@link #setState}\r
+ * method instead.\r
+ * @type Number\r
+ * @default {@link CKEDITOR.TRISTATE_OFF}\r
+ * @example\r
+ * if ( command.<b>state</b> == CKEDITOR.TRISTATE_DISABLED )\r
+ * alert( 'This command is disabled' );\r
+ */\r
state : CKEDITOR.TRISTATE_OFF\r
});\r
\r
\r
CKEDITOR.command.prototype =\r
{\r
+ /**\r
+ * Enables the command for execution. The command state (see\r
+ * {@link CKEDITOR.command.prototype.state}) available before disabling it\r
+ * is restored.\r
+ * @example\r
+ * command.<b>enable()</b>;\r
+ * command.exec(); // Execute the command.\r
+ */\r
enable : function()\r
{\r
if ( this.state == CKEDITOR.TRISTATE_DISABLED )\r
this.setState( ( !this.preserveState || ( typeof this.previousState == 'undefined' ) ) ? CKEDITOR.TRISTATE_OFF : this.previousState );\r
},\r
\r
+ /**\r
+ * Disables the command for execution. The command state (see\r
+ * {@link CKEDITOR.command.prototype.state}) will be set to\r
+ * {@link CKEDITOR.TRISTATE_DISABLED}.\r
+ * @example\r
+ * command.<b>disable()</b>;\r
+ * command.exec(); // "false" - Nothing happens.\r
+ */\r
disable : function()\r
{\r
this.setState( CKEDITOR.TRISTATE_DISABLED );\r
},\r
\r
+ /**\r
+ * Sets the command state.\r
+ * @param {Number} newState The new state. See {@link #state}.\r
+ * @returns {Boolean} Returns "true" if the command state changed.\r
+ * @example\r
+ * command.<b>setState( CKEDITOR.TRISTATE_ON )</b>;\r
+ * command.exec(); // Execute the command.\r
+ * command.<b>setState( CKEDITOR.TRISTATE_DISABLED )</b>;\r
+ * command.exec(); // "false" - Nothing happens.\r
+ * command.<b>setState( CKEDITOR.TRISTATE_OFF )</b>;\r
+ * command.exec(); // Execute the command.\r
+ */\r
setState : function( newState )\r
{\r
// Do nothing if there is no state change.\r
return true;\r
},\r
\r
+ /**\r
+ * Toggles the on/off (active/inactive) state of the command. This is\r
+ * mainly used internally by context sensitive commands.\r
+ * @example\r
+ * command.<b>toggleState()</b>;\r
+ */\r
toggleState : function()\r
{\r
if ( this.state == CKEDITOR.TRISTATE_OFF )\r
};\r
\r
CKEDITOR.event.implementOn( CKEDITOR.command.prototype, true );\r
+\r
+/**\r
+ * Indicates the previous command state.\r
+ * @name CKEDITOR.command.prototype.previousState\r
+ * @type Number\r
+ * @see #state\r
+ * @example\r
+ * alert( command.<b>previousState</b> );\r
+ */\r
+\r
+/**\r
+ * Fired when the command state changes.\r
+ * @name CKEDITOR.command#state\r
+ * @event\r
+ * @example\r
+ * command.on( <b>'state'</b> , function( e )\r
+ * {\r
+ * // Alerts the new state.\r
+ * alert( this.state );\r
+ * });\r
+ */\r