8
0

imageresizeui.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 ImageResize from '../../src/imageresize';
  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. ImageResize,
  17. Indent,
  18. IndentBlock,
  19. EasyImage
  20. ],
  21. toolbar: [ 'heading', '|', 'bold', 'italic', 'link',
  22. 'bulletedList', 'numberedList', 'blockQuote', 'insertTable', 'undo', 'redo', 'outdent', 'indent' ],
  23. table: {
  24. contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells' ],
  25. tableToolbar: [ 'bold', 'italic' ]
  26. },
  27. cloudServices: CS_CONFIG
  28. };
  29. const imageConfig1 = {
  30. resizeUnit: '%',
  31. resizeOptions: [
  32. {
  33. name: 'imageResize:original',
  34. label: 'Original size',
  35. value: null
  36. },
  37. {
  38. name: 'imageResize:50',
  39. label: '50%',
  40. value: '50'
  41. },
  42. {
  43. name: 'imageResize:75',
  44. label: '75%',
  45. value: '75'
  46. }
  47. ],
  48. toolbar: [ 'imageStyle:alignLeft', 'imageStyle:full', 'imageStyle:side', '|', 'imageResize' ],
  49. styles: [
  50. 'full',
  51. 'alignLeft',
  52. 'side' // Purposely using side image instead right aligned image to make sure it works well with both style types.
  53. ]
  54. };
  55. const config1 = {
  56. ...commonConfig,
  57. image: imageConfig1
  58. };
  59. ClassicEditor
  60. .create( document.querySelector( '#editor1' ), config1 )
  61. .then( editor => {
  62. window.editor = editor;
  63. } )
  64. .catch( err => {
  65. console.error( err.stack );
  66. } );
  67. const imageConfig2 = {
  68. resizeUnit: '%',
  69. resizeOptions: [
  70. {
  71. name: 'imageResize:original',
  72. label: 'Original size',
  73. value: null
  74. },
  75. {
  76. name: 'imageResize:50',
  77. label: '50%',
  78. value: '50'
  79. },
  80. {
  81. name: 'imageResize:75',
  82. label: '75%',
  83. value: '75'
  84. }
  85. ],
  86. toolbar: [
  87. 'imageStyle:alignLeft',
  88. 'imageStyle:full',
  89. 'imageStyle:side', '|',
  90. 'imageResize:original',
  91. 'imageResize:50',
  92. 'imageResize:75'
  93. ],
  94. styles: [
  95. 'full',
  96. 'alignLeft',
  97. 'side' // Purposely using side image instead right aligned image to make sure it works well with both style types.
  98. ]
  99. };
  100. const config2 = {
  101. ...commonConfig,
  102. image: imageConfig2
  103. };
  104. ClassicEditor
  105. .create( document.querySelector( '#editor2' ), config2 )
  106. .then( editor => {
  107. window.editor = editor;
  108. } )
  109. .catch( err => {
  110. console.error( err.stack );
  111. } );