-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathkendo.html.chip.js
124 lines (102 loc) · 4.23 KB
/
kendo.html.chip.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
import "./kendo.html.base.js";
import "./kendo.icons.js";
export const __meta__ = {
id: "html.chip",
name: "Html.Chip",
category: "web",
description: "HTML rendering utility for Kendo UI for jQuery.",
depends: [ "html.base", "icons" ],
features: []
};
(function($, undefined) {
var kendo = window.kendo,
HTMLBase = kendo.html.HTMLBase;
var renderChip = function(element, options) {
if (!element || $.isPlainObject(element)) {
options = element;
element = $("<span></span>");
}
return (new HTMLChip(element, options)).html();
};
var HTMLChip = HTMLBase.extend({
init: function(element, options) {
var that = this;
HTMLBase.fn.init.call(that, element, options);
that._wrapper();
},
options: {
name: "HTMLChip",
size: "medium",
rounded: "medium",
fillMode: "solid",
themeColor: "base",
attr: {},
icon: "",
iconClass: "",
iconAttr: {},
removable: false,
removableAttr: {},
removeIcon: "x-circle",
removeIconClass: "",
content: "",
text: "",
actions: [],
stylingOptions: [ "size", "rounded", "fillMode", "themeColor" ]
},
_wrapper: function() {
var that = this,
options = that.options;
options.text = options.text || options.label;
that.wrapper = that.element.wrap("<div class='k-chip'></div>").parent().attr(options.attr);
that._addClasses();
if (options.icon) {
that.wrapper.prepend($(kendo.ui.icon({ icon: options.icon, size: "small", iconClass: `k-chip-icon${options.iconClass ? ` ${options.iconClass}` : '' }` })).attr(options.iconAttr));
} else if (options.iconClass) {
that.wrapper.prepend($("<span class='" + options.iconClass + "'></span>").attr(options.iconAttr));
} else if (options.avatarClass) {
that.wrapper.prepend($("<span class='k-chip-avatar k-avatar k-avatar-md k-avatar-solid k-avatar-solid-primary k-rounded-full " + options.avatarClass + "'></span>").attr(options.iconAttr));
}
that.element.addClass("k-chip-content");
if (options.text) {
that.element.html('<span class="k-chip-label">' + options.text + '</span>');
}
if (options.visible === false) {
that.wrapper.addClass("k-hidden");
}
if (options.selected === true) {
that.wrapper.addClass("k-selected");
}
if (options.enabled === false) {
that.wrapper.addClass("k-disabled");
}
if ((options.actions && options.actions.length > 0) || options.removable) {
that._actions();
}
},
_actions: function() {
var that = this,
options = that.options;
that.actionsWrapper = $("<span class='k-chip-actions'></span>");
that.actionsWrapper.appendTo(that.wrapper);
if (options.actions && options.actions.length > 0) {
for (var i = 0; i < options.actions.length; i++) {
var action = options.actions[i];
that.actionsWrapper.append($(`<span class='k-chip-action ${action.iconClass ? action.iconClass : ''}'>${kendo.ui.icon({ icon: action.icon, size: "small" })}</span>`).attr(action.attr ? action.attr : {}));
}
}
if (options.removable) {
that.actionsWrapper.append($(`<span class='k-chip-action k-chip-remove-action'>${kendo.ui.icon({ icon: options.removeIcon, size: "small" })}</span>`).attr(options.removableAttr));
}
}
});
$.extend(kendo.html, {
renderChip: renderChip,
HTMLChip: HTMLChip
});
kendo.cssProperties.registerPrefix("HTMLChip", "k-chip-");
kendo.cssProperties.registerValues("HTMLChip", [{
prop: "rounded",
values: kendo.cssProperties.roundedValues.concat([['full', 'full']])
}]);
})(window.kendo.jQuery);
export default kendo;