-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathkendo.html.input.js
154 lines (129 loc) · 4.52 KB
/
kendo.html.input.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
import "./kendo.html.base.js";
export const __meta__ = {
id: "html.input",
name: "Html.Input",
category: "web",
description: "HTML rendering utility for Kendo UI for jQuery.",
depends: [ "html.base" ],
features: []
};
(function($, undefined) {
var kendo = window.kendo,
HTMLBase = kendo.html.HTMLBase;
var renderCheckBox = function(element, options) {
if (arguments[0] === undefined || $.isPlainObject(arguments[0])) {
options = element;
element = $("<input />");
}
return (new HTMLCheckBox(element, options)).html();
};
var renderRadioButton = function(element, options) {
if (arguments[0] === undefined || $.isPlainObject(arguments[0])) {
options = element;
element = $("<input />");
}
return (new HTMLRadioButton(element, options)).html();
};
var HTMLInput = HTMLBase.extend({
init: function(element, options) {
var that = this;
HTMLBase.fn.init.call(that, element, options);
that._wrapper();
that._addClasses();
},
options: {
label: null,
labelPosition: "after",
labelId: null,
encoded: true
},
_wrapper: function() {
var that = this,
element = that.element[0],
options = that.options,
elementId = element.id;
that.wrapper = that.element
.addClass(options.inputClass)
.prop("type", options.type);
if (!elementId && !!options.label) {
element.id = elementId = kendo.guid();
}
if (!!options.label) {
that.labelEl = $("<label for='" + elementId + "' class='" + options.labelClass + "'>");
if (options.encoded) {
that.labelEl.text(options.label);
} else {
that.labelEl.html(options.label);
}
if (options.labelId) {
that.labelEl.attr("id", options.labelId);
}
if (options.optional) {
that.labelEl.append("<span class='" + options.optionalClass + "'>" + options.optionalText + "</span>");
}
that.element[options.labelPosition](that.labelEl);
}
},
html: function() {
var that = this,
after = that.options.labelPosition === "after",
wrapperHtml = HTMLBase.fn.html.call(that);
if (!that.labelEl) {
return wrapperHtml;
}
if (after) {
return wrapperHtml + that.labelEl[0].outerHTML;
}
return that.labelEl[0].outerHTML + wrapperHtml;
}
});
var HTMLCheckBox = HTMLInput.extend({
init: function(element, options) {
var that = this;
HTMLInput.fn.init.call(that, element, options);
that._addClasses();
},
options: {
name: "HTMLCheckBox",
inputClass: "k-checkbox",
labelClass: "k-checkbox-label",
optionalClass: "k-label-optional",
optionalText: "(Optional)",
type: "checkbox",
rounded: "medium",
size: "medium",
stylingOptions: [ "size", "rounded" ]
}
});
var HTMLRadioButton = HTMLInput.extend({
init: function(element, options) {
var that = this;
HTMLInput.fn.init.call(that, element, options);
that._addClasses();
},
options: {
name: "HTMLRadioButton",
inputClass: "k-radio",
labelClass: "k-radio-label",
optionalClass: "k-label-optional",
optionalText: "(Optional)",
type: "radio",
size: "medium",
stylingOptions: [ "size"]
}
});
$.extend(kendo.html, {
renderCheckBox: renderCheckBox,
renderRadioButton: renderRadioButton,
HTMLInput: HTMLInput,
HTMLCheckBox: HTMLCheckBox,
HTMLRadioButton: HTMLRadioButton
});
kendo.cssProperties.registerPrefix("HTMLCheckBox", "k-checkbox-");
kendo.cssProperties.registerValues("HTMLCheckBox", [{
prop: "rounded",
values: kendo.cssProperties.roundedValues.concat([['full', 'full']])
}]);
kendo.cssProperties.registerPrefix("HTMLRadioButton", "k-radio-");
})(window.kendo.jQuery);
export default kendo;