From 63414b965397a9fd7d2f49e8dea4b848e0d6707e Mon Sep 17 00:00:00 2001 From: Joao Sa Date: Fri, 28 Jun 2013 00:53:17 -0300 Subject: [PATCH] fix(jqLite): prepend array in correct order Match jQuery behavior when prepending array into empty element --- src/jqLite.js | 7 +------ test/jqLiteSpec.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/jqLite.js b/src/jqLite.js index 57c12821d3fa..bf1802f9e498 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -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); }); } }, diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index 7412c8c44a11..6aafd1f85cb4 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -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('
'); + expect(root.prepend([a, b, c])).toBe(root); + expect(sortedHtml(root)). + toBe('
A
B
C
'); + }); + it('should prepend array to content in the right order', function() { + var root = jqLite('
text
'); + expect(root.prepend([a, b, c])).toBe(root); + expect(sortedHtml(root)). + toBe('
A
B
C
text
'); + }); });