-
Notifications
You must be signed in to change notification settings - Fork 4
/
plugin.js
80 lines (78 loc) · 2.84 KB
/
plugin.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
/**
* @file
* Written by Henri MEDOT <henri.medot[AT]absyx[DOT]fr>
* http://www.absyx.fr
*/
CKEDITOR.tools.createImageData = function(dimensions) {
return 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="' + dimensions.width + '" height="' + dimensions.height + '"></svg>');
};
CKEDITOR.plugins.add('video', {
requires: 'dialog,fakeobjects',
lang: 'en,fr,ru',
icons: 'video',
hidpi: true,
onLoad: function() {
var url = CKEDITOR.getUrl(this.path + 'images/placeholder.png');
CKEDITOR.addCss('img.cke-video{background:#f8f8f8 url(' + url + ') center center no-repeat;outline:1px solid #ccc;outline-offset:-1px;min-width:192px;min-height:108px;max-width:100%;width:auto!important;height:auto!important;}');
},
init: function(editor) {
editor.addCommand('video', new CKEDITOR.dialogCommand('video', {
allowedContent: 'video[autoplay,controls,height,loop,muted,preload,!src,width]'
}));
editor.ui.addButton('Video', {
label: editor.lang.video.button,
command: 'video'
});
CKEDITOR.dialog.add('video', this.path + 'dialogs/video.js');
editor.on('doubleclick', function(e) {
var element = e.data.element;
if (element && element.is('img') && !element.isReadOnly() && element.data('cke-real-element-type') == 'video') {
e.data.dialog = 'video';
}
});
if (editor.addMenuItems) {
editor.addMenuGroup('video', 11);
editor.addMenuItems({
video: {
label: editor.lang.video.title,
command: 'video',
group: 'video'
}
});
}
if (editor.contextMenu) {
editor.contextMenu.addListener(function(element) {
if (element && element.is('img') && !element.isReadOnly() && element.data('cke-real-element-type') == 'video') {
return {video: CKEDITOR.TRISTATE_OFF};
}
});
}
editor.filter.addElementCallback(function(element) {
if (element.name == 'cke:video') {
return CKEDITOR.FILTER_SKIP_TREE;
}
});
editor.lang.fakeobjects.video = editor.lang.video.button;
},
afterInit: function(editor) {
editor.on('toHtml', function(e) {
var html = e.data.dataValue;
html = html.replace(/(<\/?)video\b/gi, '$1cke:video');
e.data.dataValue = html;
}, null, null, 1);
var dataProcessor = editor.dataProcessor;
var dataFilter = dataProcessor && dataProcessor.dataFilter;
if (dataFilter) {
dataFilter.addRules({
elements: {
'cke:video': function(element) {
var attributes = CKEDITOR.tools.extend({}, element.attributes);
element = editor.createFakeParserElement(element, 'cke-video', 'video', false);
element.attributes.src = CKEDITOR.tools.createImageData(attributes);
return element;
}
}
});
}
}
});