-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplugin.js
84 lines (73 loc) · 2.32 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
81
82
83
84
CKEDITOR.plugins.add('btcards', {
requires: 'widget,dialog,contextmenu,smethods',
lang: 'en,ru,uk',
icons: 'btcards',
init: function(editor){
var commandDefinition = {
exec: function(editor){
var c = this.name.replace(/.{4}/, '$&-'),
div = editor.document.createElement('div', {attributes: {class: c}}),
el = editor.widgets.getByElement(editor.getSelection().getStartElement()).element;
(c == 'card-body' && el.findOne('.card-footer')) ? div.insertBefore(el.getLast()) : el.append(div, c == 'card-header');
}
};
CKEDITOR.dialog.add('btcards', this.path + 'dialogs/btcards.js');
editor.addCommands({
cardHeader: commandDefinition,
cardBody: commandDefinition,
cardFooter: commandDefinition
});
editor.widgets.add('btcards', {
allowedContent: 'div(!card,card-header,card-body,card-footer)',
requiredContent: 'div(card)',
editables: { content: 'div' },
template: '<div class="card"><div></div></div>',
button: editor.lang.btcards.label,
dialog: 'btcards',
upcast: function(element){
return element.name == 'div' && element.hasClass('card');
},
init: function(){
this.setData('style', this.element.getAttribute('style'));
this.on('dialog', function(e){
e.data.widget = this;
}, this);
},
data: function(){
this.data.style ? this.element.setAttribute('style', this.data.style) : this.element.removeAttribute('style');
}
});
editor.addMenuGroup('btcards');
editor.addMenuItems({
cardHeader: {
label: editor.lang.btcards.header,
command: 'cardHeader',
group: 'btcards',
order: 1
},
cardBody: {
label: editor.lang.btcards.cbody,
command: 'cardBody',
group: 'btcards',
order: 1
},
cardFooter: {
label: editor.lang.btcards.footer,
command: 'cardFooter',
group: 'btcards',
order: 2
}
});
editor.contextMenu.addListener(function(element){
var card = editor.widgets.getByElement(element);
if (card && card.element.hasClass('card'))
if (card.element.findOne('.card-body'))
return {
cardHeader: card.element.findOne('.card-header') ? CKEDITOR.TRISTATE_DISABLED : CKEDITOR.TRISTATE_OFF,
cardFooter: card.element.findOne('.card-footer') ? CKEDITOR.TRISTATE_DISABLED : CKEDITOR.TRISTATE_OFF
};
else
return { cardBody: CKEDITOR.TRISTATE_OFF };
});
}
});