8
0
Просмотр исходного кода

Got rid of *EditableUIView#enableEditingRootListeners(). Moved to render() because view document root rendering is postponed now.

Aleksander Nowodzinski 7 лет назад
Родитель
Сommit
2ef181c431

+ 24 - 21
packages/ckeditor5-editor-classic/src/classiceditorui.js

@@ -82,16 +82,16 @@ export default class ClassicEditorUI extends EditorUI {
 		const editable = view.editable;
 		const editingRoot = editingView.document.getRoot();
 
+		// The editable UI and editing root should share the same name. Then name is used
+		// to recognize the particular editable, for instance in ARIA attributes.
+		editable.name = editingRoot.rootName;
+
 		view.render();
 
 		// The editable UI element in DOM is available for sure only after the editor UI view has been rendered.
 		// But it can be available earlier if a DOM element has been passed to BalloonEditor.create().
 		const editableElement = editable.element;
 
-		// The editable UI and editing root should share the same name. Then name is used
-		// to recognize the particular editable, for instance in ARIA attributes.
-		editable.name = editingRoot.rootName;
-
 		// Register the editable UI view in the editor. A single editor instance can aggregate multiple
 		// editable areas (roots) but the classic editor has only one.
 		this._editableElements.set( editable.name, editableElement );
@@ -110,22 +110,6 @@ export default class ClassicEditorUI extends EditorUI {
 		// toolbar gets focused.
 		view.editable.bind( 'isFocused' ).to( this.focusTracker );
 
-		// The UI must wait until the data is ready to attach certain actions that operate
-		// on the editing view–level. They use the view writer to set attributes on the editable
-		// element and doing so before data is loaded into the model (ready) would destroy the
-		// original content.
-		editor.on( 'dataReady', () => {
-			view.editable.enableEditingRootListeners();
-
-			const placeholderText = editor.config.get( 'placeholder' ) || editor.sourceElement.getAttribute( 'placeholder' );
-
-			if ( placeholderText ) {
-				const placeholderElement = getRootPlaceholderElement( editingRoot );
-
-				addPlaceholder( editingView, placeholderElement, placeholderText );
-			}
-		} );
-
 		// If an element containing the initial data of the editor was provided, replace it with
 		// an editor instance's UI in DOM until the editor is destroyed. For instance, a <textarea>
 		// can be such element.
@@ -133,6 +117,7 @@ export default class ClassicEditorUI extends EditorUI {
 			this._elementReplacer.replace( replacementElement, this.element );
 		}
 
+		this._initPlaceholder();
 		this._initToolbar();
 		this.fire( 'ready' );
 	}
@@ -145,7 +130,6 @@ export default class ClassicEditorUI extends EditorUI {
 		const editingView = this.editor.editing.view;
 
 		this._elementReplacer.restore();
-		view.editable.disableEditingRootListeners();
 		editingView.detachDomRoot( view.editable.name );
 		view.destroy();
 
@@ -179,4 +163,23 @@ export default class ClassicEditorUI extends EditorUI {
 			toolbar: view.toolbar
 		} );
 	}
+
+	/**
+	 * Enable the placeholder text on the editing root, if any was configured.
+	 *
+	 * @private
+	 */
+	_initPlaceholder() {
+		const editor = this.editor;
+		const editingView = editor.editing.view;
+		const editingRoot = editingView.document.getRoot();
+
+		const placeholderText = editor.config.get( 'placeholder' ) || editor.sourceElement.getAttribute( 'placeholder' );
+
+		if ( placeholderText ) {
+			const placeholderElement = getRootPlaceholderElement( editingRoot );
+
+			addPlaceholder( editingView, placeholderElement, placeholderText );
+		}
+	}
 }

+ 3 - 1
packages/ckeditor5-editor-classic/tests/manual/placeholder.html

@@ -1,3 +1,5 @@
-<div id="editor-1" placeholder="Placeholder from the attribute"></div>
+<div id="editor-1" placeholder="Placeholder from the attribute">
+	<p>Remove this text to see the placeholder.</p>
+</div>
 <br />
 <div id="editor-2" placeholder="Placeholder from the attribute"></div>