inline-editor.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals console, window, document */
  6. import InlineEditor from '@ckeditor/ckeditor5-editor-inline/src/inlineeditor';
  7. import fullSizeIcon from '@ckeditor/ckeditor5-core/theme/icons/object-center.svg';
  8. import alignLeftIcon from '@ckeditor/ckeditor5-core/theme/icons/object-left.svg';
  9. import alignRightIcon from '@ckeditor/ckeditor5-core/theme/icons/object-right.svg';
  10. import ArticlePreset from '@ckeditor/ckeditor5-presets/src/article';
  11. const inlineInjectElements = document.querySelectorAll( '#snippet-inline-editor [data-inline-inject]' );
  12. Array.prototype.map.call( inlineInjectElements, inlineElement => {
  13. const config = {
  14. plugins: [ ArticlePreset ],
  15. toolbar: [ 'headings', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ],
  16. image: {
  17. toolbar: [ 'imageTextAlternative', '|', 'imageStyleLeft', 'imageStyleFull', 'imageStyleRight' ],
  18. styles: [
  19. {
  20. name: 'imageStyleFull',
  21. title: 'Full size image',
  22. icon: fullSizeIcon,
  23. value: null
  24. },
  25. {
  26. name: 'imageStyleLeft',
  27. title: 'Left aligned image',
  28. icon: alignLeftIcon,
  29. value: 'left',
  30. className: 'image-style-left'
  31. },
  32. {
  33. name: 'imageStyleRight',
  34. title: 'Right aligned image',
  35. icon: alignRightIcon,
  36. value: 'right',
  37. className: 'image-style-right'
  38. }
  39. ]
  40. }
  41. };
  42. if ( inlineElement.tagName.toLowerCase() == 'header' ) {
  43. config.removePlugins = [ 'Blockquote', 'Image', 'ImageToolbar', 'List' ];
  44. config.toolbar = [ 'headings', 'bold', 'italic', 'link' ];
  45. }
  46. InlineEditor.create( inlineElement, config )
  47. .then( editor => {
  48. window.editor = editor;
  49. } )
  50. .catch( err => {
  51. console.error( err );
  52. } );
  53. } );