-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.js
134 lines (106 loc) · 5.89 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
(function () {
CKEDITOR.plugins.add('ckbutton', {
lang: 'en',
requires: 'widget,dialog',
icons: 'ckbutton',
init: function (editor) {
// Allow any attributes.
editor.config.extraAllowedContent = '*(*);*{*}';
var lang = editor.lang.ckbutton;
console.log(editor);
CKEDITOR.dialog.add('ckbutton', this.path + 'dialogs/ckbutton.js');
// Add widget
editor.ui.addButton('ckbutton', {
label: lang.buttonTitle,
command: 'ckbutton',
icon: this.path + 'icons/ckbutton.png'
});
editor.widgets.add('ckbutton', {
dialog: 'ckbutton',
allowedContent: 'a(ckbutton)',
template: '<a class="ckbutton">' + '<span class="text"></span>' + '</a>',
init: function () {
var $el = jQuery(this.element.$);
this.data.styles = $el.attr('data-custom-button');
this.data.href = $el.attr('href');
this.data.target = $el.attr('target');
this.data.text = jQuery('.text', $el).text();
var bs_icon_left = jQuery('.bs-icon-left', $el);
var bs_icon_right = jQuery('.bs-icon-right', $el);
var fa_icon_left = jQuery('.fa-icon-left', $el);
var fa_icon_right = jQuery('.fa-icon-right', $el);
if (bs_icon_left.length > 0) {
bs_icon_left.removeClass('bs-icon-left').removeClass('glyphicon');
this.data.bsiconleft = bs_icon_left.attr('class');
bs_icon_left.addClass('bs-icon-left').addClass('glyphicon');
}
if (bs_icon_right.length > 0) {
bs_icon_right.removeClass('bs-icon-right').removeClass('glyphicon');
this.data.bsiconright = bs_icon_right.attr('class');
bs_icon_right.addClass('bs-icon-right').addClass('glyphicon');
}
if (fa_icon_left.length > 0) {
fa_icon_left.removeClass('fa-icon-left').removeClass('fa');
this.data.faiconleft = fa_icon_left.attr('class');
fa_icon_left.addClass('fa-icon-left').addClass('fa');
}
if (fa_icon_right.length > 0) {
fa_icon_right.removeClass('fa-icon-right').removeClass('fa');
this.data.faiconright = fa_icon_right.attr('class');
fa_icon_right.addClass('fa-icon-right').addClass('fa');
}
},
data: function () {
var $el = jQuery(this.element.$);
var styles = this.editor.config.buttonStylesSet;
var buttonStyle = styles[this.data.styles];
if (buttonStyle) {
$el.attr('data-custom-button', this.data.styles);
for (var i = 0; i < styles.length; i++) {
$el.removeClass(styles[i].attributes.class);
}
$el.addClass(buttonStyle.attributes.class)
}
if (this.data.href) {
$el.attr('href', this.data.href);
this.element.$.removeAttribute('data-cke-saved-href');
}
if (this.data.target && this.data.target != '') {
$el.attr('target', this.data.target);
}
if (this.data.text) {
jQuery('.text', $el).text(this.data.text);
}
if (this.data.hasOwnProperty('bsiconleft')) {
jQuery('.bs-icon-left', $el).remove();
if (this.data.bsiconleft) {
$el.prepend(`<span style="word-spacing: -1em;" class="bs-icon-left glyphicon ${this.data.bsiconleft}"> </span>\n`);
}
}
if (this.data.hasOwnProperty('bsiconright')) {
jQuery('.bs-icon-right', $el).remove();
if (this.data.bsiconright) {
$el.append(`<span style="word-spacing: -1em;" class="bs-icon-right glyphicon ${this.data.bsiconright}"> </span>\n`);
}
}
if (this.data.hasOwnProperty('faiconleft')) {
jQuery('.fa-icon-left', $el).remove();
if (this.data.faiconleft) {
$el.prepend(`<i style="word-spacing: -1em;" class="fa fa-icon-left ${this.data.faiconleft}"> </i>\n`);
}
}
if (this.data.hasOwnProperty('faiconright')) {
jQuery('.fa-icon-right', $el).remove();
if (this.data.faiconright) {
$el.append(`<i style="word-spacing: -1em;" class="fa fa-icon-right ${this.data.faiconright}"> </i>\n`);
}
}
},
upcast: function (element) {
return (element.name == 'a' || element.name == 'button') && element.hasClass('ckbutton');
}
});
}
}
);
})();