Skip to content

Commit

Permalink
Fix: Support insertion of CharacterData nodes
Browse files Browse the repository at this point in the history
The original test for arrays yields false positives, since CharacterData elements also have a length property. Hence $('body').append(document.createTextNode('foo')) throws a TypeError.
  • Loading branch information
fgnass committed Oct 17, 2011
1 parent a1f0dad commit 89c03de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/zepto.js
Expand Up @@ -436,7 +436,7 @@ var Zepto = (function() {
adjacencyOperators.forEach(function(key, operator) {
$.fn[key] = function(html){
var nodes = isO(html) ? html : fragment(html);
if (!('length' in nodes)) nodes = [nodes];
if (!('length' in nodes) || nodes.nodeType) nodes = [nodes];
if (nodes.length < 1) return this;
var size = this.length, copyByClone = size > 1, inReverse = operator < 2;

Expand Down
14 changes: 14 additions & 0 deletions test/zepto.html
Expand Up @@ -1114,6 +1114,20 @@ <h1>Zepto DOM unit tests</h1>

t.assertEqual('before<div id="beforeafter">prependappend</div>after', $('#beforeafter_container').html());

//testing with TextNode as parameter
$('#beforeafter_container').html('<div id="beforeafter"></div>');

function text(contents){
return document.createTextNode(contents);
}

$('#beforeafter').append(text('append'));
$('#beforeafter').prepend(text('prepend'));
$('#beforeafter').before(text('before'));
$('#beforeafter').after(text('after'));

t.assertEqual('before<div id="beforeafter">prependappend</div>after', $('#beforeafter_container').html());

$('#beforeafter_container').html('<div id="beforeafter"></div>');

function div(contents){
Expand Down

0 comments on commit 89c03de

Please sign in to comment.