JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6
[ckeditor.git] / _source / core / editor.js
index d66aac9..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
@@ -272,7 +281,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                // is not available, get the first one (default one).\r
                                                lang = ( CKEDITOR.tools.indexOf( pluginLangs, editor.langCode ) >= 0 ? editor.langCode : pluginLangs[ 0 ] );\r
 \r
-                                               if ( !plugin.lang[ lang ] )\r
+                                               if ( !plugin.langEntries || !plugin.langEntries[ lang ] )\r
                                                {\r
                                                        // Put the language file URL into the list of files to\r
                                                        // get downloaded.\r
@@ -280,7 +289,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                }\r
                                                else\r
                                                {\r
-                                                       CKEDITOR.tools.extend( editor.lang, plugin.lang[ lang ] );\r
+                                                       CKEDITOR.tools.extend( editor.lang, plugin.langEntries[ lang ] );\r
                                                        lang = null;\r
                                                }\r
                                        }\r
@@ -305,7 +314,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                                                // Uses the first loop to update the language entries also.\r
                                                                if ( m === 0 && languageCodes[ i ] && plugin.lang )\r
-                                                                       CKEDITOR.tools.extend( editor.lang, plugin.lang[ languageCodes[ i ] ] );\r
+                                                                       CKEDITOR.tools.extend( editor.lang, plugin.langEntries[ languageCodes[ i ] ] );\r
 \r
                                                                // Call the plugin method (beforeInit and init).\r
                                                                if ( plugin[ methods[ m ] ] )\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
@@ -561,7 +575,7 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                 * @returns {Boolean} "true" if the command has been successfuly\r
                 *              executed, otherwise "false".\r
                 * @example\r
-                * editorInstance.execCommand( 'Bold' );\r
+                * editorInstance.execCommand( 'bold' );\r
                 */\r
                execCommand : function( commandName, data )\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