Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix(jqLite): prepend array in correct order
Browse files Browse the repository at this point in the history
Match jQuery behavior when prepending array into empty element
  • Loading branch information
joaomsa authored and petebacondarwin committed Jul 3, 2013
1 parent 5f24bb0 commit 63414b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 1 addition & 6 deletions src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,12 +689,7 @@ forEach({
if (element.nodeType === 1) {
var index = element.firstChild;
forEach(new JQLite(node), function(child){
if (index) {
element.insertBefore(child, index);
} else {
element.appendChild(child);
index = child;
}
element.insertBefore(child, index);
});
}
},
Expand Down
12 changes: 12 additions & 0 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,18 @@ describe('jqLite', function() {
expect(root.prepend('abc')).toEqual(root);
expect(root.html().toLowerCase()).toEqual('abctext');
});
it('should prepend array to empty in the right order', function() {
var root = jqLite('<div>');
expect(root.prepend([a, b, c])).toBe(root);
expect(sortedHtml(root)).
toBe('<div><div>A</div><div>B</div><div>C</div></div>');
});
it('should prepend array to content in the right order', function() {
var root = jqLite('<div>text</div>');
expect(root.prepend([a, b, c])).toBe(root);
expect(sortedHtml(root)).
toBe('<div><div>A</div><div>B</div><div>C</div>text</div>');
});
});


Expand Down

0 comments on commit 63414b9

Please sign in to comment.