103 lines
No EOL
4.4 KiB
HTML
103 lines
No EOL
4.4 KiB
HTML
<html><head><title>CheckItem.js</title><link rel="stylesheet" type="text/css" href="../resources/style.css" media="screen"/></head><body><h1>CheckItem.js</h1><pre class="highlighted"><code><i>/**
|
|
* @class Ext.menu.CheckItem
|
|
* @extends Ext.menu.Item
|
|
* Adds a menu item that contains a checkbox by <b>default</b>, but can also be part of a radio group.
|
|
* @constructor
|
|
* Creates a <b>new</b> CheckItem
|
|
* @param {Object} config Configuration options
|
|
*/</i>
|
|
Ext.menu.CheckItem = <b>function</b>(config){
|
|
Ext.menu.CheckItem.superclass.constructor.call(<b>this</b>, config);
|
|
<b>this</b>.addEvents({
|
|
<i>/**
|
|
* @event beforecheckchange
|
|
* Fires before the checked value is set, providing an opportunity to cancel <b>if</b> needed
|
|
* @param {Ext.menu.CheckItem} <b>this</b>
|
|
* @param {Boolean} checked The <b>new</b> checked value that will be set
|
|
*/</i>
|
|
"beforecheckchange" : true,
|
|
<i>/**
|
|
* @event checkchange
|
|
* Fires after the checked value has been set
|
|
* @param {Ext.menu.CheckItem} <b>this</b>
|
|
* @param {Boolean} checked The checked value that was set
|
|
*/</i>
|
|
"checkchange" : true
|
|
});
|
|
<b>if</b>(this.checkHandler){
|
|
<b>this</b>.on('checkchange', <b>this</b>.checkHandler, <b>this</b>.scope);
|
|
}
|
|
};
|
|
Ext.extend(Ext.menu.CheckItem, Ext.menu.Item, {
|
|
<i>/**
|
|
* @cfg {String} group
|
|
* All check items <b>with</b> the same group name will automatically be grouped into a single-select
|
|
* radio button group (defaults to '')
|
|
*/</i>
|
|
<i>// holder</i>
|
|
<i>/***
|
|
* @cfg {String} itemCls The <b>default</b> CSS class to use <b>for</b> check items (defaults to "x-menu-item x-menu-check-item")
|
|
*/</i>
|
|
itemCls : "x-menu-item x-menu-check-item",
|
|
<i>/**
|
|
* @cfg {String} groupClass The <b>default</b> CSS class to use <b>for</b> radio group check items (defaults to "x-menu-group-item")
|
|
*/</i>
|
|
groupClass : "x-menu-group-item",
|
|
|
|
<i>/**
|
|
* @cfg {Boolean} checked True to initialize <b>this</b> checkbox as checked (defaults to false). Note that
|
|
* <b>if</b> this checkbox is part of a radio group (group = true) only the last item <b>in</b> the group that is
|
|
* initialized <b>with</b> checked = true will be rendered as checked.
|
|
*/</i>
|
|
checked: false,
|
|
|
|
<i>// private</i>
|
|
ctype: "Ext.menu.CheckItem",
|
|
|
|
<i>// private</i>
|
|
onRender : <b>function</b>(c){
|
|
Ext.menu.CheckItem.superclass.onRender.apply(<b>this</b>, arguments);
|
|
<b>if</b>(this.group){
|
|
<b>this</b>.el.addClass(<b>this</b>.groupClass);
|
|
}
|
|
Ext.menu.MenuMgr.registerCheckable(<b>this</b>);
|
|
<b>if</b>(this.checked){
|
|
<b>this</b>.checked = false;
|
|
<b>this</b>.setChecked(true, true);
|
|
}
|
|
},
|
|
|
|
<i>// private</i>
|
|
destroy : <b>function</b>(){
|
|
<b>if</b>(this.rendered){
|
|
Ext.menu.MenuMgr.unregisterCheckable(<b>this</b>);
|
|
}
|
|
Ext.menu.CheckItem.superclass.destroy.apply(<b>this</b>, arguments);
|
|
},
|
|
|
|
<i>/**
|
|
* Set the checked state of <b>this</b> item
|
|
* @param {Boolean} checked The <b>new</b> checked value
|
|
* @param {Boolean} suppressEvent (optional) True to prevent the checkchange event from firing (defaults to false)
|
|
*/</i>
|
|
setChecked : <b>function</b>(state, suppressEvent){
|
|
<b>if</b>(this.checked != state && <b>this</b>.fireEvent("beforecheckchange", <b>this</b>, state) !== false){
|
|
<b>if</b>(this.container){
|
|
<b>this</b>.container[state ? "addClass" : "removeClass"]("x-menu-item-checked");
|
|
}
|
|
<b>this</b>.checked = state;
|
|
<b>if</b>(suppressEvent !== true){
|
|
<b>this</b>.fireEvent("checkchange", <b>this</b>, state);
|
|
}
|
|
}
|
|
},
|
|
|
|
<i>// private</i>
|
|
handleClick : <b>function</b>(e){
|
|
<b>if</b>(!<b>this</b>.disabled && !(<b>this</b>.checked && <b>this</b>.group)){<i>// disable unselect on radio item</i>
|
|
<b>this</b>.setChecked(!<b>this</b>.checked);
|
|
}
|
|
Ext.menu.CheckItem.superclass.handleClick.apply(<b>this</b>, arguments);
|
|
}
|
|
});</code></pre><hr><div style="font-size:10px;text-align:center;color:gray;">Ext - Copyright © 2006-2007 Ext JS, LLC<br />All rights reserved.</div>
|
|
</body></html> |