restrictededitingexceptionediting.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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/restrictededitingexceptionediting
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import RestrictedEditingExceptionCommand from './restrictededitingexceptioncommand';
  10. /**
  11. * @extends module:core/plugin~Plugin
  12. */
  13. export default class RestrictedEditingExceptionEditing extends Plugin {
  14. /**
  15. * @inheritDoc
  16. */
  17. static get pluginName() {
  18. return 'RestrictedEditingExceptionEditing';
  19. }
  20. /**
  21. * @inheritDoc
  22. */
  23. init() {
  24. const editor = this.editor;
  25. editor.model.schema.extend( '$text', { allowAttributes: [ 'restrictedEditingException' ] } );
  26. editor.conversion.for( 'upcast' ).elementToAttribute( {
  27. model: 'restrictedEditingException',
  28. view: {
  29. name: 'span',
  30. classes: 'ck-restricted-editing-exception'
  31. }
  32. } );
  33. editor.conversion.for( 'downcast' ).attributeToElement( {
  34. model: 'restrictedEditingException',
  35. view: ( modelAttributeValue, viewWriter ) => {
  36. if ( modelAttributeValue ) {
  37. // Make the restricted editing <span> outer-most in the view.
  38. return viewWriter.createAttributeElement( 'span', { class: 'ck-restricted-editing-exception' }, { priority: -10 } );
  39. }
  40. }
  41. } );
  42. editor.commands.add( 'restrictedEditingException', new RestrictedEditingExceptionCommand( editor ) );
  43. }
  44. }