ソースを参照

Renamed the attachPlaceholder() helper to addPlaceholder().

Aleksander Nowodzinski 6 年 前
コミット
e2da5c35db

+ 10 - 10
packages/ckeditor5-engine/src/view/placeholder.js

@@ -13,18 +13,18 @@ import '../../theme/placeholder.css';
 const documentPlaceholders = new WeakMap();
 
 /**
- * Attaches placeholder to provided element and updates it's visibility. To change placeholder simply call this method
- * once again with new parameters.
+ * Adds a placeholder to the provided view element and updates it's visibility. To change the placeholder,
+ * simply call this method again with new parameters.
  *
  * @param {module:engine/view/view~View} view View controller.
- * @param {module:engine/view/element~Element|Function} element Element to attach placeholder to or a function
+ * @param {module:engine/view/element~Element|Function} element Element to add placeholder to or a function
  * that returns such an element when an {@link module:engine/view/rooteditableelement~RootEditableElement root editable}
  * instance is passed into it.
  * @param {String} placeholderText Placeholder text to use.
  * @param {Function} [checkFunction] If provided it will be called before checking if placeholder should be displayed.
  * If function returns `false` placeholder will not be showed.
  */
-export function attachPlaceholder( view, element, placeholderText, checkFunction ) {
+export function addPlaceholder( view, element, placeholderText, checkFunction ) {
 	const document = view.document;
 
 	// Single listener per document.
@@ -46,12 +46,12 @@ export function attachPlaceholder( view, element, placeholderText, checkFunction
 }
 
 /**
- * Removes placeholder functionality from given element.
+ * Removes the placeholder functionality from a given element.
  *
  * @param {module:engine/view/view~View} view
  * @param {module:engine/view/element~Element} element
  */
-export function detachPlaceholder( view, element ) {
+export function removePlaceholder( view, element ) {
 	if ( typeof element == 'function' ) {
 		element = element();
 	}
@@ -161,18 +161,18 @@ function updateSinglePlaceholder( writer, element, info ) {
 }
 
 /**
- * Returns a view element the placeholder can be attached to inside a view editing root.
+ * Returns a view element the placeholder can be added to inside a view editing root.
  *
  * Even if empty, the editing root usually hosts at least one empty element (paragraph, heading, etc.).
- * Because of that, the placeholder cannot be attached directly to the root and doing so would mean both
+ * Because of that, the placeholder cannot be added directly to the root and doing so would mean both
  * a CSS pseudo–element (with a placeholder text) and an empty element are displayed next to each other.
  *
- * Instead, the placeholder must be attached to that empty element and this helper returns it, if there
+ * Instead, the placeholder must be added to that empty element and this helper returns it, if there
  * is one.
  *
  * @param {module:engine/view/rooteditableelement~RootEditableElement} root The root editable view that
  * is to have a placeholder.
- * @returns {module:engine/view/element~Element|null} An element the placeholder can be attached to.
+ * @returns {module:engine/view/element~Element|null} An element the placeholder can be added to.
  */
 export function getRootPlaceholderElement( root ) {
 	return () => {

+ 3 - 3
packages/ckeditor5-engine/tests/manual/placeholder.js

@@ -12,7 +12,7 @@ import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import Undo from '@ckeditor/ckeditor5-undo/src/undo';
 import Heading from '@ckeditor/ckeditor5-heading/src/heading';
 import global from '@ckeditor/ckeditor5-utils/src/dom/global';
-import { attachPlaceholder } from '../../src/view/placeholder';
+import { addPlaceholder } from '../../src/view/placeholder';
 
 ClassicEditor
 	.create( global.document.querySelector( '#editor' ), {
@@ -25,8 +25,8 @@ ClassicEditor
 		const header = viewDoc.getRoot().getChild( 0 );
 		const paragraph = viewDoc.getRoot().getChild( 1 );
 
-		attachPlaceholder( view, header, 'Type some header text...' );
-		attachPlaceholder( view, paragraph, 'Type some paragraph text...' );
+		addPlaceholder( view, header, 'Type some header text...' );
+		addPlaceholder( view, paragraph, 'Type some paragraph text...' );
 		view.render();
 	} )
 	.catch( err => {

+ 19 - 19
packages/ckeditor5-engine/tests/view/placeholder.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md.
  */
 
-import { attachPlaceholder, detachPlaceholder } from '../../src/view/placeholder';
+import { addPlaceholder, removePlaceholder } from '../../src/view/placeholder';
 import createViewRoot from './_utils/createroot';
 import View from '../../src/view/view';
 import ViewRange from '../../src/view/range';
@@ -19,12 +19,12 @@ describe( 'placeholder', () => {
 		viewDocument.isFocused = true;
 	} );
 
-	describe( 'createPlaceholder', () => {
+	describe( 'addPlaceholder', () => {
 		it( 'should attach proper CSS class and data attribute', () => {
 			setData( view, '<div></div><div>{another div}</div>' );
 			const element = viewRoot.getChild( 0 );
 
-			attachPlaceholder( view, element, 'foo bar baz' );
+			addPlaceholder( view, element, 'foo bar baz' );
 
 			expect( element.getAttribute( 'data-placeholder' ) ).to.equal( 'foo bar baz' );
 			expect( element.hasClass( 'ck-placeholder' ) ).to.be.true;
@@ -34,7 +34,7 @@ describe( 'placeholder', () => {
 			setData( view, '<div>first div</div><div>{another div}</div>' );
 			const element = viewRoot.getChild( 0 );
 
-			attachPlaceholder( view, element, 'foo bar baz' );
+			addPlaceholder( view, element, 'foo bar baz' );
 
 			expect( element.getAttribute( 'data-placeholder' ) ).to.equal( 'foo bar baz' );
 			expect( element.hasClass( 'ck-placeholder' ) ).to.be.false;
@@ -44,7 +44,7 @@ describe( 'placeholder', () => {
 			setData( view, '<div><ui:span></ui:span><ui:span></ui:span></div><div>{another div}</div>' );
 			const element = viewRoot.getChild( 0 );
 
-			attachPlaceholder( view, element, 'foo bar baz' );
+			addPlaceholder( view, element, 'foo bar baz' );
 
 			expect( element.getAttribute( 'data-placeholder' ) ).to.equal( 'foo bar baz' );
 			expect( element.hasClass( 'ck-placeholder' ) ).to.be.true;
@@ -54,7 +54,7 @@ describe( 'placeholder', () => {
 			setData( view, '<div>[]</div><div>another div</div>' );
 			const element = viewRoot.getChild( 0 );
 
-			attachPlaceholder( view, element, 'foo bar baz' );
+			addPlaceholder( view, element, 'foo bar baz' );
 
 			expect( element.getAttribute( 'data-placeholder' ) ).to.equal( 'foo bar baz' );
 			expect( element.hasClass( 'ck-placeholder' ) ).to.be.false;
@@ -65,7 +65,7 @@ describe( 'placeholder', () => {
 			const element = viewRoot.getChild( 0 );
 			viewDocument.isFocused = false;
 
-			attachPlaceholder( view, element, 'foo bar baz' );
+			addPlaceholder( view, element, 'foo bar baz' );
 
 			expect( element.getAttribute( 'data-placeholder' ) ).to.equal( 'foo bar baz' );
 			expect( element.hasClass( 'ck-placeholder' ) ).to.be.true;
@@ -77,7 +77,7 @@ describe( 'placeholder', () => {
 			let result = true;
 			const spy = sinon.spy( () => result );
 
-			attachPlaceholder( view, element, 'foo bar baz', spy );
+			addPlaceholder( view, element, 'foo bar baz', spy );
 
 			sinon.assert.called( spy );
 			expect( element.getAttribute( 'data-placeholder' ) ).to.equal( 'foo bar baz' );
@@ -92,7 +92,7 @@ describe( 'placeholder', () => {
 			setData( view, '<div></div><div>{another div}</div>' );
 			const element = viewRoot.getChild( 0 );
 
-			attachPlaceholder( view, element, 'foo bar baz' );
+			addPlaceholder( view, element, 'foo bar baz' );
 
 			expect( element.getAttribute( 'data-placeholder' ) ).to.equal( 'foo bar baz' );
 			expect( element.hasClass( 'ck-placeholder' ) ).to.be.true;
@@ -108,8 +108,8 @@ describe( 'placeholder', () => {
 			setData( view, '<div></div><div>{another div}</div>' );
 			const element = viewRoot.getChild( 0 );
 
-			attachPlaceholder( view, element, 'foo bar baz' );
-			attachPlaceholder( view, element, 'new text' );
+			addPlaceholder( view, element, 'foo bar baz' );
+			addPlaceholder( view, element, 'new text' );
 
 			expect( element.getAttribute( 'data-placeholder' ) ).to.equal( 'new text' );
 			expect( element.hasClass( 'ck-placeholder' ) ).to.be.true;
@@ -119,7 +119,7 @@ describe( 'placeholder', () => {
 			setData( view, '<div></div><div>{another div}</div>' );
 			const element = viewRoot.getChild( 0 );
 
-			attachPlaceholder( view, element, 'foo bar baz' );
+			addPlaceholder( view, element, 'foo bar baz' );
 			setData( view, '<p>paragraph</p>' );
 
 			view.render();
@@ -136,8 +136,8 @@ describe( 'placeholder', () => {
 			setData( secondView, '<div></div><div>{another div}</div>' );
 			const secondElement = secondRoot.getChild( 0 );
 
-			attachPlaceholder( view, element, 'first placeholder' );
-			attachPlaceholder( secondView, secondElement, 'second placeholder' );
+			addPlaceholder( view, element, 'first placeholder' );
+			addPlaceholder( secondView, secondElement, 'second placeholder' );
 
 			expect( element.getAttribute( 'data-placeholder' ) ).to.equal( 'first placeholder' );
 			expect( element.hasClass( 'ck-placeholder' ) ).to.be.true;
@@ -165,7 +165,7 @@ describe( 'placeholder', () => {
 			setData( view, '<div></div><div>{another div}</div>' );
 			const element = viewRoot.getChild( 0 );
 
-			attachPlaceholder( view, element, 'foo bar baz' );
+			addPlaceholder( view, element, 'foo bar baz' );
 
 			view.change( writer => {
 				writer.setSelection( ViewRange._createIn( element ) );
@@ -180,17 +180,17 @@ describe( 'placeholder', () => {
 		} );
 	} );
 
-	describe( 'detachPlaceholder', () => {
+	describe( 'removePlaceholder', () => {
 		it( 'should remove placeholder from element', () => {
 			setData( view, '<div></div><div>{another div}</div>' );
 			const element = viewRoot.getChild( 0 );
 
-			attachPlaceholder( view, element, 'foo bar baz' );
+			addPlaceholder( view, element, 'foo bar baz' );
 
 			expect( element.getAttribute( 'data-placeholder' ) ).to.equal( 'foo bar baz' );
 			expect( element.hasClass( 'ck-placeholder' ) ).to.be.true;
 
-			detachPlaceholder( view, element );
+			removePlaceholder( view, element );
 
 			expect( element.hasAttribute( 'data-placeholder' ) ).to.be.false;
 			expect( element.hasClass( 'ck-placeholder' ) ).to.be.false;
@@ -200,7 +200,7 @@ describe( 'placeholder', () => {
 			setData( view, '<div></div><div>{another div}</div>' );
 			const element = viewRoot.getChild( 0 );
 
-			detachPlaceholder( view, element );
+			removePlaceholder( view, element );
 
 			expect( element.hasAttribute( 'data-placeholder' ) ).to.be.false;
 			expect( element.hasClass( 'ck-placeholder' ) ).to.be.false;