This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
linkdecorator.js
90 lines (84 loc) · 2.22 KB
/
linkdecorator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/
/* globals console:false, window, document, CKEditorInspector */
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
import Enter from '@ckeditor/ckeditor5-enter/src/enter';
import Typing from '@ckeditor/ckeditor5-typing/src/typing';
import Link from '../../src/link';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import Undo from '@ckeditor/ckeditor5-undo/src/undo';
import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
// Just to have nicely styles switchbutton;
import '@ckeditor/ckeditor5-theme-lark/theme/ckeditor5-ui/components/list/list.css';
window.editors = {};
ClassicEditor
.create( document.querySelector( '#editor' ), {
plugins: [ Link, Typing, Paragraph, Clipboard, Undo, Enter ],
toolbar: [ 'link', 'undo', 'redo' ],
link: {
decorators: {
isExternal: {
mode: 'manual',
label: 'Open in a new tab',
attributes: {
target: '_blank',
rel: 'noopener noreferrer'
}
},
isDownloadable: {
mode: 'manual',
label: 'Downloadable',
attributes: {
download: 'download'
}
},
isGallery: {
mode: 'manual',
label: 'Gallery link',
attributes: {
class: 'gallery'
}
}
}
}
} )
.then( editor => {
CKEditorInspector.attach( 'manual', editor );
window.editors.manualDecorators = editor;
} )
.catch( err => {
console.error( err.stack );
} );
ClassicEditor
.create( document.querySelector( '#editor2' ), {
plugins: [ Link, Typing, Paragraph, Clipboard, Undo, Enter ],
toolbar: [ 'link', 'undo', 'redo' ],
link: {
decorators: {
isTelephone: {
mode: 'automatic',
callback: url => url.startsWith( 'tel:' ),
attributes: {
class: 'phone'
}
},
isInternal: {
mode: 'automatic',
callback: url => url.startsWith( '#' ),
attributes: {
class: 'internal'
}
}
},
addTargetToExternalLinks: true
}
} )
.then( editor => {
CKEditorInspector.attach( 'automatic', editor );
window.editors.automaticDecorators = editor;
} )
.catch( err => {
console.error( err.stack );
} );