X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/c930e9176a5a85509c5b0230e2bff5c22a591432..530ef4b6c5b943cfa68b779d11cf7de29aa878bf:/pkgs/pkg-buttons-debug.js diff --git a/pkgs/pkg-buttons-debug.js b/pkgs/pkg-buttons-debug.js index 86e62405..d376d040 100644 --- a/pkgs/pkg-buttons-debug.js +++ b/pkgs/pkg-buttons-debug.js @@ -1,6 +1,6 @@ /*! - * Ext JS Library 3.0.0 - * Copyright(c) 2006-2009 Ext JS, LLC + * Ext JS Library 3.2.1 + * Copyright(c) 2006-2010 Ext JS, Inc. * licensing@extjs.com * http://www.extjs.com/license */ @@ -16,7 +16,6 @@ *
b
: Buttone
: EventObjectWhen a custom {@link #template} is used, you must ensure that this selector results in the selection of * a focussable element.
- *Defaults to "button:first-child".
+ *Defaults to 'button:first-child'.
*/ buttonSelector : 'button:first-child', @@ -141,7 +135,13 @@ Ext.Button = Ext.extend(Ext.BoxComponent, { * *Defaults to 'small'.
*/ - scale: 'small', + scale : 'small', + + /** + * @cfg {Object} scope The scope (this reference) in which the + *{@link #handler}
and {@link #toggleHandler}
is
+ * executed. Defaults to this Button.
+ */
/**
* @cfg {String} iconAlign
@@ -185,6 +185,13 @@ Ext.Button = Ext.extend(Ext.BoxComponent, {
* @type Menu
* The {@link Ext.menu.Menu Menu} object associated with this Button when configured with the {@link #menu} config option.
*/
+ /**
+ * @cfg {Boolean} autoWidth
+ * By default, if a width is not specified the button will attempt to stretch horizontally to fit its content.
+ * If the button is being managed by a width sizing layout (hbox, fit, anchor), set this to false to prevent
+ * the button from doing this automatic sizing.
+ * Defaults to undefined.
+ */
initComponent : function(){
Ext.Button.superclass.initComponent.call(this);
@@ -258,28 +265,33 @@ Ext.Button = Ext.extend(Ext.BoxComponent, {
},
/**
- * This method returns an object which provides substitution parameters for the {@link #template Template} used + *
This method returns an Array which provides substitution parameters for the {@link #template Template} used * to create this Button's DOM structure.
*Instances or subclasses which use a different Template to create a different DOM structure may need to provide their * own implementation of this method.
*The default implementation which provides data for the default {@link #template} returns an Array containing the * following items:
'x-btn-arrow'
or 'x-btn-arrow-bottom'
or ''
)this
reference) in which the handler function is executed.
+ * Defaults to this Button.
* @return {Ext.Button} this
*/
setHandler : function(handler, scope){
@@ -483,12 +501,28 @@ Ext.Button = Ext.extend(Ext.BoxComponent, {
setText : function(text){
this.text = text;
if(this.el){
- this.el.child('td.x-btn-mc ' + this.buttonSelector).update(text);
+ this.btnEl.update(text || ' ');
+ this.setButtonClass();
}
this.doAutoWidth();
return this;
},
+ /**
+ * Sets the background image (inline style) of the button. This method also changes
+ * the value of the {@link icon} config internally.
+ * @param {String} icon The path to an image to display in the button
+ * @return {Ext.Button} this
+ */
+ setIcon : function(icon){
+ this.icon = icon;
+ if(this.el){
+ this.btnEl.setStyle('background-image', icon ? 'url(' + icon + ')' : '');
+ this.setButtonClass();
+ }
+ return this;
+ },
+
/**
* Gets the text for this Button
* @return {String} The button text
@@ -506,7 +540,9 @@ Ext.Button = Ext.extend(Ext.BoxComponent, {
toggle : function(state, suppressEvent){
state = state === undefined ? !this.pressed : !!state;
if(state != this.pressed){
- this.el[state ? 'addClass' : 'removeClass']('x-btn-pressed');
+ if(this.rendered){
+ this.el[state ? 'addClass' : 'removeClass']('x-btn-pressed');
+ }
this.pressed = state;
if(!suppressEvent){
this.fireEvent('toggle', this, state);
@@ -518,13 +554,6 @@ Ext.Button = Ext.extend(Ext.BoxComponent, {
return this;
},
- /**
- * Focus the button
- */
- focus : function(){
- this.btnEl.focus();
- },
-
// private
onDisable : function(){
this.onDisableChange(true);
@@ -534,7 +563,7 @@ Ext.Button = Ext.extend(Ext.BoxComponent, {
onEnable : function(){
this.onDisableChange(false);
},
-
+
onDisableChange : function(disabled){
if(this.el){
if(!Ext.isIE6 || !this.text){
@@ -553,6 +582,10 @@ Ext.Button = Ext.extend(Ext.BoxComponent, {
if(this.tooltip){
Ext.QuickTips.getQuickTip().cancelShow(this.btnEl);
}
+ if(this.menu.isVisible()){
+ this.menu.hide();
+ }
+ this.menu.ownerCt = this;
this.menu.show(this.el, this.menuAlign);
}
return this;
@@ -562,7 +595,7 @@ Ext.Button = Ext.extend(Ext.BoxComponent, {
* Hide this button's menu (if it has one)
*/
hideMenu : function(){
- if(this.menu){
+ if(this.hasVisibleMenu()){
this.menu.hide();
}
return this;
@@ -573,7 +606,7 @@ Ext.Button = Ext.extend(Ext.BoxComponent, {
* @return {Boolean}
*/
hasVisibleMenu : function(){
- return this.menu && this.menu.isVisible();
+ return this.menu && this.menu.ownerCt == this && this.menu.isVisible();
},
// private
@@ -588,7 +621,7 @@ Ext.Button = Ext.extend(Ext.BoxComponent, {
if(this.enableToggle && (this.allowDepress !== false || !this.pressed)){
this.toggle();
}
- if(this.menu && !this.menu.isVisible() && !this.ignoreNextClick){
+ if(this.menu && !this.hasVisibleMenu() && !this.ignoreNextClick){
this.showMenu();
}
this.fireEvent('click', this, e);
@@ -616,7 +649,7 @@ Ext.Button = Ext.extend(Ext.BoxComponent, {
if(!internal){
this.el.addClass('x-btn-over');
if(!this.monitoringMouseOver){
- Ext.getDoc().on('mouseover', this.monitorMouseOver, this);
+ this.doc.on('mouseover', this.monitorMouseOver, this);
this.monitoringMouseOver = true;
}
this.fireEvent('mouseover', this, e);
@@ -631,7 +664,7 @@ Ext.Button = Ext.extend(Ext.BoxComponent, {
monitorMouseOver : function(e){
if(e.target != this.el.dom && !e.within(this.el)){
if(this.monitoringMouseOver){
- Ext.getDoc().un('mouseover', this.monitorMouseOver, this);
+ this.doc.un('mouseover', this.monitorMouseOver, this);
this.monitoringMouseOver = false;
}
this.onMouseOut(e);
@@ -647,6 +680,15 @@ Ext.Button = Ext.extend(Ext.BoxComponent, {
this.fireEvent('menutriggerout', this, this.menu, e);
}
},
+
+ focus : function() {
+ this.btnEl.focus();
+ },
+
+ blur : function() {
+ this.btnEl.blur();
+ },
+
// private
onFocus : function(e){
if(!this.disabled){
@@ -667,27 +709,33 @@ Ext.Button = Ext.extend(Ext.BoxComponent, {
onMouseDown : function(e){
if(!this.disabled && e.button === 0){
this.getClickEl(e).addClass('x-btn-click');
- Ext.getDoc().on('mouseup', this.onMouseUp, this);
+ this.doc.on('mouseup', this.onMouseUp, this);
}
},
// private
onMouseUp : function(e){
if(e.button === 0){
this.getClickEl(e, true).removeClass('x-btn-click');
- Ext.getDoc().un('mouseup', this.onMouseUp, this);
+ this.doc.un('mouseup', this.onMouseUp, this);
}
},
// private
onMenuShow : function(e){
- this.ignoreNextClick = 0;
- this.el.addClass('x-btn-menu-active');
- this.fireEvent('menushow', this, this.menu);
+ if(this.menu.ownerCt == this){
+ this.menu.ownerCt = this;
+ this.ignoreNextClick = 0;
+ this.el.addClass('x-btn-menu-active');
+ this.fireEvent('menushow', this, this.menu);
+ }
},
// private
onMenuHide : function(e){
- this.el.removeClass('x-btn-menu-active');
- this.ignoreNextClick = this.restoreClick.defer(250, this);
- this.fireEvent('menuhide', this, this.menu);
+ if(this.menu.ownerCt == this){
+ this.el.removeClass('x-btn-menu-active');
+ this.ignoreNextClick = this.restoreClick.defer(250, this);
+ this.fireEvent('menuhide', this, this.menu);
+ delete this.menu.ownerCt;
+ }
},
// private
@@ -695,11 +743,24 @@ Ext.Button = Ext.extend(Ext.BoxComponent, {
this.ignoreNextClick = 0;
}
-
-
/**
* @cfg {String} autoEl @hide
*/
+ /**
+ * @cfg {String/Object} html @hide
+ */
+ /**
+ * @cfg {String} contentEl @hide
+ */
+ /**
+ * @cfg {Mixed} data @hide
+ */
+ /**
+ * @cfg {Mixed} tpl @hide
+ */
+ /**
+ * @cfg {String} tplWriteMode @hide
+ */
});
Ext.reg('button', Ext.Button);
@@ -759,302 +820,312 @@ Ext.ButtonToggleMgr = function(){
return null;
}
};
-}();/**
- * @class Ext.SplitButton
- * @extends Ext.Button
- * A split button that provides a built-in dropdown arrow that can fire an event separately from the default
- * click event of the button. Typically this would be used to display a dropdown menu that provides additional
- * options to the primary button action, but any custom handler can provide the arrowclick implementation. Example usage:
- *
-// display a dropdown menu:
-new Ext.SplitButton({
- renderTo: 'button-ct', // the container id
- text: 'Options',
- handler: optionsHandler, // handle a click on the button itself
- menu: new Ext.menu.Menu({
- items: [
- // these items will render as dropdown menu items when the arrow is clicked:
- {text: 'Item 1', handler: item1Handler},
- {text: 'Item 2', handler: item2Handler}
- ]
- })
-});
-
-// Instead of showing a menu, you provide any type of custom
-// functionality you want when the dropdown arrow is clicked:
-new Ext.SplitButton({
- renderTo: 'button-ct',
- text: 'Options',
- handler: optionsHandler,
- arrowHandler: myCustomHandler
-});
-
- * @cfg {Function} arrowHandler A function called when the arrow button is clicked (can be used instead of click event)
- * @cfg {String} arrowTooltip The title attribute of the arrow
- * @constructor
- * Create a new menu button
- * @param {Object} config The config object
- * @xtype splitbutton
- */
-Ext.SplitButton = Ext.extend(Ext.Button, {
- // private
- arrowSelector : 'em',
- split: true,
-
- // private
- initComponent : function(){
- Ext.SplitButton.superclass.initComponent.call(this);
- /**
- * @event arrowclick
- * Fires when this button's arrow is clicked
- * @param {MenuButton} this
- * @param {EventObject} e The click event
- */
- this.addEvents("arrowclick");
- },
-
- // private
- onRender : function(){
- Ext.SplitButton.superclass.onRender.apply(this, arguments);
- if(this.arrowTooltip){
- this.el.child(this.arrowSelector).dom[this.tooltipType] = this.arrowTooltip;
- }
- },
-
- /**
- * Sets this button's arrow click handler.
- * @param {Function} handler The function to call when the arrow is clicked
- * @param {Object} scope (optional) Scope for the function passed above
- */
- setArrowHandler : function(handler, scope){
- this.arrowHandler = handler;
- this.scope = scope;
- },
-
- getMenuClass : function(){
- return 'x-btn-split' + (this.arrowAlign == 'bottom' ? '-bottom' : '');
- },
-
- isClickOnArrow : function(e){
- return this.arrowAlign != 'bottom' ?
- e.getPageX() > this.el.child(this.buttonSelector).getRegion().right :
- e.getPageY() > this.el.child(this.buttonSelector).getRegion().bottom;
- },
-
- // private
- onClick : function(e, t){
- e.preventDefault();
- if(!this.disabled){
- if(this.isClickOnArrow(e)){
- if(this.menu && !this.menu.isVisible() && !this.ignoreNextClick){
- this.showMenu();
- }
- this.fireEvent("arrowclick", this, e);
- if(this.arrowHandler){
- this.arrowHandler.call(this.scope || this, this, e);
- }
- }else{
- if(this.enableToggle){
- this.toggle();
- }
- this.fireEvent("click", this, e);
- if(this.handler){
- this.handler.call(this.scope || this, this, e);
- }
- }
- }
- },
-
- // private
- isMenuTriggerOver : function(e){
- return this.menu && e.target.tagName == 'em';
- },
-
- // private
- isMenuTriggerOut : function(e, internal){
- return this.menu && e.target.tagName != 'em';
- }
-});
-
-Ext.reg('splitbutton', Ext.SplitButton);/**
- * @class Ext.CycleButton
- * @extends Ext.SplitButton
- * A specialized SplitButton that contains a menu of {@link Ext.menu.CheckItem} elements. The button automatically
- * cycles through each menu item on click, raising the button's {@link #change} event (or calling the button's
- * {@link #changeHandler} function, if supplied) for the active menu item. Clicking on the arrow section of the
- * button displays the dropdown menu just like a normal SplitButton. Example usage:
- *
-var btn = new Ext.CycleButton({
- showText: true,
- prependText: 'View as ',
- items: [{
- text:'text only',
- iconCls:'view-text',
- checked:true
- },{
- text:'HTML',
- iconCls:'view-html'
- }],
- changeHandler:function(btn, item){
- Ext.Msg.alert('Change View', item.text);
- }
-});
-
- * @constructor
- * Create a new split button
- * @param {Object} config The config object
- * @xtype cycle
- */
-Ext.CycleButton = Ext.extend(Ext.SplitButton, {
- /**
- * @cfg {Array} items An array of {@link Ext.menu.CheckItem} config objects to be used when creating the
- * button's menu items (e.g., {text:'Foo', iconCls:'foo-icon'})
- */
- /**
- * @cfg {Boolean} showText True to display the active item's text as the button text (defaults to false)
- */
- /**
- * @cfg {String} prependText A static string to prepend before the active item's text when displayed as the
- * button's text (only applies when showText = true, defaults to '')
- */
- /**
- * @cfg {Function} changeHandler A callback function that will be invoked each time the active menu
- * item in the button's menu has changed. If this callback is not supplied, the SplitButton will instead
- * fire the {@link #change} event on active item change. The changeHandler function will be called with the
- * following argument list: (SplitButton this, Ext.menu.CheckItem item)
- */
- /**
- * @cfg {String} forceIcon A css class which sets an image to be used as the static icon for this button. This
- * icon will always be displayed regardless of which item is selected in the dropdown list. This overrides the
- * default behavior of changing the button's icon to match the selected item's icon on change.
- */
- /**
- * @property menu
- * @type Menu
- * The {@link Ext.menu.Menu Menu} object used to display the {@link Ext.menu.CheckItem CheckItems} representing the available choices.
- */
-
- // private
- getItemText : function(item){
- if(item && this.showText === true){
- var text = '';
- if(this.prependText){
- text += this.prependText;
- }
- text += item.text;
- return text;
- }
- return undefined;
- },
-
- /**
- * Sets the button's active menu item.
- * @param {Ext.menu.CheckItem} item The item to activate
- * @param {Boolean} suppressEvent True to prevent the button's change event from firing (defaults to false)
- */
- setActiveItem : function(item, suppressEvent){
- if(typeof item != 'object'){
- item = this.menu.items.get(item);
- }
- if(item){
- if(!this.rendered){
- this.text = this.getItemText(item);
- this.iconCls = item.iconCls;
- }else{
- var t = this.getItemText(item);
- if(t){
- this.setText(t);
- }
- this.setIconClass(item.iconCls);
- }
- this.activeItem = item;
- if(!item.checked){
- item.setChecked(true, true);
- }
- if(this.forceIcon){
- this.setIconClass(this.forceIcon);
- }
- if(!suppressEvent){
- this.fireEvent('change', this, item);
- }
- }
- },
-
- /**
- * Gets the currently active menu item.
- * @return {Ext.menu.CheckItem} The active item
- */
- getActiveItem : function(){
- return this.activeItem;
- },
-
- // private
- initComponent : function(){
- this.addEvents(
- /**
- * @event change
- * Fires after the button's active menu item has changed. Note that if a {@link #changeHandler} function
- * is set on this CycleButton, it will be called instead on active item change and this change event will
- * not be fired.
- * @param {Ext.CycleButton} this
- * @param {Ext.menu.CheckItem} item The menu item that was selected
- */
- "change"
- );
-
- if(this.changeHandler){
- this.on('change', this.changeHandler, this.scope||this);
- delete this.changeHandler;
- }
-
- this.itemCount = this.items.length;
-
- this.menu = {cls:'x-cycle-menu', items:[]};
- var checked;
- for(var i = 0, len = this.itemCount; i < len; i++){
- var item = this.items[i];
- item.group = item.group || this.id;
- item.itemIndex = i;
- item.checkHandler = this.checkHandler;
- item.scope = this;
- item.checked = item.checked || false;
- this.menu.items.push(item);
- if(item.checked){
- checked = item;
- }
- }
- this.setActiveItem(checked, true);
- Ext.CycleButton.superclass.initComponent.call(this);
-
- this.on('click', this.toggleSelected, this);
- },
-
- // private
- checkHandler : function(item, pressed){
- if(pressed){
- this.setActiveItem(item);
- }
- },
-
- /**
- * This is normally called internally on button click, but can be called externally to advance the button's
- * active item programmatically to the next one in the menu. If the current item is the last one in the menu
- * the active item will be set to the first item in the menu.
- */
- toggleSelected : function(){
- this.menu.render();
-
- var nextIdx, checkItem;
- for (var i = 1; i < this.itemCount; i++) {
- nextIdx = (this.activeItem.itemIndex + i) % this.itemCount;
- // check the potential item
- checkItem = this.menu.items.itemAt(nextIdx);
- // if its not disabled then check it.
- if (!checkItem.disabled) {
- checkItem.setChecked(true);
- break;
- }
- }
- }
-});
+}();
+/**
+ * @class Ext.SplitButton
+ * @extends Ext.Button
+ * A split button that provides a built-in dropdown arrow that can fire an event separately from the default
+ * click event of the button. Typically this would be used to display a dropdown menu that provides additional
+ * options to the primary button action, but any custom handler can provide the arrowclick implementation. Example usage:
+ *
+// display a dropdown menu:
+new Ext.SplitButton({
+ renderTo: 'button-ct', // the container id
+ text: 'Options',
+ handler: optionsHandler, // handle a click on the button itself
+ menu: new Ext.menu.Menu({
+ items: [
+ // these items will render as dropdown menu items when the arrow is clicked:
+ {text: 'Item 1', handler: item1Handler},
+ {text: 'Item 2', handler: item2Handler}
+ ]
+ })
+});
+
+// Instead of showing a menu, you provide any type of custom
+// functionality you want when the dropdown arrow is clicked:
+new Ext.SplitButton({
+ renderTo: 'button-ct',
+ text: 'Options',
+ handler: optionsHandler,
+ arrowHandler: myCustomHandler
+});
+
+ * @cfg {Function} arrowHandler A function called when the arrow button is clicked (can be used instead of click event)
+ * @cfg {String} arrowTooltip The title attribute of the arrow
+ * @constructor
+ * Create a new menu button
+ * @param {Object} config The config object
+ * @xtype splitbutton
+ */
+Ext.SplitButton = Ext.extend(Ext.Button, {
+ // private
+ arrowSelector : 'em',
+ split: true,
+
+ // private
+ initComponent : function(){
+ Ext.SplitButton.superclass.initComponent.call(this);
+ /**
+ * @event arrowclick
+ * Fires when this button's arrow is clicked
+ * @param {MenuButton} this
+ * @param {EventObject} e The click event
+ */
+ this.addEvents("arrowclick");
+ },
+
+ // private
+ onRender : function(){
+ Ext.SplitButton.superclass.onRender.apply(this, arguments);
+ if(this.arrowTooltip){
+ this.el.child(this.arrowSelector).dom[this.tooltipType] = this.arrowTooltip;
+ }
+ },
+
+ /**
+ * Sets this button's arrow click handler.
+ * @param {Function} handler The function to call when the arrow is clicked
+ * @param {Object} scope (optional) Scope for the function passed above
+ */
+ setArrowHandler : function(handler, scope){
+ this.arrowHandler = handler;
+ this.scope = scope;
+ },
+
+ getMenuClass : function(){
+ return 'x-btn-split' + (this.arrowAlign == 'bottom' ? '-bottom' : '');
+ },
+
+ isClickOnArrow : function(e){
+ if (this.arrowAlign != 'bottom') {
+ var visBtn = this.el.child('em.x-btn-split');
+ var right = visBtn.getRegion().right - visBtn.getPadding('r');
+ return e.getPageX() > right;
+ } else {
+ return e.getPageY() > this.btnEl.getRegion().bottom;
+ }
+ },
+
+ // private
+ onClick : function(e, t){
+ e.preventDefault();
+ if(!this.disabled){
+ if(this.isClickOnArrow(e)){
+ if(this.menu && !this.menu.isVisible() && !this.ignoreNextClick){
+ this.showMenu();
+ }
+ this.fireEvent("arrowclick", this, e);
+ if(this.arrowHandler){
+ this.arrowHandler.call(this.scope || this, this, e);
+ }
+ }else{
+ if(this.enableToggle){
+ this.toggle();
+ }
+ this.fireEvent("click", this, e);
+ if(this.handler){
+ this.handler.call(this.scope || this, this, e);
+ }
+ }
+ }
+ },
+
+ // private
+ isMenuTriggerOver : function(e){
+ return this.menu && e.target.tagName == this.arrowSelector;
+ },
+
+ // private
+ isMenuTriggerOut : function(e, internal){
+ return this.menu && e.target.tagName != this.arrowSelector;
+ }
+});
+
+Ext.reg('splitbutton', Ext.SplitButton);/**
+ * @class Ext.CycleButton
+ * @extends Ext.SplitButton
+ * A specialized SplitButton that contains a menu of {@link Ext.menu.CheckItem} elements. The button automatically
+ * cycles through each menu item on click, raising the button's {@link #change} event (or calling the button's
+ * {@link #changeHandler} function, if supplied) for the active menu item. Clicking on the arrow section of the
+ * button displays the dropdown menu just like a normal SplitButton. Example usage:
+ *
+var btn = new Ext.CycleButton({
+ showText: true,
+ prependText: 'View as ',
+ items: [{
+ text:'text only',
+ iconCls:'view-text',
+ checked:true
+ },{
+ text:'HTML',
+ iconCls:'view-html'
+ }],
+ changeHandler:function(btn, item){
+ Ext.Msg.alert('Change View', item.text);
+ }
+});
+
+ * @constructor
+ * Create a new split button
+ * @param {Object} config The config object
+ * @xtype cycle
+ */
+Ext.CycleButton = Ext.extend(Ext.SplitButton, {
+ /**
+ * @cfg {Array} items An array of {@link Ext.menu.CheckItem} config objects to be used when creating the
+ * button's menu items (e.g., {text:'Foo', iconCls:'foo-icon'})
+ */
+ /**
+ * @cfg {Boolean} showText True to display the active item's text as the button text (defaults to false)
+ */
+ /**
+ * @cfg {String} prependText A static string to prepend before the active item's text when displayed as the
+ * button's text (only applies when showText = true, defaults to '')
+ */
+ /**
+ * @cfg {Function} changeHandler A callback function that will be invoked each time the active menu
+ * item in the button's menu has changed. If this callback is not supplied, the SplitButton will instead
+ * fire the {@link #change} event on active item change. The changeHandler function will be called with the
+ * following argument list: (SplitButton this, Ext.menu.CheckItem item)
+ */
+ /**
+ * @cfg {String} forceIcon A css class which sets an image to be used as the static icon for this button. This
+ * icon will always be displayed regardless of which item is selected in the dropdown list. This overrides the
+ * default behavior of changing the button's icon to match the selected item's icon on change.
+ */
+ /**
+ * @property menu
+ * @type Menu
+ * The {@link Ext.menu.Menu Menu} object used to display the {@link Ext.menu.CheckItem CheckItems} representing the available choices.
+ */
+
+ // private
+ getItemText : function(item){
+ if(item && this.showText === true){
+ var text = '';
+ if(this.prependText){
+ text += this.prependText;
+ }
+ text += item.text;
+ return text;
+ }
+ return undefined;
+ },
+
+ /**
+ * Sets the button's active menu item.
+ * @param {Ext.menu.CheckItem} item The item to activate
+ * @param {Boolean} suppressEvent True to prevent the button's change event from firing (defaults to false)
+ */
+ setActiveItem : function(item, suppressEvent){
+ if(!Ext.isObject(item)){
+ item = this.menu.getComponent(item);
+ }
+ if(item){
+ if(!this.rendered){
+ this.text = this.getItemText(item);
+ this.iconCls = item.iconCls;
+ }else{
+ var t = this.getItemText(item);
+ if(t){
+ this.setText(t);
+ }
+ this.setIconClass(item.iconCls);
+ }
+ this.activeItem = item;
+ if(!item.checked){
+ item.setChecked(true, false);
+ }
+ if(this.forceIcon){
+ this.setIconClass(this.forceIcon);
+ }
+ if(!suppressEvent){
+ this.fireEvent('change', this, item);
+ }
+ }
+ },
+
+ /**
+ * Gets the currently active menu item.
+ * @return {Ext.menu.CheckItem} The active item
+ */
+ getActiveItem : function(){
+ return this.activeItem;
+ },
+
+ // private
+ initComponent : function(){
+ this.addEvents(
+ /**
+ * @event change
+ * Fires after the button's active menu item has changed. Note that if a {@link #changeHandler} function
+ * is set on this CycleButton, it will be called instead on active item change and this change event will
+ * not be fired.
+ * @param {Ext.CycleButton} this
+ * @param {Ext.menu.CheckItem} item The menu item that was selected
+ */
+ "change"
+ );
+
+ if(this.changeHandler){
+ this.on('change', this.changeHandler, this.scope||this);
+ delete this.changeHandler;
+ }
+
+ this.itemCount = this.items.length;
+
+ this.menu = {cls:'x-cycle-menu', items:[]};
+ var checked = 0;
+ Ext.each(this.items, function(item, i){
+ Ext.apply(item, {
+ group: item.group || this.id,
+ itemIndex: i,
+ checkHandler: this.checkHandler,
+ scope: this,
+ checked: item.checked || false
+ });
+ this.menu.items.push(item);
+ if(item.checked){
+ checked = i;
+ }
+ }, this);
+ Ext.CycleButton.superclass.initComponent.call(this);
+ this.on('click', this.toggleSelected, this);
+ this.setActiveItem(checked, true);
+ },
+
+ // private
+ checkHandler : function(item, pressed){
+ if(pressed){
+ this.setActiveItem(item);
+ }
+ },
+
+ /**
+ * This is normally called internally on button click, but can be called externally to advance the button's
+ * active item programmatically to the next one in the menu. If the current item is the last one in the menu
+ * the active item will be set to the first item in the menu.
+ */
+ toggleSelected : function(){
+ var m = this.menu;
+ m.render();
+ // layout if we haven't before so the items are active
+ if(!m.hasLayout){
+ m.doLayout();
+ }
+
+ var nextIdx, checkItem;
+ for (var i = 1; i < this.itemCount; i++) {
+ nextIdx = (this.activeItem.itemIndex + i) % this.itemCount;
+ // check the potential item
+ checkItem = m.items.itemAt(nextIdx);
+ // if its not disabled then check it.
+ if (!checkItem.disabled) {
+ checkItem.setChecked(true);
+ break;
+ }
+ }
+ }
+});
Ext.reg('cycle', Ext.CycleButton);
\ No newline at end of file