// raw events
/**
* @event click
- * The raw click event for the entire grid.
+ * When a butotn is pressed
* @param {Roo.EventObject} e
*/
- "click" : true
+ "click" : true,
+ /**
+ * @event toggle
+ * After the button has been toggles
+ * @param {Roo.EventObject} e
+ * @param {boolean} pressed (also available as button.pressed)
+ */
+ "toggle" : true
});
};
name: false,
target: false,
+
+ pressed : null,
+
+
getAutoCreate : function(){
var cfg = {
} else {
cfg.tag = this.tag;
}
- cfg.html = this.html || cfg.html;
+ cfg.html = '<span class="roo-button-text">' + (this.html || cfg.html) + '</span>';
- if (this.toggle===true) {
+ if (this.toggle == true) {
cfg={
tag: 'div',
cls: 'slider-frame roo-button',
if (this.theme==='default') {
cfg.cls = 'btn roo-button';
- if (this.parentType != 'Navbar') {
- this.weight = this.weight.length ? this.weight : 'default';
- }
+ //if (this.parentType != 'Navbar') {
+ this.weight = this.weight.length ? this.weight : 'default';
+ //}
if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
cfg.cls += ' btn-' + this.weight;
if (this.disabled) {
cfg.disabled = 'disabled';
}
- //????
+
if (this.items) {
Roo.log('changing to ul' );
- cfg.tag = 'ul';
+ cfg.tag = 'div';
this.glyphicon = 'caret';
}
+ cfg.cls += this.size.length ? (' btn-' + this.size) : '';
+
+ //gsRoo.log(this.parentType);
+ if (this.parentType === 'Navbar' && !this.parent().bar) {
+ Roo.log('changing to li?');
+
+ cfg.tag = 'li';
+
+ cfg.cls = '';
+ cfg.cn = [{
+ tag : 'a',
+ cls : 'roo-button',
+ html : this.html,
+ href : this.href || '#'
+ }];
+ if (this.menu) {
+ cfg.cn[0].html = this.html + ' <span class="caret"></span>';
+ cfg.cls += ' dropdown';
+ }
+
+ delete cfg.html;
+
+ }
+
+ cfg.cls += this.parentType === 'Navbar' ? ' navbar-btn' : '';
+
if (this.glyphicon) {
cfg.html = ' ' + cfg.html;
cfg.html='';
}
- cfg.cls += this.size.length ? (' btn-' + this.size) : '';
-
- //gsRoo.log(this.parentType);
- if (this.parentType === 'Navbar') {
- cfg.tag = 'li';
-
- cfg.cls = '';
- cfg.cn = [{
- tag : 'a',
- cls : 'roo-button',
- html : this.html,
- href : this.href || '#'
- }];
- if (this.menu) {
- cfg.cn[0].html = this.html + ' <span class="caret"></span>';
- cfg.cls += ' dropdown';
- }
-
- delete cfg.html;
-
- }
- else if (this.menu) {
+ if (this.menu) {
cfg.cls += ' dropdown';
- cfg.html = this.html + ' <span class="caret"></span>';
+ cfg.html = typeof(cfg.html) != 'undefined' ? cfg.html + ' <span class="caret"></span>' : '<span class="caret"></span>';
}
if (cfg.tag !== 'a' && this.href !== '') {
initEvents: function() {
// Roo.log('init events?');
// Roo.log(this.el.dom);
+ // add the menu...
+
+ if (typeof (this.menu) != 'undefined') {
+ this.menu.parentType = this.xtype;
+ this.menu.triggerEl = this.el;
+ this.addxtype(Roo.apply({}, this.menu));
+ }
+
+
if (this.el.hasClass('roo-button')) {
this.el.on('click', this.onClick, this);
} else {
this.el.select('.roo-button').on('click', this.onClick, this);
}
+ if(this.removeClass){
+ this.el.on('click', this.onClick, this);
+ }
+ this.el.enableDisplayMode();
},
onClick : function(e)
{
+ if (this.disabled) {
+ return;
+ }
+
Roo.log('button on click ');
if(this.preventDefault){
e.preventDefault();
}
+ if (this.pressed === true || this.pressed === false) {
+ this.pressed = !this.pressed;
+ this.el[this.pressed ? 'addClass' : 'removeClass']('active');
+ this.fireEvent('toggle', this, e, this.pressed);
+ }
+
this.fireEvent('click', this, e);
+ },
+
+ /**
+ * Enables this button
+ */
+ enable : function()
+ {
+ this.disabled = false;
+ this.el.removeClass('disabled');
+ },
+
+ /**
+ * Disable this button
+ */
+ disable : function()
+ {
+ this.disabled = true;
+ this.el.addClass('disabled');
+ },
+ /**
+ * sets the active state on/off,
+ * @param {Boolean} state (optional) Force a particular state
+ */
+ setActive : function(v) {
+
+ this.el[v ? 'addClass' : 'removeClass']('active');
+ },
+ /**
+ * toggles the current active state
+ */
+ toggleActive : function()
+ {
+ var active = this.el.hasClass('active');
+ this.setActive(!active);
+
+
+ },
+ setText : function(str)
+ {
+ this.el.select('.roo-button-text',true).first().dom.innerHTML = str;
+ },
+ getText : function()
+ {
+ return this.el.select('.roo-button-text',true).first().dom.innerHTML;
+ },
+ hide: function() {
+
+
+ this.el.hide();
+ },
+ show: function() {
+
+ this.el.show();
}