Index: _source/plugins/showblocks/plugin.js
===================================================================
--- _source/plugins/showblocks/plugin.js (revision 6660)
+++ _source/plugins/showblocks/plugin.js (revision )
@@ -89,6 +89,7 @@
var commandDefinition =
{
+ readOnly : 1,
preserveState : true,
editorFocus : false,
Index: _samples/readonly.html
===================================================================
--- _samples/readonly.html (revision )
+++ _samples/readonly.html (revision )
@@ -0,0 +1,90 @@
+
+
+
+
+ Read-only — CKEditor Sample
+
+
+
+
+
+
+
+
+
+
+
+ CKEditor Sample — Using CKEditor ReadOnly API
+
+
+
+ This sample shows how to use the
+ set read-only
+ API to put editor into an immutable state.
+
+
+ For details on how to create this setup check the source code of this sample page.
+
+
+
+
+
+
+
+
+
+
+
Index: _source/plugins/about/plugin.js
===================================================================
--- _source/plugins/about/plugin.js (revision 6660)
+++ _source/plugins/about/plugin.js (revision )
@@ -11,6 +11,7 @@
var command = editor.addCommand( 'about', new CKEDITOR.dialogCommand( 'about' ) );
command.modes = { wysiwyg:1, source:1 };
command.canUndo = false;
+ command.readOnly = 1;
editor.ui.addButton( 'About',
{
Index: _source/plugins/save/plugin.js
===================================================================
--- _source/plugins/save/plugin.js (revision 6660)
+++ _source/plugins/save/plugin.js (revision )
@@ -12,6 +12,7 @@
var saveCmd =
{
modes : { wysiwyg:1, source:1 },
+ readOnly : 1,
exec : function( editor )
{
Index: _source/plugins/showborders/plugin.js
===================================================================
--- _source/plugins/showborders/plugin.js (revision 6660)
+++ _source/plugins/showborders/plugin.js (revision )
@@ -40,6 +40,7 @@
{
preserveState : true,
editorFocus : false,
+ readOnly: 1,
exec : function ( editor )
{
Index: _source/plugins/basicstyles/plugin.js
===================================================================
--- _source/plugins/basicstyles/plugin.js (revision 6660)
+++ _source/plugins/basicstyles/plugin.js (revision )
@@ -17,7 +17,7 @@
editor.attachStyleStateChange( style, function( state )
{
- editor.getCommand( commandName ).setState( state );
+ !editor.readOnly && editor.getCommand( commandName ).setState( state );
});
editor.addCommand( commandName, new CKEDITOR.styleCommand( style ) );
Index: _source/plugins/editingblock/plugin.js
===================================================================
--- _source/plugins/editingblock/plugin.js (revision 6660)
+++ _source/plugins/editingblock/plugin.js (revision )
@@ -113,6 +113,11 @@
}, 0 );
});
+ // Force reload the mode to refresh all command states.
+ editor.on( 'readOnly', function() {
+ this.setMode( this.mode || this.config.startupMode, 1 );
+ });
+
editor.on( 'destroy', function ()
{
// -> currentMode.unload( holderElement );
@@ -151,7 +156,7 @@
* // Switch to "source" view.
* CKEDITOR.instances.editor1.setMode( 'source' );
*/
- CKEDITOR.editor.prototype.setMode = function( mode )
+ CKEDITOR.editor.prototype.setMode = function( mode, forceReload )
{
this.fire( 'beforeSetMode', { newMode : mode } );
@@ -162,7 +167,7 @@
// Unload the previous mode.
if ( this.mode )
{
- if ( mode == this.mode )
+ if ( !forceReload && mode == this.mode )
return;
this.fire( 'beforeModeUnload' );
Index: _source/plugins/justify/plugin.js
===================================================================
--- _source/plugins/justify/plugin.js (revision 6660)
+++ _source/plugins/justify/plugin.js (revision )
@@ -49,6 +49,9 @@
function onSelectionChange( evt )
{
+ if ( evt.editor.readOnly )
+ return;
+
var command = evt.editor.getCommand( this.name );
command.state = getState.call( this, evt.editor, evt.data.path );
command.fire( 'state' );
Index: _source/core/dom/range.js
===================================================================
--- _source/core/dom/range.js (revision 6682)
+++ _source/core/dom/range.js (revision )
@@ -1870,7 +1870,7 @@
return 0;
}
// Range enclosed entirely in an editable element.
- else if ( node.is( 'body' )
+ else if ( node.is( 'html' )
|| node.getAttribute( 'contentEditable' ) == 'true'
&& ( node.contains( anotherEnd ) || node.equals( anotherEnd ) ) )
{
Index: _source/plugins/selection/plugin.js
===================================================================
--- _source/plugins/selection/plugin.js (revision 6660)
+++ _source/plugins/selection/plugin.js (revision )
@@ -92,6 +92,7 @@
var selectAllCmd =
{
modes : { wysiwyg : 1, source : 1 },
+ readOnly : CKEDITOR.env.ie || CKEDITOR.env.webkit,
exec : function( editor )
{
switch ( editor.mode )
Index: _source/plugins/find/plugin.js
===================================================================
--- _source/plugins/find/plugin.js (revision 6660)
+++ _source/plugins/find/plugin.js (revision )
@@ -15,6 +15,7 @@
});
var findCommand = editor.addCommand( 'find', new CKEDITOR.dialogCommand( 'find' ) );
findCommand.canUndo = false;
+ findCommand.readOnly = 1;
editor.ui.addButton( 'Replace',
{
Index: _source/plugins/find/dialogs/find.js
===================================================================
--- _source/plugins/find/dialogs/find.js (revision 6681)
+++ _source/plugins/find/dialogs/find.js (revision )
@@ -854,6 +854,9 @@
finder.searchRange = getSearchRange();
this.selectPage( startupPage );
+
+ if ( startupPage == 'find' && this._.editor.readOnly )
+ this.hidePage('replace' );
},
onHide : function()
{
Index: _source/plugins/menu/plugin.js
===================================================================
--- _source/plugins/menu/plugin.js (revision 6660)
+++ _source/plugins/menu/plugin.js (revision )
@@ -97,9 +97,9 @@
{
var item = this.editor.getMenuItem( itemName );
- if ( item )
+ if ( item && ( !item.command || this.editor.getCommand( item.command ).state ) )
{
- item.state = listenerItems[ itemName ];
+ item.state = listenerItems[ itemName ];
this.add( item );
}
}
Index: _source/plugins/elementspath/plugin.js
===================================================================
--- _source/plugins/elementspath/plugin.js (revision 6660)
+++ _source/plugins/elementspath/plugin.js (revision )
@@ -15,6 +15,7 @@
toolbarFocus :
{
editorFocus : false,
+ readOnly : 1,
exec : function( editor )
{
var idBase = editor._.elementsPath.idBase;
Index: _source/plugins/a11yhelp/plugin.js
===================================================================
--- _source/plugins/a11yhelp/plugin.js (revision 6660)
+++ _source/plugins/a11yhelp/plugin.js (revision )
@@ -37,6 +37,7 @@
});
},
modes : { wysiwyg:1, source:1 },
+ readOnly : 1,
canUndo : false
});
Index: _source/core/editor.js
===================================================================
--- _source/core/editor.js (revision 6660)
+++ _source/core/editor.js (revision )
@@ -160,6 +160,16 @@
*/
editor.tabIndex = editor.config.tabIndex || editor.element.getAttribute( 'tabindex' ) || 0;
+ /**
+ * Immutable field indicate the read-only state of this editor.
+ * @name CKEDITOR.editor.prototype.readOnly
+ * @see CKEDITOR.editor.prototype.setReadOnly
+ * @type Boolean
+ * @default CKEDITOR.config.readOnly
+ * @since 3.6
+ */
+ editor.readOnly = !!( editor.config.readOnly || editor.element.getAttribute( 'disabled' ) );
+
// Fire the "configLoaded" event.
editor.fireOnce( 'configLoaded' );
@@ -394,7 +404,7 @@
}
};
- function updateCommandsMode()
+ function updateCommands()
{
var command,
commands = this._.commands,
@@ -403,7 +413,8 @@
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 +502,7 @@
CKEDITOR.fire( 'instanceCreated', null, this );
- this.on( 'mode', updateCommandsMode, null, null, 1 );
+ this.on( 'mode', updateCommands, null, null, 1 );
initConfig( this, instanceConfig );
};
@@ -714,6 +725,22 @@
},
/**
+ * Turn editor into read-only mode or restore it from read-only mode.
+ * @param enable {Boolean}
+ * @since 3.6
+ * Note: current editing block will be reloaded.
+ */
+ setReadOnly : function( enable )
+ {
+ if ( this.readOnly != enable )
+ {
+ this.readOnly = !!enable;
+ // Reload current mode, then fire the event on editor.
+ 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 +868,17 @@
*/
/**
+ * Whether to start the editor in read-only mode, otherwise it depends on if "disabled" attribute is presented on the host <textarea>.
+ * @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 +1021,10 @@
* @param {CKEDITOR.editor} editor This editor instance.
* @param {Object} element The element to insert.
*/
+
+/**
+ * Event fired once editor's {@link CKEDITOR.editor.prototype.readOnly} state has changed.
+ * @name CKEDITOR.editor#readOnly
+ * @event
+ * @param {CKEDITOR.editor} editor This editor instance.
+ */
Index: _source/plugins/toolbar/plugin.js
===================================================================
--- _source/plugins/toolbar/plugin.js (revision 6660)
+++ _source/plugins/toolbar/plugin.js (revision )
@@ -36,6 +36,7 @@
toolbarFocus :
{
modes : { wysiwyg : 1, source : 1 },
+ readOnly : 1,
exec : function( editor )
{
@@ -294,6 +295,7 @@
editor.addCommand( 'toolbarCollapse',
{
+ readOnly : 1,
exec : function( editor )
{
var collapser = CKEDITOR.document.getById( collapserId ),
Index: _source/plugins/print/plugin.js
===================================================================
--- _source/plugins/print/plugin.js (revision 6660)
+++ _source/plugins/print/plugin.js (revision )
@@ -37,5 +37,6 @@
editor.document.$.execCommand( "Print" );
},
canUndo : false,
+ readOnly : 1,
modes : { wysiwyg : !( CKEDITOR.env.opera ) } // It is imposible to print the inner document in Opera.
};
Index: _source/plugins/richcombo/plugin.js
===================================================================
--- _source/plugins/richcombo/plugin.js (revision 6660)
+++ _source/plugins/richcombo/plugin.js (revision )
@@ -130,7 +130,8 @@
editor.on( 'mode', function()
{
- this.setState( this.modes[ editor.mode ] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED );
+ var state = this.modes[ editor.mode ] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED;
+ this.setState( editor.readOnly && !this.readOnly ? CKEDITOR.TRISTATE_DISABLED : state );
this.setValue( '' );
},
this );
Index: _source/plugins/button/plugin.js
===================================================================
--- _source/plugins/button/plugin.js (revision 6660)
+++ _source/plugins/button/plugin.js (revision )
@@ -149,10 +149,12 @@
editor.on( 'mode', function()
{
var mode = editor.mode;
+
// Restore saved button state.
- this.setState( this.modes[ mode ] ?
- modeStates[ mode ] != undefined ? modeStates[ mode ] :
- CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED );
+ var state = this.modes[ mode ] ? modeStates[ mode ] != undefined ? modeStates[ mode ] :
+ CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED;
+
+ this.setState( editor.readOnly && !this.readOnly ? CKEDITOR.TRISTATE_DISABLED : state );
}, this);
}
else if ( command )
Index: _source/plugins/sourcearea/plugin.js
===================================================================
--- _source/plugins/sourcearea/plugin.js (revision 6660)
+++ _source/plugins/sourcearea/plugin.js (revision )
@@ -41,6 +41,8 @@
textarea.addClass( 'cke_source' );
textarea.addClass( 'cke_enable_context_menu' );
+ editor.readOnly && textarea.setAttribute( 'disabled', true );
+
var styles =
{
// IE7 has overflow the