X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fcore%2Feditor.js;h=9801bbe3813105133542573e97d35606a3f445bc;hb=refs%2Ftags%2Fv3.6;hp=1e56a1265a949b692a90b10df83472dfd229a680;hpb=1056598c95187351dc58f4991d331e2258d038b5;p=ckeditor.git diff --git a/_source/core/editor.js b/_source/core/editor.js index 1e56a12..9801bbe 100644 --- a/_source/core/editor.js +++ b/_source/core/editor.js @@ -160,6 +160,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license */ editor.tabIndex = editor.config.tabIndex || editor.element.getAttribute( 'tabindex' ) || 0; + /** + * Indicates the read-only state of this editor. This is a read-only property. + * @name CKEDITOR.editor.prototype.readOnly + * @type Boolean + * @since 3.6 + * @see CKEDITOR.editor#setReadOnly + */ + editor.readOnly = !!( editor.config.readOnly || editor.element.getAttribute( 'disabled' ) ); + // Fire the "configLoaded" event. editor.fireOnce( 'configLoaded' ); @@ -394,16 +403,20 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } }; - function updateCommandsMode() + function updateCommands() { var command, commands = this._.commands, mode = this.mode; + if ( !mode ) + return; + for ( var name in commands ) { command = commands[ name ]; - command[ command.startDisabled ? 'disable' : command.modes[ mode ] ? 'enable' : 'disable' ](); + command[ command.startDisabled ? 'disable' : + this.readOnly && !command.readOnly ? 'disable' : command.modes[ mode ] ? 'enable' : 'disable' ](); } } @@ -491,7 +504,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license CKEDITOR.fire( 'instanceCreated', null, this ); - this.on( 'mode', updateCommandsMode, null, null, 1 ); + this.on( 'mode', updateCommands, null, null, 1 ); + this.on( 'readOnly', updateCommands, null, null, 1 ); initConfig( this, instanceConfig ); }; @@ -714,6 +728,28 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype, }, /** + * Puts or restores the editor into read-only state. When in read-only, + * the user is not able to change the editor contents, but still use + * some editor features. This function sets the readOnly property of + * the editor, firing the "readOnly" event.

+ * Note: the current editing area will be reloaded. + * @param {Boolean} [makeEditable] Indicates that the editor must be + * restored from read-only mode, making it editable. + * @since 3.6 + */ + setReadOnly : function( makeEditable ) + { + if ( this.readOnly != !makeEditable ) + { + this.readOnly = !makeEditable; + + // Fire the readOnly event so the editor features can update + // their state accordingly. + this.fire( 'readOnly' ); + } + }, + + /** * Inserts HTML into the currently selected position in the editor. * @param {String} data HTML code to be inserted into the editor. * @example @@ -841,6 +877,18 @@ CKEDITOR.on( 'loaded', function() */ /** + * If "true", makes the editor start in read-only state. Otherwise, it'll check + * if the linked <textarea> has the "disabled" attribute. + * @name CKEDITOR.config.readOnly + * @see CKEDITOR.editor#setReadOnly + * @type Boolean + * @default false + * @since 3.6 + * @example + * config.readOnly = true; + */ + +/** * Fired when a CKEDITOR instance is created, but still before initializing it. * To interact with a fully initialized instance, use the * {@link CKEDITOR#instanceReady} event instead. @@ -983,3 +1031,11 @@ CKEDITOR.on( 'loaded', function() * @param {CKEDITOR.editor} editor This editor instance. * @param {Object} element The element to insert. */ + +/** + * Event fired after {@link CKEDITOR.editor#readOnly} property changes. + * @name CKEDITOR.editor#readOnly + * @event + * @since 3.6 + * @param {CKEDITOR.editor} editor This editor instance. + */