wordcount.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* globals console, window, document */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  8. import WordCount from '../../src/wordcount';
  9. ClassicEditor
  10. .create( document.querySelector( '#editor' ), {
  11. plugins: [ ArticlePluginSet, WordCount ],
  12. toolbar: [
  13. 'heading', 'bold', 'italic', 'bulletedList', 'numberedList', 'blockQuote', 'link', 'undo', 'redo'
  14. ]
  15. } )
  16. .then( editor => {
  17. window.editor = editor;
  18. const wordCountPlugin = editor.plugins.get( 'WordCount' );
  19. const wordCount = wordCountPlugin.getWordCountContainer();
  20. wordCountPlugin.on( 'update', ( evt, payload ) => {
  21. console.log( JSON.stringify( payload ) );
  22. } );
  23. document.getElementById( 'words' ).appendChild( wordCount );
  24. document.getElementById( 'destroy-editor' ).addEventListener( 'click', () => {
  25. editor.destroy();
  26. } );
  27. } )
  28. .catch( err => {
  29. console.error( err.stack );
  30. } );