浏览代码

Draft of the view root destriction.

Aleksander Nowodzinski 7 年之前
父节点
当前提交
a6ac8c58e9

+ 11 - 2
packages/ckeditor5-ui/src/editableui/editableuiview.js

@@ -59,6 +59,8 @@ export default class EditableUIView extends View {
 		 */
 		this.externalElement = editableElement;
 
+		this.viewRoot = null;
+
 		/**
 		 * The element which is the main editable element (usually the one with `contentEditable="true"`).
 		 *
@@ -81,8 +83,9 @@ export default class EditableUIView extends View {
 		}
 	}
 
-	attachDomRootActions() {
-		const viewRoot = this.editingView.domConverter.domToView( this.element );
+	enableDomRootActions() {
+		const viewRoot = this.viewRoot = this.editingView.domConverter.domToView( this.element );
+
 		const updateFocusClasses = () => {
 			this.editingView.change( writer => {
 				writer.addClass( this.isFocused ? 'ck-focused' : 'ck-blurred', viewRoot );
@@ -94,6 +97,12 @@ export default class EditableUIView extends View {
 		updateFocusClasses();
 	}
 
+	disableDomRootActions() {
+		this.editingView.change( writer => {
+			writer.removeClass( [ 'ck-blurred', 'ck-focused' ], this.viewRoot );
+		} );
+	}
+
 	/**
 	 * @inheritDoc
 	 */

+ 10 - 5
packages/ckeditor5-ui/src/editableui/inline/inlineeditableuiview.js

@@ -42,17 +42,16 @@ export default class InlineEditableUIView extends EditableUIView {
 		} );
 	}
 
-	attachDomRootActions() {
-		super.attachDomRootActions();
+	enableDomRootActions() {
+		super.enableDomRootActions();
 
 		const t = this.t;
-		const viewRoot = this.editingView.domConverter.domToView( this.element );
 		const updateAriaLabelAttribute = () => {
 			this.editingView.change( writer => {
 				if ( this.name ) {
-					writer.setAttribute( 'aria-label', t( 'Rich Text Editor, %0', [ this.name ] ), viewRoot );
+					writer.setAttribute( 'aria-label', t( 'Rich Text Editor, %0', [ this.name ] ), this.viewRoot );
 				} else {
-					writer.removeAttribute( 'aria-label', viewRoot );
+					writer.removeAttribute( 'aria-label', this.viewRoot );
 				}
 			} );
 		};
@@ -60,4 +59,10 @@ export default class InlineEditableUIView extends EditableUIView {
 		this.on( 'change:name', updateAriaLabelAttribute );
 		updateAriaLabelAttribute();
 	}
+
+	disableDomRootActions() {
+		this.editingView.change( writer => {
+			writer.removeAttribute( 'aria-label', this.viewRoot );
+		} );
+	}
 }