imageresizebuttons.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. /* global document, console, window */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  8. import Indent from '@ckeditor/ckeditor5-indent/src/indent';
  9. import IndentBlock from '@ckeditor/ckeditor5-indent/src/indentblock';
  10. import EasyImage from '@ckeditor/ckeditor5-easy-image/src/easyimage';
  11. import ImageResizeEditing from '../../src/imageresize/imageresizeediting';
  12. import ImageResizeButtons from '../../src/imageresize/imageresizebuttons';
  13. import { CS_CONFIG } from '@ckeditor/ckeditor5-cloud-services/tests/_utils/cloud-services-config';
  14. const commonConfig = {
  15. plugins: [
  16. ArticlePluginSet,
  17. Indent,
  18. IndentBlock,
  19. EasyImage,
  20. ImageResizeEditing,
  21. ImageResizeButtons
  22. ],
  23. toolbar: [ 'heading', '|', 'bold', 'italic', 'link',
  24. 'bulletedList', 'numberedList', 'blockQuote', 'insertTable', 'undo', 'redo', 'outdent', 'indent' ],
  25. table: {
  26. contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells' ],
  27. tableToolbar: [ 'bold', 'italic' ]
  28. },
  29. cloudServices: CS_CONFIG
  30. };
  31. // Editor 1
  32. const imageConfig1 = {
  33. resizeUnit: '%',
  34. resizeOptions: [
  35. {
  36. name: 'imageResize:original',
  37. value: null
  38. },
  39. {
  40. name: 'imageResize:50',
  41. value: '50'
  42. },
  43. {
  44. name: 'imageResize:75',
  45. value: '75'
  46. }
  47. ],
  48. toolbar: [ 'imageStyle:alignLeft', 'imageStyle:alignCenter', 'imageStyle:alignRight', '|', 'imageResize' ],
  49. styles: [
  50. 'alignLeft',
  51. 'alignCenter',
  52. 'alignRight'
  53. ]
  54. };
  55. const config1 = {
  56. ...commonConfig,
  57. image: imageConfig1
  58. };
  59. ClassicEditor
  60. .create( document.querySelector( '#editor1' ), config1 )
  61. .then( editor => {
  62. window.editor1 = editor;
  63. } )
  64. .catch( err => {
  65. console.error( err.stack );
  66. } );
  67. // Editor 2
  68. const imageConfig2 = {
  69. resizeUnit: '%',
  70. resizeOptions: [
  71. {
  72. name: 'imageResize:original',
  73. value: null,
  74. icon: 'original'
  75. },
  76. {
  77. name: 'imageResize:50',
  78. value: '50',
  79. icon: 'medium'
  80. },
  81. {
  82. name: 'imageResize:75',
  83. value: '75',
  84. icon: 'large'
  85. }
  86. ],
  87. toolbar: [
  88. 'imageStyle:alignLeft',
  89. 'imageStyle:full',
  90. 'imageStyle:side', '|',
  91. 'imageResize:50',
  92. 'imageResize:75',
  93. 'imageResize:original'
  94. ],
  95. styles: [
  96. 'full',
  97. 'alignLeft',
  98. 'side' // Purposely using side image instead right aligned image to make sure it works well with both style types.
  99. ]
  100. };
  101. const config2 = {
  102. ...commonConfig,
  103. image: imageConfig2
  104. };
  105. ClassicEditor
  106. .create( document.querySelector( '#editor2' ), config2 )
  107. .then( editor => {
  108. window.editor2 = editor;
  109. } )
  110. .catch( err => {
  111. console.error( err.stack );
  112. } );