mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
Move Palette related functionality form Pane to Palette constructor.
This commit is contained in:
parent
e1fba03b34
commit
85fbc94f41
2 changed files with 15 additions and 15 deletions
|
@ -25,13 +25,25 @@
|
||||||
// DOCS: Palette#remove()
|
// DOCS: Palette#remove()
|
||||||
|
|
||||||
initialize: function Palette(title, components, values) {
|
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')
|
var parent = DomElement.find('.palettejs-panel')
|
||||||
|| DomElement.find('body').appendChild(
|
|| DomElement.find('body').appendChild(
|
||||||
DomElement.create('div', { class: 'palettejs-panel' }));
|
DomElement.create('div', { class: 'palettejs-panel' }));
|
||||||
this._element = parent.appendChild(
|
this._element = parent.appendChild(
|
||||||
DomElement.create('div', { class: 'palettejs-palette' },
|
DomElement.create('div', { class: 'palettejs-palette' },
|
||||||
[this._table]));
|
[this._table]));
|
||||||
|
if (props) {
|
||||||
|
Base.set(this, props,
|
||||||
|
{ title: true, components: true, values: true });
|
||||||
|
}
|
||||||
// Link to the current scope's palettes list.
|
// Link to the current scope's palettes list.
|
||||||
// TODO: This is the only paper dependency in Palette.js
|
// TODO: This is the only paper dependency in Palette.js
|
||||||
// Find a way to make it independent.
|
// Find a way to make it independent.
|
||||||
|
|
|
@ -20,18 +20,10 @@ var Pane = Base.extend(Callback, /** @lends Pane# */{
|
||||||
// Defaults for internals
|
// Defaults for internals
|
||||||
_enabled: true,
|
_enabled: true,
|
||||||
|
|
||||||
initialize: function Pane(title, components, values) {
|
initialize: function Pane(components, values) {
|
||||||
// Support object literal constructor
|
|
||||||
var props = Base.isPlainObject(title) && title;
|
|
||||||
if (props) {
|
|
||||||
title = props.title;
|
|
||||||
components = props.components;
|
|
||||||
values = props.values;
|
|
||||||
}
|
|
||||||
if (!values)
|
if (!values)
|
||||||
values = {};
|
values = {};
|
||||||
this._table = DomElement.create('table', { class: 'palettejs-pane' });
|
this._table = DomElement.create('table', { class: 'palettejs-pane' });
|
||||||
this._title = title;
|
|
||||||
// NOTE: We modify the actual passed components and values objects so
|
// NOTE: We modify the actual passed components and values objects so
|
||||||
// the newly created components and their values can easily be
|
// the newly created components and their values can easily be
|
||||||
// referenced from outside.
|
// referenced from outside.
|
||||||
|
@ -43,7 +35,7 @@ var Pane = Base.extend(Callback, /** @lends Pane# */{
|
||||||
if (Base.isPlainObject(component)) {
|
if (Base.isPlainObject(component)) {
|
||||||
var row = DomElement.addChildren(this._table,
|
var row = DomElement.addChildren(this._table,
|
||||||
['tr', { class: 'palettejs-row' }])[0];
|
['tr', { class: 'palettejs-row' }])[0];
|
||||||
new Component(this, name, components[name], values[name], row);
|
new Component(this, name, component, values, row);
|
||||||
} else {
|
} else {
|
||||||
delete components[name];
|
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() {
|
getComponents: function() {
|
||||||
|
|
Loading…
Reference in a new issue