-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathkendo.togglebutton.js
113 lines (91 loc) · 3.32 KB
/
kendo.togglebutton.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
import "./kendo.core.js";
import "./kendo.button.js";
export const __meta__ = {
id: "togglebutton",
name: "ToggleButton",
category: "web",
description: "The ToggleButton widget displays styled buttons with selected state.",
depends: ["core", "button"]
};
(function($, undefined) {
var kendo = window.kendo,
Button = kendo.ui.Button,
CLICK = "click",
TOGGLE = "toggle",
NS = ".kendoToggleButton",
ARIA_PRESSED = "aria-pressed",
SELECTED = "k-selected",
DATA_GROUP = "data-group",
ID = "id";
var ToggleButton = Button.extend({
init: function(element, options) {
var that = this;
Button.fn.init.call(that, element, options);
element = that.wrapper = that.element;
options = that.options;
that._selected = options.selected === true ? true : false;
that.toggle(that._selected);
if (options.group) {
element.attr(DATA_GROUP, options.group);
}
kendo.notify(that);
},
destroy: function() {
var that = this;
that.wrapper.off(NS);
Button.fn.destroy.call(that);
},
events: [
CLICK,
TOGGLE
],
options: {
name: "ToggleButton",
group: undefined,
selected: false
},
toggle: function(toggle) {
if (toggle === undefined) {
toggle = !this._selected;
}
this._selected = toggle;
if (toggle === true) {
this.element.attr(ARIA_PRESSED, true);
this.element.addClass(SELECTED);
} else if (toggle === false) {
this.element.attr(ARIA_PRESSED, false);
this.element.removeClass(SELECTED);
}
},
_click: function(e) {
if (this.options.enable) {
if (this.trigger(CLICK, {
event: e,
id: this.element.attr(ID),
target: this.element
})) {
e.preventDefault();
} else {
this.toggle();
this.trigger(TOGGLE, {
event: e,
checked: this._selected,
group: this.options.group,
id: this.element.attr(ID),
target: this.element
});
}
}
}
});
kendo.cssProperties.registerPrefix("ToggleButton", "k-button-");
kendo.cssProperties.registerValues("ToggleButton", [{
prop: "fillMode",
values: kendo.cssProperties.fillModeValues.concat(["link"])
}, {
prop: "rounded",
values: kendo.cssProperties.roundedValues.concat([['full', 'full']])
}]);
kendo.ui.plugin(ToggleButton);
})(window.kendo.jQuery);
export default kendo;