standardeditingmodeediting.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /**
  6. * @module restricted-editing/standardeditingmodeediting
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import RestrictedEditingExceptionCommand from './restrictededitingexceptioncommand';
  10. /**
  11. * The Standard Editing Mode editing feature.
  12. *
  13. * * It introduces the `restrictedEditingException` text attributes that is rendered as
  14. * `<spans>` with the `restricted-editing-exception` CSS class.
  15. * * It registers the `'restrictedEditingException'` command.
  16. *
  17. * @extends module:core/plugin~Plugin
  18. */
  19. export default class StandardEditingModeEditing extends Plugin {
  20. /**
  21. * @inheritDoc
  22. */
  23. static get pluginName() {
  24. return 'StandardEditingModeEditing';
  25. }
  26. /**
  27. * @inheritDoc
  28. */
  29. init() {
  30. const editor = this.editor;
  31. editor.model.schema.extend( '$text', { allowAttributes: [ 'restrictedEditingException' ] } );
  32. editor.conversion.for( 'upcast' ).elementToAttribute( {
  33. model: 'restrictedEditingException',
  34. view: {
  35. name: 'span',
  36. classes: 'restricted-editing-exception'
  37. }
  38. } );
  39. editor.conversion.for( 'downcast' ).attributeToElement( {
  40. model: 'restrictedEditingException',
  41. view: ( modelAttributeValue, viewWriter ) => {
  42. if ( modelAttributeValue ) {
  43. // Make the restricted editing <span> outer-most in the view.
  44. return viewWriter.createAttributeElement( 'span', { class: 'restricted-editing-exception' }, { priority: -10 } );
  45. }
  46. }
  47. } );
  48. editor.commands.add( 'restrictedEditingException', new RestrictedEditingExceptionCommand( editor ) );
  49. editor.editing.view.change( writer => {
  50. for ( const root of editor.editing.view.document.roots ) {
  51. writer.addClass( 'ck-restricted-editing_mode_standard', root );
  52. }
  53. } );
  54. }
  55. }