imageresizeui.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 ImageResizeUI from '../../src/imageresize/ui/imageresizeui';
  9. import Indent from '@ckeditor/ckeditor5-indent/src/indent';
  10. import IndentBlock from '@ckeditor/ckeditor5-indent/src/indentblock';
  11. import EasyImage from '@ckeditor/ckeditor5-easy-image/src/easyimage';
  12. import { CS_CONFIG } from '@ckeditor/ckeditor5-cloud-services/tests/_utils/cloud-services-config';
  13. const commonConfig = {
  14. plugins: [
  15. ArticlePluginSet,
  16. ImageResizeUI,
  17. Indent,
  18. IndentBlock,
  19. EasyImage
  20. ],
  21. toolbar: [ 'heading', '|', 'bold', 'italic', 'link',
  22. 'bulletedList', 'numberedList', 'blockQuote', 'insertTable', 'undo', 'redo', 'outdent', 'indent' ],
  23. image: {
  24. resizeUnit: '%',
  25. imageResizeOptions: [
  26. {
  27. name: 'imageResize:original',
  28. label: 'Original size',
  29. value: null
  30. },
  31. {
  32. name: 'imageResize:50',
  33. label: '50%',
  34. value: '50'
  35. },
  36. {
  37. name: 'imageResize:75',
  38. label: '75%',
  39. value: '75'
  40. }
  41. ],
  42. toolbar: [ 'imageStyle:alignLeft', 'imageStyle:full', 'imageStyle:side', '|', 'imageResize' ],
  43. styles: [
  44. 'full',
  45. 'alignLeft',
  46. 'side' // Purposely using side image instead right aligned image to make sure it works well with both style types.
  47. ]
  48. },
  49. table: {
  50. contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells' ],
  51. tableToolbar: [ 'bold', 'italic' ]
  52. },
  53. cloudServices: CS_CONFIG
  54. };
  55. const imageConfig1 = {
  56. resizeUnit: '%',
  57. imageResizeOptions: [
  58. {
  59. name: 'imageResize:original',
  60. label: 'Original size',
  61. value: null
  62. },
  63. {
  64. name: 'imageResize:50',
  65. label: '50%',
  66. value: '50'
  67. },
  68. {
  69. name: 'imageResize:75',
  70. label: '75%',
  71. value: '75'
  72. }
  73. ],
  74. toolbar: [ 'imageStyle:alignLeft', 'imageStyle:full', 'imageStyle:side', '|', 'imageResize' ],
  75. styles: [
  76. 'full',
  77. 'alignLeft',
  78. 'side' // Purposely using side image instead right aligned image to make sure it works well with both style types.
  79. ]
  80. };
  81. const config1 = {
  82. ...commonConfig,
  83. image: imageConfig1
  84. };
  85. ClassicEditor
  86. .create( document.querySelector( '#editor1' ), config1 )
  87. .then( editor => {
  88. window.editor = editor;
  89. } )
  90. .catch( err => {
  91. console.error( err.stack );
  92. } );
  93. const imageConfig2 = {
  94. resizeUnit: '%',
  95. imageResizeOptions: [
  96. {
  97. name: 'imageResize:original',
  98. label: 'Original size',
  99. value: null
  100. },
  101. {
  102. name: 'imageResize:50',
  103. label: '50%',
  104. value: '50'
  105. },
  106. {
  107. name: 'imageResize:75',
  108. label: '75%',
  109. value: '75'
  110. }
  111. ],
  112. toolbar: [
  113. 'imageStyle:alignLeft',
  114. 'imageStyle:full',
  115. 'imageStyle:side', '|',
  116. 'imageResize:original',
  117. 'imageResize:50',
  118. 'imageResize:75'
  119. ],
  120. styles: [
  121. 'full',
  122. 'alignLeft',
  123. 'side' // Purposely using side image instead right aligned image to make sure it works well with both style types.
  124. ]
  125. };
  126. const config2 = {
  127. ...commonConfig,
  128. image: imageConfig2
  129. };
  130. ClassicEditor
  131. .create( document.querySelector( '#editor2' ), config2 )
  132. .then( editor => {
  133. window.editor = editor;
  134. } )
  135. .catch( err => {
  136. console.error( err.stack );
  137. } );