-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathckeditor-iframely-previews-gists.js
62 lines (49 loc) · 2.17 KB
/
ckeditor-iframely-previews-gists.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
import MediaEmbed from '@ckeditor/ckeditor5-media-embed/src/mediaembed';
var IFRAME_SRC = '//cdn.iframe.ly/api/iframe';
var API_KEY = '...';
// Your API key from https://iframely.com/profile';
var editorInstance;
ClassicEditor
.create( document.querySelector( '#editor' ), {
plugins: [
// Include 'MediaEmbed' plugin among others.
MediaEmbed
],
toolbar: [ 'mediaEmbed', 'bold', 'italic' ],
// Configure 'mediaEmbed' with Iframely previews.
mediaEmbed: {
// Enable previews.
previewsInData: true,
providers: [
{
// hint: this is just for previews. Get actual HTML codes by making API calls from your CMS
name: 'iframely previews',
// Match all URLs or just the ones you need:
url: /.+/,
html: match => {
const url = match[ 0 ];
var iframeUrl = IFRAME_SRC + '?app=1&api_key=' + API_KEY + '&url=' + encodeURIComponent(url);
// alternatively, use &key= instead of &api_key with the MD5 hash of your api_key
// more about it: http://dev.iframely.com/docs/allow-origins
return (
// If you need, set maxwidth and other styles for 'iframely-embed' class - it's yours to customize
'<div class="iframely-embed">' +
'<div class="iframely-responsive">' +
`<iframe src="${ iframeUrl }" ` +
'frameborder="0" allow="autoplay; encrypted-media" allowfullscreen>' +
'</iframe>' +
'</div>' +
'</div>'
);
}
}
]
}
} )
.then( editor => {
console.log( 'Editor was initialized', editor );
// Store editor markup, etc.
} )
.catch( error => {
console.error( error.stack );
} );