8
0

formsubmit.js 965 B

123456789101112131415161718192021222324252627282930313233
  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 '../_utils/articlepluginset';
  8. // Replace original submit method to prevent page reload.
  9. document.getElementById( 'form' ).submit = () => {};
  10. ClassicEditor
  11. .create( document.querySelector( '#editor' ), {
  12. plugins: [ ArticlePluginSet ],
  13. toolbar: [ 'bold', 'italic', 'undo', 'redo' ],
  14. } )
  15. .then( editor => {
  16. window.editor = editor;
  17. const form = document.getElementById( 'form' );
  18. document.getElementById( 'submit-with-js' ).addEventListener( 'click', () => {
  19. form.submit();
  20. } );
  21. form.addEventListener( 'submit', evt => {
  22. evt.preventDefault();
  23. } );
  24. } )
  25. .catch( err => {
  26. console.error( err.stack );
  27. } );