mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 06:00:56 -05:00
Clean up DOM code a bit.
This commit is contained in:
parent
9fec267dd4
commit
5456f1a595
2 changed files with 19 additions and 16 deletions
|
@ -174,21 +174,25 @@ var DomElement = new function() {
|
|||
el.removeChild(el.firstChild);
|
||||
},
|
||||
|
||||
addChild: function(el, child) {
|
||||
return create(child, el)[0];
|
||||
},
|
||||
|
||||
insertBefore: function(ref, el) {
|
||||
return ref.parentNode.insertBefore(create(el)[0], ref);
|
||||
},
|
||||
|
||||
// insertAfter: function(ref, el) {
|
||||
// var parent = ref.parentNode,
|
||||
// next = ref.nextSibling,
|
||||
// el = create(el)[0];
|
||||
// if (next) {
|
||||
// parent.insertBefore(el, next);
|
||||
// } else {
|
||||
// parent.appendChild(el);
|
||||
// }
|
||||
// return el;
|
||||
// },
|
||||
insertAfter: function(ref, el) {
|
||||
var parent = ref.parentNode,
|
||||
next = ref.nextSibling,
|
||||
el = create(el)[0];
|
||||
if (next) {
|
||||
parent.insertBefore(el, next);
|
||||
} else {
|
||||
parent.appendChild(el);
|
||||
}
|
||||
return el;
|
||||
},
|
||||
|
||||
getBounds: function(el, viewport) {
|
||||
var doc = el.ownerDocument,
|
||||
|
|
|
@ -254,8 +254,7 @@ var Component = Base.extend(Callback, /** @lends Component# */{
|
|||
if (!node && title) {
|
||||
// Create a caption tag, and nest the title in a span inside,
|
||||
// so we can offer some more flexibility with CSS on it.
|
||||
node = this._titleNode = DomElement.insertBefore(
|
||||
this._tbody, [
|
||||
node = this._titleNode = DomElement.insertBefore(this._tbody, [
|
||||
'caption', [ 'span' ],
|
||||
]).firstChild;
|
||||
} else if (node && !title) {
|
||||
|
@ -275,9 +274,9 @@ var Component = Base.extend(Callback, /** @lends Component# */{
|
|||
|
||||
_setLabel: function(label, nodeName, parent) {
|
||||
if (parent) {
|
||||
this[nodeName] = DomElement.set(this[nodeName]
|
||||
|| parent.appendChild(DomElement.create('label',
|
||||
{ 'for': 'palettejs-input-' + this._name })),
|
||||
this[nodeName] = DomElement.set(
|
||||
this[nodeName] || DomElement.addChild(parent,
|
||||
['label', { 'for': 'palettejs-input-' + this._name }]),
|
||||
'text', label);
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue