resize.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. import ResizerCentral from '@ckeditor/ckeditor5-widget/src/resizercentral';
  14. import ResizerSide from '@ckeditor/ckeditor5-widget/src/resizerside';
  15. ClassicEditor
  16. .create( document.querySelector( '#editor' ), {
  17. plugins: [ EnterPlugin, TypingPlugin, ParagraphPlugin, ImagePlugin, UndoPlugin, ClipboardPlugin ],
  18. toolbar: [ 'undo', 'redo' ]
  19. } )
  20. .then( editor => {
  21. window.editor = editor;
  22. } )
  23. .catch( err => {
  24. console.error( err.stack );
  25. } );
  26. ( function() {
  27. const optionsWrapper = document.getElementById( 'resizer-options' );
  28. const defaultConfig = {
  29. handler: [ 'top-left', 'top-right', 'bottom-right', 'bottom-left' ]
  30. };
  31. const dynamicStylesheet = document.createElement( 'style' );
  32. const cssRules = {};
  33. for ( const checkbox of optionsWrapper.querySelectorAll( 'input[name="handler[]"]' ) ) {
  34. checkbox.addEventListener( 'change', function() {
  35. const ruleValue = `.ck-widget__resizer.ck-widget__resizer-${ this.value } { display: none; }`;
  36. if ( this.value in cssRules ) {
  37. dynamicStylesheet.sheet.deleteRule( cssRules[ this.value ] );
  38. delete cssRules[ this.value ];
  39. }
  40. if ( !this.checked ) {
  41. cssRules[ this.value ] = dynamicStylesheet.sheet.insertRule( ruleValue );
  42. }
  43. } );
  44. if ( defaultConfig.handler.includes( checkbox.value ) ) {
  45. checkbox.checked = true;
  46. }
  47. }
  48. document.head.appendChild( dynamicStylesheet );
  49. // Resize using image
  50. document.getElementById( 'resize-image' ).addEventListener( 'change', function() {
  51. window.pocResizeUsingImage = this.checked;
  52. } );
  53. // Resize strategy
  54. document.getElementById( 'strategy' ).addEventListener( 'change', function() {
  55. const strategies = {
  56. 'center': ResizerCentral,
  57. 'side': ResizerSide
  58. };
  59. window.editor.plugins.get( 'WidgetResizer' ).set( 'resizerStrategy', strategies[ this.value ] );
  60. console.log( this.value, window.pocResizeStrategy );
  61. } );
  62. }() );