1.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals console, window, document */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  8. ClassicEditor
  9. .create( document.querySelector( '#editor' ), {
  10. plugins: [ ArticlePluginSet ],
  11. toolbar: {
  12. items: [
  13. 'headings',
  14. 'bold',
  15. 'italic',
  16. 'link',
  17. 'bulletedList',
  18. 'numberedList',
  19. 'blockQuote',
  20. 'undo',
  21. 'redo'
  22. ]
  23. },
  24. image: {
  25. toolbar: [
  26. 'imageStyleFull',
  27. 'imageStyleSide',
  28. '|',
  29. 'imageTextAlternative'
  30. ]
  31. }
  32. } )
  33. .then( editor => {
  34. window.editor = editor;
  35. const schema = editor.model.schema;
  36. schema.on( 'checkAttribute', ( evt, args ) => {
  37. const ctx = args[ 0 ];
  38. const attributeName = args[ 1 ];
  39. if ( ctx.endsWith( 'heading1 $text' ) && [ 'linkHref', 'italic' ].includes( attributeName ) ) {
  40. evt.stop();
  41. evt.return = false;
  42. }
  43. if ( ctx.endsWith( 'heading2 $text' ) && attributeName == 'italic' ) {
  44. evt.stop();
  45. evt.return = false;
  46. }
  47. if ( ctx.endsWith( 'heading2 $text' ) && attributeName == 'italic' ) {
  48. evt.stop();
  49. evt.return = false;
  50. }
  51. if ( ctx.endsWith( 'blockQuote listItem $text' ) && attributeName == 'linkHref' ) {
  52. evt.stop();
  53. evt.return = false;
  54. }
  55. if ( ctx.endsWith( 'paragraph $text' ) && attributeName == 'bold' ) {
  56. evt.stop();
  57. evt.return = false;
  58. }
  59. } );
  60. schema.addChildCheck( ( ctx, childDef ) => {
  61. if ( ctx.endsWith( '$root' ) && childDef.name == 'heading3' ) {
  62. return false;
  63. }
  64. } );
  65. } )
  66. .catch( err => {
  67. console.error( err.stack );
  68. } );