8
0
Quellcode durchsuchen

Transform method into getter. Update docs and tests.

Mateusz Samsel vor 6 Jahren
Ursprung
Commit
7a995390f8

+ 2 - 2
packages/ckeditor5-word-count/docs/features/word-count.md

@@ -29,7 +29,7 @@ ClassicEditor
 		const wordCountPlugin = editor.plugins.get( 'WordCount' );
 		const wordCountWrapper = document.getElementById( 'word-count' );
 
-		wordCountWrapper.appendChild( wordCounterPlugin.getWordCountContainer() );
+		wordCountWrapper.appendChild( wordCounterPlugin.wordCountContainer );
 	} )
 	.catch( ... );
 ```
@@ -92,7 +92,7 @@ ClassicEditor
 ## Common API
 
 The {@link module:wordcount/wordcount~WordCount} plugin provides:
-  * {@link module:wordcount/wordcount~WordCount#getWordCountContainer} method. It returns a self-updating HTML element which is updated with the current number of words and characters in the editor. There is a possibility to remove "Words" or "Characters" counters with proper configuration of {@link module:wordcount/wordcount~WordCountConfig#displayWords} and {@link module:wordcount/wordcount~WordCountConfig#displayCharacters},
+  * {@link module:wordcount/wordcount~WordCount#wordCountContainer} method. It returns a self-updating HTML element which is updated with the current number of words and characters in the editor. There is a possibility to remove "Words" or "Characters" counters with proper configuration of {@link module:wordcount/wordcount~WordCountConfig#displayWords} and {@link module:wordcount/wordcount~WordCountConfig#displayCharacters},
   * {@link module:wordcount/wordcount~WordCount#event:update update event} which is fired whenever the plugins update the number of counted words and characters. There is a possibility to run own callback function with updated values. Please note that update event is throttled.
 
 <info-box>

+ 9 - 9
packages/ckeditor5-word-count/src/wordcount.js

@@ -69,7 +69,7 @@ export default class WordCount extends Plugin {
 		this.set( 'words', 0 );
 
 		/**
-		 * Label used to display words value in {@link #getWordCountContainer output contianer}
+		 * Label used to display words value in {@link #wordCountContainer output container}
 		 *
 		 * @observable
 		 * @private
@@ -79,7 +79,7 @@ export default class WordCount extends Plugin {
 		this.set( '_wordsLabel' );
 
 		/**
-		 * Label used to display characters value in {@link #getWordCountContainer output contianer}
+		 * Label used to display characters value in {@link #wordCountContainer output container}
 		 *
 		 * @observable
 		 * @private
@@ -128,7 +128,7 @@ export default class WordCount extends Plugin {
 		}
 
 		if ( isElement( this._config.container ) ) {
-			this._config.container.appendChild( this.getWordCountContainer() );
+			this._config.container.appendChild( this.wordCountContainer );
 		}
 	}
 
@@ -143,7 +143,7 @@ export default class WordCount extends Plugin {
 	}
 
 	/**
-	 * Method creates self-updated HTML element. Repeated executions return the same element.
+	 * Creates self-updated HTML element. Repeated executions return the same element.
 	 * Returned element has followed HTML structure:
 	 *
 	 * 		<div class="ck ck-word-count">
@@ -151,9 +151,9 @@ export default class WordCount extends Plugin {
 	 * 			<div class="ck-word-count__characters">Characters: 28</div>
 	 * 		</div>
 	 *
-	 * @returns {HTMLElement}
+	 * @type {HTMLElement}
 	 */
-	getWordCountContainer() {
+	get wordCountContainer() {
 		const editor = this.editor;
 		const t = editor.t;
 		const displayWords = editor.config.get( 'wordCount.displayWords' );
@@ -273,7 +273,7 @@ export default class WordCount extends Plugin {
 
 /**
  * This option allows for hiding the word counter. The element obtained through
- * {@link module:wordcount/wordcount~WordCount#getWordCountContainer} will only preserve
+ * {@link module:wordcount/wordcount~WordCount#wordCountContainer} will only preserve
  * the characters part. Word counter is displayed by default when this configuration option is not defined.
  *
  *		const wordCountConfig = {
@@ -291,7 +291,7 @@ export default class WordCount extends Plugin {
 
 /**
  * This option allows for hiding the character counter. The element obtained through
- * {@link module:wordcount/wordcount~WordCount#getWordCountContainer} will only preserve
+ * {@link module:wordcount/wordcount~WordCount#wordCountContainer} will only preserve
  * the words part. Character counter is displayed by default when this configuration option is not defined.
  *
  *		const wordCountConfig = {
@@ -324,7 +324,7 @@ export default class WordCount extends Plugin {
 
 /**
  * This option allows on providing an HTML element where
- * {@link module:wordcount/wordcount~WordCount#getWordCountContainer word count container} will be appended automatically.
+ * {@link module:wordcount/wordcount~WordCount#wordCountContainer word count container} will be appended automatically.
  *
  *		const wordCountConfig = {
  *			container: document.getElementById( 'container-for-word-count' );

+ 1 - 1
packages/ckeditor5-word-count/tests/manual/wordcount.html

@@ -8,5 +8,5 @@
 <div id="editor">
 	Hello world.
 </div>
-<div id="other-words-container">
+<div id="words-container">
 </div>

+ 1 - 1
packages/ckeditor5-word-count/tests/manual/wordcount.js

@@ -19,7 +19,7 @@ ClassicEditor
 			onUpdate: values => {
 				console.log( `Values from 'onUpdate': ${ JSON.stringify( values ) }` );
 			},
-			container: document.getElementById( 'other-words-container' )
+			container: document.getElementById( 'words-container' )
 		}
 	} )
 	.then( editor => {

+ 6 - 6
packages/ckeditor5-word-count/tests/wordcount.js

@@ -94,7 +94,7 @@ describe( 'WordCount', () => {
 	describe( 'self-updating element', () => {
 		let container;
 		beforeEach( () => {
-			container = wordCountPlugin.getWordCountContainer();
+			container = wordCountPlugin.wordCountContainer;
 		} );
 
 		it( 'provides html element', () => {
@@ -127,7 +127,7 @@ describe( 'WordCount', () => {
 		} );
 
 		it( 'subsequent calls provides the same element', () => {
-			const newContainer = wordCountPlugin.getWordCountContainer();
+			const newContainer = wordCountPlugin.wordCountContainer;
 
 			expect( container ).to.equal( newContainer );
 		} );
@@ -231,7 +231,7 @@ describe( 'WordCount', () => {
 			} )
 				.then( editor => {
 					const wordCountPlugin = editor.plugins.get( 'WordCount' );
-					const container = wordCountPlugin.getWordCountContainer();
+					const container = wordCountPlugin.wordCountContainer;
 
 					expect( container.innerText ).to.equal( 'Characters: 0' );
 				} )
@@ -248,7 +248,7 @@ describe( 'WordCount', () => {
 			} )
 				.then( editor => {
 					const wordCountPlugin = editor.plugins.get( 'WordCount' );
-					const container = wordCountPlugin.getWordCountContainer();
+					const container = wordCountPlugin.wordCountContainer;
 
 					expect( container.innerText ).to.equal( 'Words: 0' );
 				} )
@@ -293,7 +293,7 @@ describe( 'WordCount', () => {
 
 					const wordCountPlugin = editor.plugins.get( 'WordCount' );
 
-					expect( element.firstElementChild ).to.equal( wordCountPlugin.getWordCountContainer() );
+					expect( element.firstElementChild ).to.equal( wordCountPlugin.wordCountContainer );
 				} );
 		} );
 	} );
@@ -321,7 +321,7 @@ describe( 'WordCount', () => {
 			} )
 				.then( editor => {
 					const wordCountPlugin = editor.plugins.get( 'WordCount' );
-					const container = wordCountPlugin.getWordCountContainer();
+					const container = wordCountPlugin.wordCountContainer;
 
 					expect( container.innerText ).to.equal( 'Słowa: 0Znaki: 0' );
 				} )