CheckItem.html
7.34 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-menu-CheckItem'>/**
</span> * A menu item that contains a togglable checkbox by default, but that can also be a part of a radio group.
*
* @example
* Ext.create('Ext.menu.Menu', {
* width: 100,
* height: 110,
* floating: false, // usually you want this set to True (default)
* renderTo: Ext.getBody(), // usually rendered by it's containing component
* items: [{
* xtype: 'menucheckitem',
* text: 'select all'
* },{
* xtype: 'menucheckitem',
* text: 'select specific'
* },{
* iconCls: 'add16',
* text: 'icon item'
* },{
* text: 'regular item'
* }]
* });
*/
Ext.define('Ext.menu.CheckItem', {
extend: 'Ext.menu.Item',
alias: 'widget.menucheckitem',
<span id='Ext-menu-CheckItem-cfg-checked'> /**
</span> * @cfg {Boolean} [checked=false]
* True to render the menuitem initially checked.
*/
<span id='Ext-menu-CheckItem-cfg-checkHandler'> /**
</span> * @cfg {Function} checkHandler
* Alternative for the {@link #checkchange} event. Gets called with the same parameters.
*/
<span id='Ext-menu-CheckItem-cfg-scope'> /**
</span> * @cfg {Object} scope
* Scope for the {@link #checkHandler} callback.
*/
<span id='Ext-menu-CheckItem-cfg-group'> /**
</span> * @cfg {String} group
* Name of a radio group that the item belongs.
*
* Specifying this option will turn check item into a radio item.
*
* Note that the group name must be globally unique.
*/
<span id='Ext-menu-CheckItem-cfg-checkedCls'> /**
</span> * @cfg {String} checkedCls
* The CSS class used by {@link #cls} to show the checked state.
* Defaults to `Ext.baseCSSPrefix + 'menu-item-checked'`.
*/
checkedCls: Ext.baseCSSPrefix + 'menu-item-checked',
<span id='Ext-menu-CheckItem-cfg-uncheckedCls'> /**
</span> * @cfg {String} uncheckedCls
* The CSS class used by {@link #cls} to show the unchecked state.
* Defaults to `Ext.baseCSSPrefix + 'menu-item-unchecked'`.
*/
uncheckedCls: Ext.baseCSSPrefix + 'menu-item-unchecked',
<span id='Ext-menu-CheckItem-cfg-groupCls'> /**
</span> * @cfg {String} groupCls
* The CSS class applied to this item's icon image to denote being a part of a radio group.
* Defaults to `Ext.baseCSSClass + 'menu-group-icon'`.
* Any specified {@link #iconCls} overrides this.
*/
groupCls: Ext.baseCSSPrefix + 'menu-group-icon',
<span id='Ext-menu-CheckItem-cfg-hideOnClick'> /**
</span> * @cfg {Boolean} [hideOnClick=false]
* Whether to not to hide the owning menu when this item is clicked.
* Defaults to `false` for checkbox items, and to `true` for radio group items.
*/
hideOnClick: false,
<span id='Ext-menu-CheckItem-cfg-checkChangeDisabled'> /**
</span> * @cfg {Boolean} [checkChangeDisabled=false]
* True to prevent the checked item from being toggled. Any submenu will still be accessible.
*/
checkChangeDisabled: false,
afterRender: function() {
var me = this;
me.callParent();
me.checked = !me.checked;
me.setChecked(!me.checked, true);
if (me.checkChangeDisabled) {
me.disableCheckChange();
}
},
initComponent: function() {
var me = this;
me.addEvents(
<span id='Ext-menu-CheckItem-event-beforecheckchange'> /**
</span> * @event beforecheckchange
* Fires before a change event. Return false to cancel.
* @param {Ext.menu.CheckItem} this
* @param {Boolean} checked
*/
'beforecheckchange',
<span id='Ext-menu-CheckItem-event-checkchange'> /**
</span> * @event checkchange
* Fires after a change event.
* @param {Ext.menu.CheckItem} this
* @param {Boolean} checked
*/
'checkchange'
);
me.callParent(arguments);
Ext.menu.Manager.registerCheckable(me);
if (me.group) {
if (!me.iconCls) {
me.iconCls = me.groupCls;
}
if (me.initialConfig.hideOnClick !== false) {
me.hideOnClick = true;
}
}
},
<span id='Ext-menu-CheckItem-method-disableCheckChange'> /**
</span> * Disables just the checkbox functionality of this menu Item. If this menu item has a submenu, that submenu
* will still be accessible
*/
disableCheckChange: function() {
var me = this,
iconEl = me.iconEl;
if (iconEl) {
iconEl.addCls(me.disabledCls);
}
// In some cases the checkbox will disappear until repainted
// Happens in everything except IE9 strict, see: EXTJSIV-6412
if (!(Ext.isIE9 && Ext.isStrict) && me.rendered) {
me.el.repaint();
}
me.checkChangeDisabled = true;
},
<span id='Ext-menu-CheckItem-method-enableCheckChange'> /**
</span> * Reenables the checkbox functionality of this menu item after having been disabled by {@link #disableCheckChange}
*/
enableCheckChange: function() {
var me = this,
iconEl = me.iconEl;
if (iconEl) {
iconEl.removeCls(me.disabledCls);
}
me.checkChangeDisabled = false;
},
onClick: function(e) {
var me = this;
if(!me.disabled && !me.checkChangeDisabled && !(me.checked && me.group)) {
me.setChecked(!me.checked);
}
this.callParent([e]);
},
onDestroy: function() {
Ext.menu.Manager.unregisterCheckable(this);
this.callParent(arguments);
},
<span id='Ext-menu-CheckItem-method-setChecked'> /**
</span> * Sets the checked state of the item
* @param {Boolean} checked True to check, false to uncheck
* @param {Boolean} [suppressEvents=false] True to prevent firing the checkchange events.
*/
setChecked: function(checked, suppressEvents) {
var me = this;
if (me.checked !== checked && (suppressEvents || me.fireEvent('beforecheckchange', me, checked) !== false)) {
if (me.el) {
me.el[checked ? 'addCls' : 'removeCls'](me.checkedCls)[!checked ? 'addCls' : 'removeCls'](me.uncheckedCls);
}
me.checked = checked;
Ext.menu.Manager.onCheckChange(me, checked);
if (!suppressEvents) {
Ext.callback(me.checkHandler, me.scope, [me, checked]);
me.fireEvent('checkchange', me, checked);
}
}
}
});
</pre>
</body>
</html>