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

Draft of the placeholder feature.

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

+ 1 - 1
packages/ckeditor5-editor-classic/src/classiceditor.js

@@ -78,7 +78,7 @@ export default class ClassicEditor extends Editor {
 
 		this.model.document.createRoot();
 
-		this.ui = new ClassicEditorUI( this, new ClassicEditorUIView( this.locale ) );
+		this.ui = new ClassicEditorUI( this, new ClassicEditorUIView( this.locale, this.editing.view ) );
 
 		attachToForm( this );
 	}

+ 18 - 4
packages/ckeditor5-editor-classic/src/classiceditorui.js

@@ -10,6 +10,7 @@
 import EditorUI from '@ckeditor/ckeditor5-core/src/editor/editorui';
 import enableToolbarKeyboardFocus from '@ckeditor/ckeditor5-ui/src/toolbar/enabletoolbarkeyboardfocus';
 import normalizeToolbarConfig from '@ckeditor/ckeditor5-ui/src/toolbar/normalizetoolbarconfig';
+import { attachPlaceholder, getPlaceholderElement } from '@ckeditor/ckeditor5-engine/src/view/placeholder';
 
 /**
  * The classic editor UI class.
@@ -38,6 +39,9 @@ export default class ClassicEditorUI extends EditorUI {
 	init() {
 		const editor = this.editor;
 		const view = this.view;
+		const editingView = editor.editing.view;
+
+		view.editable.bind( 'isFocused' ).to( editingView.document );
 
 		view.render();
 
@@ -50,20 +54,30 @@ export default class ClassicEditorUI extends EditorUI {
 		}
 
 		// Setup the editable.
-		const editingRoot = editor.editing.view.document.getRoot();
-		view.editable.bind( 'isReadOnly' ).to( editingRoot );
-		view.editable.bind( 'isFocused' ).to( editor.editing.view.document );
+		const editingRoot = editingView.document.getRoot();
 		view.editable.name = editingRoot.rootName;
 
+		editor.on( 'dataReady', () => {
+			view.editable.enableDomRootActions();
+
+			attachPlaceholder( editingView, getPlaceholderElement( editingRoot ), 'Type some text...' );
+		} );
+
 		this.focusTracker.add( this.view.editableElement );
 
 		this.view.toolbar.fillFromConfig( this._toolbarConfig.items, this.componentFactory );
 
 		enableToolbarKeyboardFocus( {
-			origin: editor.editing.view,
+			origin: editingView,
 			originFocusTracker: this.focusTracker,
 			originKeystrokeHandler: editor.keystrokes,
 			toolbar: this.view.toolbar
 		} );
 	}
+
+	destroy() {
+		this.view.editable.disableDomRootActions();
+
+		super.destroy();
+	}
 }

+ 2 - 2
packages/ckeditor5-editor-classic/src/classiceditoruiview.js

@@ -26,7 +26,7 @@ export default class ClassicEditorUIView extends BoxedEditorUIView {
 	 *
 	 * @param {module:utils/locale~Locale} locale The {@link module:core/editor/editor~Editor#locale} instance.
 	 */
-	constructor( locale ) {
+	constructor( locale, editingView ) {
 		super( locale );
 
 		/**
@@ -52,7 +52,7 @@ export default class ClassicEditorUIView extends BoxedEditorUIView {
 		 * @readonly
 		 * @member {module:ui/editableui/inline/inlineeditableuiview~InlineEditableUIView}
 		 */
-		this.editable = new InlineEditableUIView( locale );
+		this.editable = new InlineEditableUIView( locale, editingView );
 	}
 
 	/**