X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/ee06f37b0f6f6d94cd05a6ffae556660f7c4a2bc..c930e9176a5a85509c5b0230e2bff5c22a591432:/pkgs/pkg-buttons-debug.js diff --git a/pkgs/pkg-buttons-debug.js b/pkgs/pkg-buttons-debug.js new file mode 100644 index 00000000..86e62405 --- /dev/null +++ b/pkgs/pkg-buttons-debug.js @@ -0,0 +1,1060 @@ +/*! + * Ext JS Library 3.0.0 + * Copyright(c) 2006-2009 Ext JS, LLC + * licensing@extjs.com + * http://www.extjs.com/license + */ +/** + * @class Ext.Button + * @extends Ext.BoxComponent + * Simple Button class + * @cfg {String} text The button text to be used as innerHTML (html tags are accepted) + * @cfg {String} icon The path to an image to display in the button (the image will be set as the background-image + * CSS property of the button by default, so if you want a mixed icon/text button, set cls:'x-btn-text-icon') + * @cfg {Function} handler A function called when the button is clicked (can be used instead of click event). + * The handler is passed the following parameters:
b
: Buttone
: EventObject{@link Ext.Toolbar.Item#overflowText overflowText}
.
+ */
+ /**
+ * @cfg {String} iconCls
+ * A css class which sets a background image to be used as the icon for this button
+ */
+ /**
+ * @cfg {String} type
+ * submit, reset or button - defaults to 'button'
+ */
+ type : 'button',
+
+ // private
+ menuClassTarget: 'tr:nth(2)',
+
+ /**
+ * @cfg {String} clickEvent
+ * The type of event to map to the button's event handler (defaults to 'click')
+ */
+ clickEvent : 'click',
+
+ /**
+ * @cfg {Boolean} handleMouseEvents
+ * False to disable visual cues on mouseover, mouseout and mousedown (defaults to true)
+ */
+ handleMouseEvents : true,
+
+ /**
+ * @cfg {String} tooltipType
+ * The type of tooltip to use. Either 'qtip' (default) for QuickTips or 'title' for title attribute.
+ */
+ tooltipType : 'qtip',
+
+ /**
+ * @cfg {String} buttonSelector
+ * (Optional) A {@link Ext.DomQuery DomQuery} selector which is used to extract the active, clickable element from the + * DOM structure created.
+ *When 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".
+ */ + buttonSelector : 'button:first-child', + + /** + * @cfg {String} scale + *(Optional) The size of the Button. Three values are allowed:
+ *Defaults to 'small'.
+ */ + scale: 'small', + + /** + * @cfg {String} iconAlign + *(Optional) The side of the Button box to render the icon. Four values are allowed:
+ *Defaults to 'left'.
+ */ + iconAlign : 'left', + + /** + * @cfg {String} arrowAlign + *(Optional) The side of the Button box to render the arrow if the button has an associated {@link #menu}. + * Two values are allowed:
+ *Defaults to 'right'.
+ */ + arrowAlign : 'right', + + /** + * @cfg {Ext.Template} template (Optional) + *A {@link Ext.Template Template} used to create the Button's DOM structure.
+ * Instances, or subclasses which need a different DOM structure may provide a different + * template layout in conjunction with an implementation of {@link #getTemplateArgs}. + * @type Ext.Template + * @property template + */ + /** + * @cfg {String} cls + * A CSS class string to apply to the button's main element. + */ + /** + * @property menu + * @type Menu + * The {@link Ext.menu.Menu Menu} object associated with this Button when configured with the {@link #menu} config option. + */ + + initComponent : function(){ + Ext.Button.superclass.initComponent.call(this); + + this.addEvents( + /** + * @event click + * Fires when this button is clicked + * @param {Button} this + * @param {EventObject} e The click event + */ + 'click', + /** + * @event toggle + * Fires when the 'pressed' state of this button changes (only if enableToggle = true) + * @param {Button} this + * @param {Boolean} pressed + */ + 'toggle', + /** + * @event mouseover + * Fires when the mouse hovers over the button + * @param {Button} this + * @param {Event} e The event object + */ + 'mouseover', + /** + * @event mouseout + * Fires when the mouse exits the button + * @param {Button} this + * @param {Event} e The event object + */ + 'mouseout', + /** + * @event menushow + * If this button has a menu, this event fires when it is shown + * @param {Button} this + * @param {Menu} menu + */ + 'menushow', + /** + * @event menuhide + * If this button has a menu, this event fires when it is hidden + * @param {Button} this + * @param {Menu} menu + */ + 'menuhide', + /** + * @event menutriggerover + * If this button has a menu, this event fires when the mouse enters the menu triggering element + * @param {Button} this + * @param {Menu} menu + * @param {EventObject} e + */ + 'menutriggerover', + /** + * @event menutriggerout + * If this button has a menu, this event fires when the mouse leaves the menu triggering element + * @param {Button} this + * @param {Menu} menu + * @param {EventObject} e + */ + 'menutriggerout' + ); + if(this.menu){ + this.menu = Ext.menu.MenuMgr.get(this.menu); + } + if(Ext.isString(this.toggleGroup)){ + this.enableToggle = true; + } + }, + +/** + *This method returns an object 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:
+// 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;
+ }
+ }
+ }
+});
+Ext.reg('cycle', Ext.CycleButton);
\ No newline at end of file