forked from smonetti/btbutton
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplugin.js
153 lines (124 loc) · 6.75 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
(function () {
CKEDITOR.plugins.add('btbutton', {
lang: 'en,ru,pt-br,uk',
requires: 'widget,dialog',
icons: 'btbutton',
init: function (editor) {
// Allow any attributes.
editor.config.extraAllowedContent = '*(*);*{*}';
var lang = editor.lang.btbutton;
CKEDITOR.dialog.add('btbutton', this.path + 'dialogs/btbutton.js');
// Add widget
editor.ui.addButton('btbutton', {
label: lang.buttonTitle,
command: 'btbutton',
icon: this.path + 'icons/btbutton.png'
});
editor.widgets.add('btbutton', {
dialog: 'btbutton',
init: function () {
var $el = jQuery(this.element.$);
if ($el.hasClass("btn-link")) {
this.data.btntype = "btn-link";
} else if ($el.hasClass("btn-default")) {
this.data.btntype = "btn-default";
} else if ($el.hasClass("btn-primary")) {
this.data.btntype = "btn-primary";
} else if ($el.hasClass("btn-info")) {
this.data.btntype = "btn-info";
} else if ($el.hasClass("btn-success")) {
this.data.btntype = "btn-success";
} else if ($el.hasClass("btn-warning")) {
this.data.btntype = "btn-warning";
} else if ($el.hasClass("btn-danger")) {
this.data.btntype = "btn-danger";
}
if ($el.hasClass("btn-xs")) {
this.data.btnsize = "btn-xs";
} else if ($el.hasClass("btn-sm")) {
this.data.btnsize = "btn-sm";
} else if ($el.hasClass("btn-lg")) {
this.data.btnsize = "btn-lg";
}
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');
}
},
template: '<a class="btn">' + '<span class="text"></span>' + '</a>',
data: function () {
var $el = jQuery(this.element.$);
if (this.data.btntype) {
$el.removeClass('btn-link btn-default btn-primary btn-info btn-success btn-warning btn-danger').addClass(this.data.btntype);
}
$el.removeClass('btn-xs btn-sm btn-lg');
if (this.data.btnsize) {
$el.addClass(this.data.btnsize);
}
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');
}
}
},
requiredContent: 'a(btn)',
upcast: function (element) {
return element.name == 'a' && element.hasClass('btn');
}
});
}
}
);
})();