linkdecorator.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 Enter from '@ckeditor/ckeditor5-enter/src/enter';
  8. import Typing from '@ckeditor/ckeditor5-typing/src/typing';
  9. import Link from '../../src/link';
  10. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  11. import Undo from '@ckeditor/ckeditor5-undo/src/undo';
  12. import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
  13. // Just to have nicely styles switchbutton;
  14. import '@ckeditor/ckeditor5-theme-lark/theme/ckeditor5-ui/components/list/list.css';
  15. window.editors = {};
  16. ClassicEditor
  17. .create( document.querySelector( '#editor' ), {
  18. plugins: [ Link, Typing, Paragraph, Clipboard, Undo, Enter ],
  19. toolbar: [ 'link', 'undo', 'redo' ],
  20. link: {
  21. decorators: {
  22. isExternal: {
  23. mode: 'manual',
  24. label: 'Open in a new tab',
  25. attributes: {
  26. target: '_blank',
  27. rel: 'noopener noreferrer'
  28. }
  29. },
  30. isDownloadable: {
  31. mode: 'manual',
  32. label: 'Downloadable',
  33. attributes: {
  34. download: 'download'
  35. }
  36. },
  37. isGallery: {
  38. mode: 'manual',
  39. label: 'Gallery link',
  40. attributes: {
  41. class: 'gallery'
  42. }
  43. }
  44. }
  45. }
  46. } )
  47. .then( editor => {
  48. CKEditorInspector.attach( 'manual', editor );
  49. window.editors.manualDecorators = editor;
  50. } )
  51. .catch( err => {
  52. console.error( err.stack );
  53. } );
  54. ClassicEditor
  55. .create( document.querySelector( '#editor2' ), {
  56. plugins: [ Link, Typing, Paragraph, Clipboard, Undo, Enter ],
  57. toolbar: [ 'link', 'undo', 'redo' ],
  58. link: {
  59. decorators: {
  60. isTelephone: {
  61. mode: 'automatic',
  62. callback: url => url.startsWith( 'tel:' ),
  63. attributes: {
  64. class: 'phone'
  65. }
  66. },
  67. isInternal: {
  68. mode: 'automatic',
  69. callback: url => url.startsWith( '#' ),
  70. attributes: {
  71. class: 'internal'
  72. }
  73. }
  74. },
  75. addTargetToExternalLinks: true
  76. }
  77. } )
  78. .then( editor => {
  79. CKEditorInspector.attach( 'automatic', editor );
  80. window.editors.automaticDecorators = editor;
  81. } )
  82. .catch( err => {
  83. console.error( err.stack );
  84. } );