readonly.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * @license Copyright (c) 2003-2020, 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. import BalloonToolbar from '@ckeditor/ckeditor5-ui/src/toolbar/balloon/balloontoolbar';
  9. ClassicEditor
  10. .create( document.querySelector( '#editor' ), {
  11. plugins: [ ArticlePluginSet, BalloonToolbar ],
  12. toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ],
  13. image: {
  14. toolbar: [ 'imageStyle:full', 'imageStyle:side', '|', 'imageTextAlternative' ]
  15. },
  16. balloonToolbar: [ 'bold', 'italic', 'link' ]
  17. } )
  18. .then( editor => {
  19. window.editor = editor;
  20. const button = document.querySelector( '#read-only' );
  21. button.addEventListener( 'click', () => {
  22. editor.isReadOnly = !editor.isReadOnly;
  23. button.textContent = editor.isReadOnly ? 'Turn off read-only mode' : 'Turn on read-only mode';
  24. editor.editing.view.focus();
  25. } );
  26. } )
  27. .catch( err => {
  28. console.error( err.stack );
  29. } );