Implement Component#enabled and Palette#enabled

This commit is contained in:
Jürg Lehni 2014-09-30 08:20:18 +02:00
parent 021ba59c54
commit d6481bcb5b
2 changed files with 32 additions and 0 deletions

View file

@ -81,6 +81,9 @@ var Component = Base.extend(Callback, /** @lends Component# */{
}
},
// Default values for internals
_enabled: true,
initialize: function Component(obj) {
this._id = Component._id = (Component._id || 0) + 1;
var type = this._type = obj.type in this._types
@ -206,6 +209,23 @@ var Component = Base.extend(Callback, /** @lends Component# */{
DomElement.toggleClass(this._element, 'hidden', !visible);
},
getEnabled: function() {
return this._enabled;
},
setEnabled: function(enabled, _fromPalette) {
if (_fromPalette) {
// When called from Palette#setEnabled, we have to remember the
// component's previous enabled state when disabling the palette,
// so we can restore it when enabling the palette again.
var prev = Base.pick(this._previousEnabled, this._enabled);
this._previousEnabled = enabled ? undefined : prev; // clear
enabled = enabled && prev;
}
DomElement.set(this._input, 'disabled', !enabled);
this._enabled = enabled;
},
getRange: function() {
return [parseFloat(DomElement.get(this._input, 'min')),
parseFloat(DomElement.get(this._input, 'max'))];

View file

@ -17,6 +17,8 @@
/* var Palette = */ Base.extend(Callback, /** @lends Palette# */{
_class: 'Palette',
_events: [ 'onChange' ],
// Defaults for internals
_enabled: true,
// DOCS: Palette#initialize
// DOCS: Palette#components
@ -69,6 +71,16 @@
paper.palettes.push(this);
},
getEnabled: function() {
return this._enabled;
},
setEnabled: function(enabled) {
this._enabled = enabled;
for (var i in this.components)
this.components[i].setEnabled(enabled, true);
},
/**
* Resets the values of the components to their
* {@link Component#defaultValue}.