Skip to content

Commit

Permalink
handle specific casese with appending
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey.Kupriyanenko committed May 5, 2014
1 parent 30cf675 commit 43520f2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,25 @@ fn.append = function(appended) {
length = this.length,
setter;

// create jBone object and then append
if (isString(appended) && rquickExpr.exec(appended)) {
appended = jBone(appended);
} else if (!isObject(appended)) {
}
// create text node for inserting
else if (!isObject(appended)) {
appended = document.createTextNode(appended);
}

if (appended instanceof jBone) {
// just append NodeElement
if (appended instanceof Node) {
setter = function(el) {
el.appendChild(appended);
};
}
// wrap object by jBone, and then append
else {
appended = appended instanceof jBone ? appended : jBone(appended);

setter = function(el, i) {
appended.forEach(function(node) {
if (i) {
Expand All @@ -35,10 +47,6 @@ fn.append = function(appended) {
}
});
};
} else if (appended instanceof Node) {
setter = function(el) {
el.appendChild(appended);
};
}

for (; i < length; i++) {
Expand Down
12 changes: 12 additions & 0 deletions test/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ describe('jBone Manipulation', function() {
expect(a.find('span')).to.have.length(2);
});

it('append(NodeList)', function() {
var a = jBone('<div>'),
f = document.createDocumentFragment();

f.appendChild(document.createElement('span'));
f.appendChild(document.createElement('span'));

a.append(f.childNodes);

expect(a.find('span')).to.have.length(2);
});

it('append(text)', function() {
var a = jBone('<div>');

Expand Down

0 comments on commit 43520f2

Please sign in to comment.