extending-content-allow-link-target.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals ClassicEditor, console, window, document */
  6. import { CS_CONFIG } from '@ckeditor/ckeditor5-cloud-services/tests/_utils/cloud-services-config';
  7. function AllowLinkTarget( editor ) {
  8. editor.model.schema.extend( '$text', { allowAttributes: 'linkTarget' } );
  9. editor.conversion.for( 'downcast' ).attributeToElement( {
  10. model: 'linkTarget',
  11. view: ( attributeValue, writer ) => {
  12. return writer.createAttributeElement( 'a', { target: attributeValue }, { priority: 5 } );
  13. },
  14. converterPriority: 'low'
  15. } );
  16. editor.conversion.for( 'upcast' ).attributeToAttribute( {
  17. view: {
  18. name: 'a',
  19. key: 'target'
  20. },
  21. model: 'linkTarget',
  22. converterPriority: 'low'
  23. } );
  24. }
  25. ClassicEditor
  26. .create( document.querySelector( '#snippet-link-target' ), {
  27. cloudServices: CS_CONFIG,
  28. extraPlugins: [ AllowLinkTarget ],
  29. toolbar: {
  30. viewportTopOffset: window.getViewportTopOffsetConfig()
  31. }
  32. } )
  33. .then( editor => {
  34. window.editor = editor;
  35. document.querySelector( '#snippet-link-target-content-update' ).addEventListener( 'click', () => {
  36. editor.setData( document.querySelector( '#snippet-link-target-content' ).value );
  37. } );
  38. } )
  39. .catch( err => {
  40. console.error( err.stack );
  41. } );