ButtonGroup: add enableButton/disableButton methods
This commit is contained in:
parent
dffd160ed3
commit
3e2c2d451e
1 changed files with 23 additions and 6 deletions
|
@ -71,26 +71,35 @@ Ox.ButtonGroup = function(options, self) {
|
|||
|
||||
self.$buttons = [];
|
||||
self.options.buttons.forEach(function(button, pos) {
|
||||
var id = self.options.id + Ox.toTitleCase(button.id);
|
||||
self.$buttons[pos] = Ox.Button({
|
||||
disabled: button.disabled,
|
||||
disabled: button.disabled || false, // FIXME: getset should handle undefined
|
||||
group: true,
|
||||
id: id,
|
||||
id: button.id,
|
||||
selectable: self.options.selectable,
|
||||
size: self.options.size,
|
||||
style: self.options.style,
|
||||
title: button.title,
|
||||
tooltip: button.tooltip,
|
||||
type: self.options.type,
|
||||
value: button.selected,
|
||||
value: button.selected || false, // FIXME: getset should handle undefined
|
||||
width: button.width
|
||||
})
|
||||
.bindEvent('change', function() {
|
||||
self.options.selectable && toggleButton(pos);
|
||||
.bindEvent(self.options.selectable ? {
|
||||
change: function() {
|
||||
toggleButton(pos);
|
||||
}
|
||||
} : {
|
||||
click: function() {
|
||||
that.triggerEvent('click', {id: button.id});
|
||||
}
|
||||
})
|
||||
.appendTo(that);
|
||||
});
|
||||
|
||||
function getButtonById(id) {
|
||||
return self.$buttons[Ox.getIndexById(self.options.buttons, id)];
|
||||
}
|
||||
|
||||
function toggleButton(pos) {
|
||||
var toggled = self.optionGroup.toggle(pos);
|
||||
if (!toggled.length) {
|
||||
|
@ -113,6 +122,14 @@ Ox.ButtonGroup = function(options, self) {
|
|||
}
|
||||
}
|
||||
|
||||
that.disableButton = function(id) {
|
||||
getButtonById(id).options({disabled: true});
|
||||
};
|
||||
|
||||
that.enableButton = function(id) {
|
||||
getButtonById(id).options({disabled: false});
|
||||
};
|
||||
|
||||
return that;
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue