formsubmit.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals console, window, document */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import ArticlePreset from '@ckeditor/ckeditor5-presets/src/article';
  8. // Replace original submit method to prevent page reload.
  9. document.getElementById( 'form' ).submit = () => {};
  10. ClassicEditor
  11. .create( document.querySelector( '#editor' ), {
  12. plugins: [ ArticlePreset ],
  13. toolbar: [ 'headings', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ],
  14. image: {
  15. toolbar: [ 'imageStyleFull', 'imageStyleSide', '|', 'imageTextAlternative' ],
  16. }
  17. } )
  18. .then( editor => {
  19. window.editor = editor;
  20. const form = document.getElementById( 'form' );
  21. document.getElementById( 'submit-with-js' ).addEventListener( 'click', () => form.submit() );
  22. form.addEventListener( 'submit', evt => {
  23. evt.preventDefault();
  24. } );
  25. } )
  26. .catch( err => {
  27. console.error( err.stack );
  28. } );