Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Fix: Word count plugin no longer throws an error when a container is …
Browse files Browse the repository at this point in the history
…undefined. Closes #16.
  • Loading branch information
mlewand authored Jul 12, 2019
2 parents dee64b3 + 46e0c6e commit e1a7a7e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/features/word-count.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ ClassicEditor
## Common API

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.

<info-box>
Expand Down
6 changes: 4 additions & 2 deletions src/wordcount.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ export default class WordCount extends Plugin {
* @inheritDoc
*/
destroy() {
this._outputView.element.remove();
this._outputView.destroy();
if ( this._outputView ) {
this._outputView.element.remove();
this._outputView.destroy();
}

super.destroy();
}
Expand Down
9 changes: 9 additions & 0 deletions tests/wordcount.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ describe( 'WordCount', () => {
.then( 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();
} );
} );
} );
} );

Expand Down

0 comments on commit e1a7a7e

Please sign in to comment.