read-only.js 1.0 KB

123456789101112131415161718192021222324252627282930313233
  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. ClassicEditor
  9. .create( document.querySelector( '#snippet-read-only' ), {
  10. plugins: [ ArticlePreset ],
  11. toolbar: [ 'headings', 'bold', 'italic', 'link', 'unlink', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ],
  12. image: {
  13. toolbar: [ 'imageStyleFull', 'imageStyleSide', '|', 'imageTextAlternative' ]
  14. }
  15. } )
  16. .then( editor => {
  17. window.editor = editor;
  18. const button = document.querySelector( '#snippet-read-only-toggle' );
  19. button.addEventListener( 'click', () => {
  20. editor.isReadOnly = !editor.isReadOnly;
  21. button.innerText = editor.isReadOnly ? 'Switch to editable mode' : 'Switch to read-only mode';
  22. } );
  23. } )
  24. .catch( err => {
  25. console.error( err.stack );
  26. } );