From 85fbc94f4182f687b57b6f996835c36f251a29a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Thu, 2 Oct 2014 17:09:08 +0200 Subject: [PATCH] Move Palette related functionality form Pane to Palette constructor. --- src/ui/Palette.js | 14 +++++++++++++- src/ui/Pane.js | 16 ++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/ui/Palette.js b/src/ui/Palette.js index f56c8baa..e7814cbc 100644 --- a/src/ui/Palette.js +++ b/src/ui/Palette.js @@ -25,13 +25,25 @@ // DOCS: Palette#remove() initialize: function Palette(title, components, values) { - Pane.call(this, title, components, values); + // Support object literal constructor + var props = Base.isPlainObject(title) && title; + if (props) { + title = props.title; + components = props.components; + values = props.values; + } + this._title = title; + Pane.call(this, components, values); var parent = DomElement.find('.palettejs-panel') || DomElement.find('body').appendChild( DomElement.create('div', { class: 'palettejs-panel' })); this._element = parent.appendChild( DomElement.create('div', { class: 'palettejs-palette' }, [this._table])); + if (props) { + Base.set(this, props, + { title: true, components: true, values: true }); + } // Link to the current scope's palettes list. // TODO: This is the only paper dependency in Palette.js // Find a way to make it independent. diff --git a/src/ui/Pane.js b/src/ui/Pane.js index a6908aa0..a0bb58a9 100644 --- a/src/ui/Pane.js +++ b/src/ui/Pane.js @@ -20,18 +20,10 @@ var Pane = Base.extend(Callback, /** @lends Pane# */{ // Defaults for internals _enabled: true, - initialize: function Pane(title, components, values) { - // Support object literal constructor - var props = Base.isPlainObject(title) && title; - if (props) { - title = props.title; - components = props.components; - values = props.values; - } + initialize: function Pane(components, values) { if (!values) values = {}; this._table = DomElement.create('table', { class: 'palettejs-pane' }); - this._title = title; // NOTE: We modify the actual passed components and values objects so // the newly created components and their values can easily be // referenced from outside. @@ -43,7 +35,7 @@ var Pane = Base.extend(Callback, /** @lends Pane# */{ if (Base.isPlainObject(component)) { var row = DomElement.addChildren(this._table, ['tr', { class: 'palettejs-row' }])[0]; - new Component(this, name, components[name], values[name], row); + new Component(this, name, component, values, row); } else { delete components[name]; } @@ -76,10 +68,6 @@ var Pane = Base.extend(Callback, /** @lends Pane# */{ }); } }); - if (props) { - Base.set(this, props, - { title: true, components: true, values: true }); - } }, getComponents: function() {