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.$buttons = [];
|
||||||
self.options.buttons.forEach(function(button, pos) {
|
self.options.buttons.forEach(function(button, pos) {
|
||||||
var id = self.options.id + Ox.toTitleCase(button.id);
|
|
||||||
self.$buttons[pos] = Ox.Button({
|
self.$buttons[pos] = Ox.Button({
|
||||||
disabled: button.disabled,
|
disabled: button.disabled || false, // FIXME: getset should handle undefined
|
||||||
group: true,
|
group: true,
|
||||||
id: id,
|
id: button.id,
|
||||||
selectable: self.options.selectable,
|
selectable: self.options.selectable,
|
||||||
size: self.options.size,
|
size: self.options.size,
|
||||||
style: self.options.style,
|
style: self.options.style,
|
||||||
title: button.title,
|
title: button.title,
|
||||||
tooltip: button.tooltip,
|
tooltip: button.tooltip,
|
||||||
type: self.options.type,
|
type: self.options.type,
|
||||||
value: button.selected,
|
value: button.selected || false, // FIXME: getset should handle undefined
|
||||||
width: button.width
|
width: button.width
|
||||||
})
|
})
|
||||||
.bindEvent('change', function() {
|
.bindEvent(self.options.selectable ? {
|
||||||
self.options.selectable && toggleButton(pos);
|
change: function() {
|
||||||
|
toggleButton(pos);
|
||||||
|
}
|
||||||
|
} : {
|
||||||
|
click: function() {
|
||||||
|
that.triggerEvent('click', {id: button.id});
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.appendTo(that);
|
.appendTo(that);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getButtonById(id) {
|
||||||
|
return self.$buttons[Ox.getIndexById(self.options.buttons, id)];
|
||||||
|
}
|
||||||
|
|
||||||
function toggleButton(pos) {
|
function toggleButton(pos) {
|
||||||
var toggled = self.optionGroup.toggle(pos);
|
var toggled = self.optionGroup.toggle(pos);
|
||||||
if (!toggled.length) {
|
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;
|
return that;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue