Browse Source

Fix: Word count plugin no longer throws an error when a container is undefined. Closes #16.

Marek Lewandowski 6 năm trước cách đây
mục cha
commit
147f413662

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

@@ -92,7 +92,7 @@ ClassicEditor
 ## Common API
 ## Common API
 
 
 The {@link module:word-count/wordcount~WordCount} plugin provides:
 The {@link module:word-count/wordcount~WordCount} plugin provides:
-  * {@link module:word-count/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:word-count/wordcount~WordCountConfig#displayWords} and {@link module:word-count/wordcount~WordCountConfig#displayCharacters},
+  * {@link module:word-count/wordcount~WordCount#wordCountContainer} getter. 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:word-count/wordcount~WordCountConfig#displayWords} and {@link module:word-count/wordcount~WordCountConfig#displayCharacters},
   * {@link module:word-count/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.
   * {@link module:word-count/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>
 <info-box>

+ 4 - 2
packages/ckeditor5-word-count/src/wordcount.js

@@ -136,8 +136,10 @@ export default class WordCount extends Plugin {
 	 * @inheritDoc
 	 * @inheritDoc
 	 */
 	 */
 	destroy() {
 	destroy() {
-		this._outputView.element.remove();
-		this._outputView.destroy();
+		if ( this._outputView ) {
+			this._outputView.element.remove();
+			this._outputView.destroy();
+		}
 
 
 		super.destroy();
 		super.destroy();
 	}
 	}

+ 9 - 0
packages/ckeditor5-word-count/tests/wordcount.js

@@ -158,6 +158,15 @@ describe( 'WordCount', () => {
 					.then( done )
 					.then( done )
 					.catch( done );
 					.catch( done );
 			} );
 			} );
+
+			it( 'should not throw an error if container is not specified', () => {
+				return VirtualTestEditor.create( {
+					plugins: [ WordCount, Paragraph ]
+				} )
+					.then( editor => {
+						return editor.destroy();
+					} );
+			} );
 		} );
 		} );
 	} );
 	} );