linkdecorator.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals console:false, window, document, CKEditorInspector */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  8. import LinkImage from '../../src/linkimage';
  9. // Just to have nicely styles switchbutton;
  10. import '@ckeditor/ckeditor5-theme-lark/theme/ckeditor5-ui/components/list/list.css';
  11. window.editors = {};
  12. ClassicEditor
  13. .create( document.querySelector( '#editor' ), {
  14. plugins: [ ArticlePluginSet, LinkImage ],
  15. toolbar: [ 'link', 'undo', 'redo' ],
  16. link: {
  17. decorators: {
  18. isExternal: {
  19. mode: 'manual',
  20. label: 'Open in a new tab',
  21. attributes: {
  22. target: '_blank',
  23. rel: 'noopener noreferrer'
  24. }
  25. },
  26. isDownloadable: {
  27. mode: 'manual',
  28. label: 'Downloadable',
  29. attributes: {
  30. download: 'download'
  31. }
  32. },
  33. isGallery: {
  34. mode: 'manual',
  35. label: 'Gallery link',
  36. attributes: {
  37. class: 'gallery'
  38. }
  39. }
  40. }
  41. },
  42. image: {
  43. toolbar: [ 'imageStyle:full', 'imageStyle:side', '|', 'imageTextAlternative', '|', 'linkImage' ]
  44. }
  45. } )
  46. .then( editor => {
  47. CKEditorInspector.attach( 'manual', editor );
  48. window.editors.manualDecorators = editor;
  49. } )
  50. .catch( err => {
  51. console.error( err.stack );
  52. } );
  53. ClassicEditor
  54. .create( document.querySelector( '#editor2' ), {
  55. plugins: [ ArticlePluginSet, LinkImage ],
  56. toolbar: [ 'link', 'undo', 'redo' ],
  57. link: {
  58. decorators: {
  59. isTelephone: {
  60. mode: 'automatic',
  61. callback: url => url.startsWith( 'tel:' ),
  62. attributes: {
  63. class: 'phone'
  64. }
  65. },
  66. isInternal: {
  67. mode: 'automatic',
  68. callback: url => url.startsWith( '#' ),
  69. attributes: {
  70. class: 'internal'
  71. }
  72. }
  73. },
  74. addTargetToExternalLinks: true
  75. },
  76. image: {
  77. toolbar: [ 'imageStyle:full', 'imageStyle:side', '|', 'imageTextAlternative', '|', 'linkImage' ]
  78. }
  79. } )
  80. .then( editor => {
  81. CKEditorInspector.attach( 'automatic', editor );
  82. window.editors.automaticDecorators = editor;
  83. } )
  84. .catch( err => {
  85. console.error( err.stack );
  86. } );