Clean up DOM code a bit.

This commit is contained in:
Jürg Lehni 2014-10-05 00:19:47 +02:00
parent 9fec267dd4
commit 5456f1a595
2 changed files with 19 additions and 16 deletions

View file

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

View file

@ -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);
}
},