8
0
Pārlūkot izejas kodu

Support defining body placeholder using textarea attribute.

Piotr Jasiun 6 gadi atpakaļ
vecāks
revīzija
24a42e9307

+ 4 - 1
packages/ckeditor5-heading/src/title.js

@@ -320,9 +320,12 @@ export default class Title extends Plugin {
 		const t = editor.t;
 		const view = editor.editing.view;
 		const viewRoot = view.document.getRoot();
+		const sourceElement = editor.sourceElement;
 
 		const titlePlaceholder = editor.config.get( 'title.placeholder' ) || t( 'Type your title' );
-		const bodyPlaceholder = editor.config.get( 'placeholder' ) || t( 'Type or paste your content here.' );
+		const bodyPlaceholder = editor.config.get( 'placeholder' ) ||
+			sourceElement && sourceElement.tagName.toLowerCase() === 'textarea' && sourceElement.getAttribute( 'placeholder' ) ||
+			t( 'Type or paste your content here.' );
 
 		// Attach placeholder to the view title element.
 		editor.editing.downcastDispatcher.on( 'insert:title-content', ( evt, data, conversionApi ) => {

+ 43 - 1
packages/ckeditor5-heading/tests/title.js

@@ -650,7 +650,7 @@ describe( 'Title', () => {
 			expect( bodyDomElement.classList.contains( 'ck-placeholder' ) ).to.equal( false );
 		} );
 
-		describe( 'custom placeholder', () => {
+		describe( 'custom placeholder defined using configuration', () => {
 			let element, editor, model;
 
 			beforeEach( () => {
@@ -691,6 +691,48 @@ describe( 'Title', () => {
 				expect( body.hasClass( 'ck-placeholder' ) ).to.equal( true );
 			} );
 		} );
+
+		describe( 'custom placeholder defined using textarea attribte', () => {
+			let element, editor, model;
+
+			beforeEach( () => {
+				element = document.createElement( 'textarea' );
+				element.setAttribute( 'placeholder', 'bom' );
+				document.body.appendChild( element );
+
+				return ClassicTestEditor.create( element, {
+					plugins: [ Title, Heading, BlockQuote, Clipboard, Image, ImageUpload, Enter, Undo ],
+					title: {
+						placeholder: 'foo'
+					}
+				} ).then( _editor => {
+					editor = _editor;
+					model = editor.model;
+				} );
+			} );
+
+			afterEach( () => {
+				return editor.destroy().then( () => element.remove() );
+			} );
+
+			it( 'should show custom placeholder in title and body', () => {
+				const viewRoot = editor.editing.view.document.getRoot();
+
+				setData( model,
+					'<title><title-content></title-content></title>' +
+					'<paragraph></paragraph>'
+				);
+
+				const title = viewRoot.getChild( 0 );
+				const body = viewRoot.getChild( 1 );
+
+				expect( title.getAttribute( 'data-placeholder' ) ).to.equal( 'foo' );
+				expect( body.getAttribute( 'data-placeholder' ) ).to.equal( 'bom' );
+
+				expect( title.hasClass( 'ck-placeholder' ) ).to.equal( true );
+				expect( body.hasClass( 'ck-placeholder' ) ).to.equal( true );
+			} );
+		} );
 	} );
 
 	describe( 'Tab press handling', () => {