fix(jqLite): support append on document fragment

previously jquery didn't support append on this node type, now it does
(since 1.8.x) so I'm adding this to jqlite as well.
This commit is contained in:
Igor Minar 2012-11-24 01:34:01 +01:00
parent b9a9f91fbf
commit 96ed9ff59a
2 changed files with 8 additions and 2 deletions

View file

@ -659,8 +659,9 @@ forEach({
append: function(element, node) {
forEach(new JQLite(node), function(child){
if (element.nodeType === 1)
if (element.nodeType === 1 || element.nodeType === 11) {
element.appendChild(child);
}
});
},

View file

@ -955,9 +955,14 @@ describe('jqLite', function() {
expect(root.append('text')).toEqual(root);
expect(root.html()).toEqual('text');
});
it('should not append anything if parent node is not of type element', function() {
it('should append to document fragment', function() {
var root = jqLite(document.createDocumentFragment());
expect(root.append('<p>foo</p>')).toBe(root);
expect(root.children().length).toBe(1);
});
it('should not append anything if parent node is not of type element or docfrag', function() {
var root = jqLite('<p>some text node</p>').contents();
expect(root.append('<p>foo</p>')).toBe(root);
expect(root.children().length).toBe(0);
});
});