linkdecorator.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals console:false, window, document */
  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. ClassicEditor
  14. .create( document.querySelector( '#editor' ), {
  15. plugins: [ Link, Typing, Paragraph, Clipboard, Undo, Enter ],
  16. toolbar: [ 'link', 'undo', 'redo' ],
  17. link: {
  18. decorators: [
  19. {
  20. mode: 'manual',
  21. label: 'Open in new window',
  22. attributes: {
  23. target: '_blank',
  24. rel: 'noopener noreferrer'
  25. }
  26. },
  27. {
  28. mode: 'manual',
  29. label: 'Downloadable',
  30. attributes: {
  31. download: 'download'
  32. }
  33. },
  34. {
  35. mode: 'manual',
  36. label: 'Gallery link',
  37. attributes: {
  38. class: 'gallery'
  39. }
  40. }
  41. ]
  42. }
  43. } )
  44. .then( editor => {
  45. if ( !window.editors ) {
  46. window.editors = {};
  47. }
  48. window.editor = 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. {
  61. mode: 'automatic',
  62. callback: url => url.startsWith( 'tel:' ),
  63. attributes: {
  64. class: 'phone'
  65. }
  66. },
  67. {
  68. mode: 'automatic',
  69. callback: url => url.startsWith( '#' ),
  70. attributes: {
  71. class: 'internal'
  72. }
  73. }
  74. ],
  75. targetDecorator: true
  76. }
  77. } )
  78. .then( editor => {
  79. if ( !window.editors ) {
  80. window.editors = {};
  81. }
  82. window.editors.autoamticDecorators = editor;
  83. } )
  84. .catch( err => {
  85. console.error( err.stack );
  86. } );