kendo.mobile.buttongroup.js
8.53 KB
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
/**
* Kendo UI v2016.1.112 (http://www.telerik.com/kendo-ui)
* Copyright 2016 Telerik AD. All rights reserved.
*
* Kendo UI commercial licenses may be obtained at
* http://www.telerik.com/purchase/license-agreement/kendo-ui-complete
* If you do not own a commercial license, this file shall be governed by the trial license terms.
*/
(function (f, define) {
define('kendo.mobile.buttongroup', ['kendo.core'], f);
}(function () {
var __meta__ = {
id: 'mobile.buttongroup',
name: 'ButtonGroup',
category: 'mobile',
description: 'The Kendo mobile ButtonGroup widget is a linear set of grouped buttons.',
depends: ['core']
};
(function ($, undefined) {
var kendo = window.kendo, ui = kendo.mobile.ui, Widget = ui.Widget, ACTIVE = 'km-state-active', DISABLE = 'km-state-disabled', SELECT = 'select', SELECTOR = 'li:not(.' + ACTIVE + ')';
function createBadge(value) {
return $('<span class="km-badge">' + value + '</span>');
}
var ButtonGroup = Widget.extend({
init: function (element, options) {
var that = this;
Widget.fn.init.call(that, element, options);
that.element.addClass('km-buttongroup').find('li').each(that._button);
that.element.on(that.options.selectOn, SELECTOR, '_select');
that._enable = true;
that.select(that.options.index);
if (!that.options.enable) {
that._enable = false;
that.wrapper.addClass(DISABLE);
}
},
events: [SELECT],
options: {
name: 'ButtonGroup',
selectOn: 'down',
index: -1,
enable: true
},
current: function () {
return this.element.find('.' + ACTIVE);
},
select: function (li) {
var that = this, index = -1;
if (li === undefined || li === -1 || !that._enable || $(li).is('.' + DISABLE)) {
return;
}
that.current().removeClass(ACTIVE);
if (typeof li === 'number') {
index = li;
li = $(that.element[0].children[li]);
} else if (li.nodeType) {
li = $(li);
index = li.index();
}
li.addClass(ACTIVE);
that.selectedIndex = index;
},
badge: function (item, value) {
var buttongroup = this.element, badge;
if (!isNaN(item)) {
item = buttongroup.children().get(item);
}
item = buttongroup.find(item);
badge = $(item.children('.km-badge')[0] || createBadge(value).appendTo(item));
if (value || value === 0) {
badge.html(value);
return this;
}
if (value === false) {
badge.empty().remove();
return this;
}
return badge.html();
},
enable: function (enable) {
var wrapper = this.wrapper;
if (typeof enable == 'undefined') {
enable = true;
}
if (enable) {
wrapper.removeClass(DISABLE);
} else {
wrapper.addClass(DISABLE);
}
this._enable = this.options.enable = enable;
},
_button: function () {
var button = $(this).addClass('km-button'), icon = kendo.attrValue(button, 'icon'), badge = kendo.attrValue(button, 'badge'), span = button.children('span'), image = button.find('img').addClass('km-image');
if (!span[0]) {
span = button.wrapInner('<span/>').children('span');
}
span.addClass('km-text');
if (!image[0] && icon) {
button.prepend($('<span class="km-icon km-' + icon + '"/>'));
}
if (badge || badge === 0) {
createBadge(badge).appendTo(button);
}
},
_select: function (e) {
if (e.which > 1 || e.isDefaultPrevented() || !this._enable) {
return;
}
this.select(e.currentTarget);
this.trigger(SELECT, { index: this.selectedIndex });
}
});
ui.plugin(ButtonGroup);
}(window.kendo.jQuery));
return window.kendo;
}, typeof define == 'function' && define.amd ? define : function (a1, a2, a3) {
(a3 || a2)();
}));