X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/25ef3491bd9ae007ff1fc2b0d7943e6eaaccf775..0494b8d9b9bb03ab6c22b34dae81261e3cd7e3e6:/src/widgets/menu/CheckItem.js diff --git a/src/widgets/menu/CheckItem.js b/src/widgets/menu/CheckItem.js index 4f994bb9..84dd2f99 100644 --- a/src/widgets/menu/CheckItem.js +++ b/src/widgets/menu/CheckItem.js @@ -1,8 +1,8 @@ /*! - * Ext JS Library 3.0.3 - * Copyright(c) 2006-2009 Ext JS, LLC - * licensing@extjs.com - * http://www.extjs.com/license + * Ext JS Library 3.3.1 + * Copyright(c) 2006-2010 Sencha Inc. + * licensing@sencha.com + * http://www.sencha.com/license */ /** * @class Ext.menu.CheckItem @@ -13,37 +13,7 @@ * @param {Object} config Configuration options * @xtype menucheckitem */ -Ext.menu.CheckItem = function(config){ - Ext.menu.CheckItem.superclass.constructor.call(this, config); - this.addEvents( - /** - * @event beforecheckchange - * Fires before the checked value is set, providing an opportunity to cancel if needed - * @param {Ext.menu.CheckItem} this - * @param {Boolean} checked The new checked value that will be set - */ - "beforecheckchange" , - /** - * @event checkchange - * Fires after the checked value has been set - * @param {Ext.menu.CheckItem} this - * @param {Boolean} checked The checked value that was set - */ - "checkchange" - ); - /** - * A function that handles the checkchange event. The function is undefined by default, but if an implementation - * is provided, it will be called automatically when the checkchange event fires. - * @param {Ext.menu.CheckItem} this - * @param {Boolean} checked The checked value that was set - * @method checkHandler - */ - if(this.checkHandler){ - this.on('checkchange', this.checkHandler, this.scope); - } - Ext.menu.MenuMgr.registerCheckable(this); -}; -Ext.extend(Ext.menu.CheckItem, Ext.menu.Item, { +Ext.menu.CheckItem = Ext.extend(Ext.menu.Item, { /** * @cfg {String} group * All check items with the same group name will automatically be grouped into a single-select @@ -60,13 +30,44 @@ Ext.extend(Ext.menu.CheckItem, Ext.menu.Item, { /** * @cfg {Boolean} checked True to initialize this checkbox as checked (defaults to false). Note that - * if this checkbox is part of a radio group (group = true) only the last item in the group that is + * if this checkbox is part of a radio group (group = true) only the first item in the group that is * initialized with checked = true will be rendered as checked. */ checked: false, // private ctype: "Ext.menu.CheckItem", + + initComponent : function(){ + Ext.menu.CheckItem.superclass.initComponent.call(this); + this.addEvents( + /** + * @event beforecheckchange + * Fires before the checked value is set, providing an opportunity to cancel if needed + * @param {Ext.menu.CheckItem} this + * @param {Boolean} checked The new checked value that will be set + */ + "beforecheckchange" , + /** + * @event checkchange + * Fires after the checked value has been set + * @param {Ext.menu.CheckItem} this + * @param {Boolean} checked The checked value that was set + */ + "checkchange" + ); + /** + * A function that handles the checkchange event. The function is undefined by default, but if an implementation + * is provided, it will be called automatically when the checkchange event fires. + * @param {Ext.menu.CheckItem} this + * @param {Boolean} checked The checked value that was set + * @method checkHandler + */ + if(this.checkHandler){ + this.on('checkchange', this.checkHandler, this.scope); + } + Ext.menu.MenuMgr.registerCheckable(this); + }, // private onRender : function(c){ @@ -92,12 +93,14 @@ Ext.extend(Ext.menu.CheckItem, Ext.menu.Item, { * @param {Boolean} suppressEvent (optional) True to prevent the checkchange event from firing (defaults to false) */ setChecked : function(state, suppressEvent){ - if(this.checked != state && this.fireEvent("beforecheckchange", this, state) !== false){ + var suppress = suppressEvent === true; + if(this.checked != state && (suppress || this.fireEvent("beforecheckchange", this, state) !== false)){ + Ext.menu.MenuMgr.onCheckChange(this, state); if(this.container){ this.container[state ? "addClass" : "removeClass"]("x-menu-item-checked"); } this.checked = state; - if(suppressEvent !== true){ + if(!suppress){ this.fireEvent("checkchange", this, state); } }