Move Palette related functionality form Pane to Palette constructor.

This commit is contained in:
Jürg Lehni 2014-10-02 17:09:08 +02:00
parent e1fba03b34
commit 85fbc94f41
2 changed files with 15 additions and 15 deletions

View file

@ -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.

View file

@ -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() {