diff options
| author | Joao Sa | 2013-06-28 00:53:17 -0300 |
|---|---|---|
| committer | Pete Bacon Darwin | 2013-07-03 20:25:28 +0100 |
| commit | 63414b965397a9fd7d2f49e8dea4b848e0d6707e (patch) | |
| tree | f4fd2203cf658e8c76341789b9dc4c45136b2e2a | |
| parent | 5f24bb0267418aa194b46c64a7dfcf07484b836d (diff) | |
| download | angular.js-63414b965397a9fd7d2f49e8dea4b848e0d6707e.tar.bz2 | |
fix(jqLite): prepend array in correct order
Match jQuery behavior when prepending array into empty element
| -rw-r--r-- | src/jqLite.js | 7 | ||||
| -rw-r--r-- | test/jqLiteSpec.js | 12 |
2 files changed, 13 insertions, 6 deletions
diff --git a/src/jqLite.js b/src/jqLite.js index 57c12821..bf1802f9 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 7412c8c4..6aafd1f8 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('<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>'); + }); }); |
