4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-menu-CheckItem'>/**
19 </span> * A menu item that contains a togglable checkbox by default, but that can also be a part of a radio group.
22 * Ext.create('Ext.menu.Menu', {
25 * floating: false, // usually you want this set to True (default)
26 * renderTo: Ext.getBody(), // usually rendered by it's containing component
28 * xtype: 'menucheckitem',
31 * xtype: 'menucheckitem',
32 * text: 'select specific',
37 * text: 'regular item'
41 Ext.define('Ext.menu.CheckItem', {
42 extend: 'Ext.menu.Item',
43 alias: 'widget.menucheckitem',
45 <span id='Ext-menu-CheckItem-cfg-checkedCls'> /**
46 </span> * @cfg {String} checkedCls
47 * The CSS class used by {@link #cls} to show the checked state.
48 * Defaults to `Ext.baseCSSPrefix + 'menu-item-checked'`.
50 checkedCls: Ext.baseCSSPrefix + 'menu-item-checked',
51 <span id='Ext-menu-CheckItem-cfg-uncheckedCls'> /**
52 </span> * @cfg {String} uncheckedCls
53 * The CSS class used by {@link #cls} to show the unchecked state.
54 * Defaults to `Ext.baseCSSPrefix + 'menu-item-unchecked'`.
56 uncheckedCls: Ext.baseCSSPrefix + 'menu-item-unchecked',
57 <span id='Ext-menu-CheckItem-cfg-groupCls'> /**
58 </span> * @cfg {String} groupCls
59 * The CSS class applied to this item's icon image to denote being a part of a radio group.
60 * Defaults to `Ext.baseCSSClass + 'menu-group-icon'`.
61 * Any specified {@link #iconCls} overrides this.
63 groupCls: Ext.baseCSSPrefix + 'menu-group-icon',
65 <span id='Ext-menu-CheckItem-cfg-hideOnClick'> /**
66 </span> * @cfg {Boolean} hideOnClick
67 * Whether to not to hide the owning menu when this item is clicked.
68 * Defaults to `false` for checkbox items, and to `true` for radio group items.
72 afterRender: function() {
75 me.checked = !me.checked;
76 me.setChecked(!me.checked, true);
79 initComponent: function() {
82 <span id='Ext-menu-CheckItem-event-beforecheckchange'> /**
83 </span> * @event beforecheckchange
84 * Fires before a change event. Return false to cancel.
85 * @param {Ext.menu.CheckItem} this
86 * @param {Boolean} checked
90 <span id='Ext-menu-CheckItem-event-checkchange'> /**
91 </span> * @event checkchange
92 * Fires after a change event.
93 * @param {Ext.menu.CheckItem} this
94 * @param {Boolean} checked
99 me.callParent(arguments);
101 Ext.menu.Manager.registerCheckable(me);
105 me.iconCls = me.groupCls;
107 if (me.initialConfig.hideOnClick !== false) {
108 me.hideOnClick = true;
113 <span id='Ext-menu-CheckItem-method-disableCheckChange'> /**
114 </span> * Disables just the checkbox functionality of this menu Item. If this menu item has a submenu, that submenu
115 * will still be accessible
117 disableCheckChange: function() {
121 me.iconEl.addCls(me.disabledCls);
123 me.checkChangeDisabled = true;
126 <span id='Ext-menu-CheckItem-method-enableCheckChange'> /**
127 </span> * Reenables the checkbox functionality of this menu item after having been disabled by {@link #disableCheckChange}
129 enableCheckChange: function() {
132 me.iconEl.removeCls(me.disabledCls);
133 me.checkChangeDisabled = false;
136 onClick: function(e) {
138 if(!me.disabled && !me.checkChangeDisabled && !(me.checked && me.group)) {
139 me.setChecked(!me.checked);
141 this.callParent([e]);
144 onDestroy: function() {
145 Ext.menu.Manager.unregisterCheckable(this);
146 this.callParent(arguments);
149 <span id='Ext-menu-CheckItem-method-setChecked'> /**
150 </span> * Sets the checked state of the item
151 * @param {Boolean} checked True to check, false to uncheck
152 * @param {Boolean} suppressEvents (optional) True to prevent firing the checkchange events. Defaults to `false`.
154 setChecked: function(checked, suppressEvents) {
156 if (me.checked !== checked && (suppressEvents || me.fireEvent('beforecheckchange', me, checked) !== false)) {
158 me.el[checked ? 'addCls' : 'removeCls'](me.checkedCls)[!checked ? 'addCls' : 'removeCls'](me.uncheckedCls);
160 me.checked = checked;
161 Ext.menu.Manager.onCheckChange(me, checked);
162 if (!suppressEvents) {
163 Ext.callback(me.checkHandler, me.scope, [me, checked]);
164 me.fireEvent('checkchange', me, checked);