From d6481bcb5b795073de22159cd16996d0e78b51b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 30 Sep 2014 08:20:18 +0200 Subject: [PATCH] Implement Component#enabled and Palette#enabled --- src/ui/Component.js | 20 ++++++++++++++++++++ src/ui/Palette.js | 12 ++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/ui/Component.js b/src/ui/Component.js index 357fdbaf..9bf7105e 100644 --- a/src/ui/Component.js +++ b/src/ui/Component.js @@ -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'))]; diff --git a/src/ui/Palette.js b/src/ui/Palette.js index 615831ef..e3f26af3 100644 --- a/src/ui/Palette.js +++ b/src/ui/Palette.js @@ -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}.