JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4.2
[ckeditor.git] / _source / core / command.js
index 0a8d098..3c54807 100644 (file)
@@ -3,10 +3,44 @@ Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
 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
@@ -20,9 +54,56 @@ CKEDITOR.command = function( editor, commandDefinition )
 \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
@@ -32,17 +113,45 @@ CKEDITOR.command = function( editor, commandDefinition )
 \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
@@ -61,6 +170,12 @@ CKEDITOR.command.prototype =
                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
@@ -71,3 +186,24 @@ CKEDITOR.command.prototype =
 };\r
 \r
 CKEDITOR.event.implementOn( CKEDITOR.command.prototype, true );\r
+\r
+/**\r
+ * Indicates the preivous 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