resize.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. /* global document, console, window */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import EnterPlugin from '@ckeditor/ckeditor5-enter/src/enter';
  8. import TypingPlugin from '@ckeditor/ckeditor5-typing/src/typing';
  9. import ParagraphPlugin from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  10. import ImagePlugin from '../../src/image';
  11. import UndoPlugin from '@ckeditor/ckeditor5-undo/src/undo';
  12. import ClipboardPlugin from '@ckeditor/ckeditor5-clipboard/src/clipboard';
  13. ClassicEditor
  14. .create( document.querySelector( '#editor' ), {
  15. plugins: [ EnterPlugin, TypingPlugin, ParagraphPlugin, ImagePlugin, UndoPlugin, ClipboardPlugin ],
  16. toolbar: [ 'undo', 'redo' ]
  17. } )
  18. .then( editor => {
  19. window.editor = editor;
  20. } )
  21. .catch( err => {
  22. console.error( err.stack );
  23. } );
  24. ( function() {
  25. const optionsWrapper = document.getElementById( 'resizer-options' );
  26. const defaultConfig = {
  27. handler: [ 'top-left', 'top-right', 'bottom-right', 'bottom-left' ]
  28. };
  29. const dynamicStylesheet = document.createElement( 'style' );
  30. const cssRules = {};
  31. for ( const checkbox of optionsWrapper.querySelectorAll( 'input[name="handler[]"]' ) ) {
  32. checkbox.addEventListener( 'change', function() {
  33. const ruleValue = `.ck-widget__resizer.ck-widget__resizer-${ this.value } { display: none; }`;
  34. if ( this.value in cssRules ) {
  35. dynamicStylesheet.sheet.deleteRule( cssRules[ this.value ] );
  36. delete cssRules[ this.value ];
  37. }
  38. if ( !this.checked ) {
  39. cssRules[ this.value ] = dynamicStylesheet.sheet.insertRule( ruleValue );
  40. }
  41. } );
  42. if ( defaultConfig.handler.includes( checkbox.value ) ) {
  43. checkbox.checked = true;
  44. }
  45. }
  46. document.head.appendChild( dynamicStylesheet );
  47. }() );