Przeglądaj źródła

Added readOnly interface property to the Editor class.

Oskar Wróbel 8 lat temu
rodzic
commit
8b22649e65

+ 9 - 0
packages/ckeditor5-core/src/editor/editor.js

@@ -89,6 +89,15 @@ export default class Editor {
 		 */
 		this.data = new DataController( this.document );
 
+		/**
+		 * Defines whether editor is read-only mode. In read-only mode editor {@link module:core/command Commands}
+		 * are disabled and is not possible to set any data to the editor.
+		 *
+		 * @observable
+		 * @member {Boolean} #readOnly
+		 */
+		this.set( 'readOnly', false );
+
 		/**
 		 * Instance of the {@link module:engine/controller/editingcontroller~EditingController editing controller}.
 		 *

+ 19 - 0
packages/ckeditor5-core/tests/editor/editor.js

@@ -158,6 +158,25 @@ describe( 'Editor', () => {
 		} );
 	} );
 
+	describe( 'readOnly', () => {
+		it( 'is false at default', () => {
+			const editor = new Editor();
+
+			expect( editor.readOnly ).to.false;
+		} );
+
+		it( 'is observable', () => {
+			const editor = new Editor();
+			const spy = sinon.spy();
+
+			editor.on( 'change:readOnly', spy );
+
+			editor.readOnly = true;
+
+			sinon.assert.calledOnce( spy );
+		} );
+	} );
+
 	describe( 'destroy()', () => {
 		it( 'should fire "destroy"', () => {
 			const editor = new Editor();