JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6
[ckeditor.git] / _source / core / editor.js
index 1e56a12..9801bbe 100644 (file)
@@ -160,6 +160,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                 */\r
                editor.tabIndex = editor.config.tabIndex || editor.element.getAttribute( 'tabindex' ) || 0;\r
 \r
+               /**\r
+                * Indicates the read-only state of this editor. This is a read-only property.\r
+                * @name CKEDITOR.editor.prototype.readOnly\r
+                * @type Boolean\r
+                * @since 3.6\r
+                * @see CKEDITOR.editor#setReadOnly\r
+                */\r
+               editor.readOnly = !!( editor.config.readOnly || editor.element.getAttribute( 'disabled' ) );\r
+\r
                // Fire the "configLoaded" event.\r
                editor.fireOnce( 'configLoaded' );\r
 \r
@@ -394,16 +403,20 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                }\r
        };\r
 \r
-       function updateCommandsMode()\r
+       function updateCommands()\r
        {\r
                var command,\r
                        commands = this._.commands,\r
                        mode = this.mode;\r
 \r
+               if ( !mode )\r
+                       return;\r
+\r
                for ( var name in commands )\r
                {\r
                        command = commands[ name ];\r
-                       command[ command.startDisabled ? 'disable' : command.modes[ mode ] ? 'enable' : 'disable' ]();\r
+                       command[ command.startDisabled ? 'disable' :\r
+                                        this.readOnly && !command.readOnly ? 'disable' : command.modes[ mode ] ? 'enable' : 'disable' ]();\r
                }\r
        }\r
 \r
@@ -491,7 +504,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                        CKEDITOR.fire( 'instanceCreated', null, this );\r
 \r
-                       this.on( 'mode', updateCommandsMode, null, null, 1 );\r
+                       this.on( 'mode', updateCommands, null, null, 1 );\r
+                       this.on( 'readOnly', updateCommands, null, null, 1 );\r
 \r
                        initConfig( this, instanceConfig );\r
                };\r
@@ -714,6 +728,28 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                },\r
 \r
                /**\r
+                * Puts or restores the editor into read-only state. When in read-only,\r
+                * the user is not able to change the editor contents, but still use\r
+                * some editor features. This function sets the readOnly property of\r
+                * the editor, firing the "readOnly" event.<br><br>\r
+                * <strong>Note:</strong> the current editing area will be reloaded.\r
+                * @param {Boolean} [makeEditable] Indicates that the editor must be\r
+                *              restored from read-only mode, making it editable.\r
+                * @since 3.6\r
+                */\r
+               setReadOnly : function( makeEditable )\r
+               {\r
+                       if ( this.readOnly != !makeEditable )\r
+                       {\r
+                               this.readOnly = !makeEditable;\r
+\r
+                               // Fire the readOnly event so the editor features can update\r
+                               // their state accordingly.\r
+                               this.fire( 'readOnly' );\r
+                       }\r
+               },\r
+\r
+               /**\r
                 * Inserts HTML into the currently selected position in the editor.\r
                 * @param {String} data HTML code to be inserted into the editor.\r
                 * @example\r
@@ -841,6 +877,18 @@ CKEDITOR.on( 'loaded', function()
  */\r
 \r
 /**\r
+ * If "true", makes the editor start in read-only state. Otherwise, it'll check\r
+ * if the linked &lt;textarea&gt; has the "disabled" attribute.\r
+ * @name CKEDITOR.config.readOnly\r
+ * @see CKEDITOR.editor#setReadOnly\r
+ * @type Boolean\r
+ * @default false\r
+ * @since 3.6\r
+ * @example\r
+ * config.readOnly = true;\r
+ */\r
+\r
+/**\r
  * Fired when a CKEDITOR instance is created, but still before initializing it.\r
  * To interact with a fully initialized instance, use the\r
  * {@link CKEDITOR#instanceReady} event instead.\r
@@ -983,3 +1031,11 @@ CKEDITOR.on( 'loaded', function()
  * @param {CKEDITOR.editor} editor This editor instance.\r
  * @param {Object} element The element to insert.\r
  */\r
+\r
+/**\r
+ * Event fired after {@link CKEDITOR.editor#readOnly} property changes.\r
+ * @name CKEDITOR.editor#readOnly\r
+ * @event\r
+ * @since 3.6\r
+ * @param {CKEDITOR.editor} editor This editor instance.\r
+ */\r