diff options
| author | Misko Hevery | 2011-06-08 14:50:27 -0700 |
|---|---|---|
| committer | Misko Hevery | 2011-06-08 15:21:33 -0700 |
| commit | 89e001b18a4f6d18caea1e9a3d015639feb4f1ee (patch) | |
| tree | 0b64c66137a4f7f7dbcb0f8e66b60b59e742396c | |
| parent | 4f2f3c9cbf345301ca8feac308878b7ac0d0a597 (diff) | |
| download | angular.js-89e001b18a4f6d18caea1e9a3d015639feb4f1ee.tar.bz2 | |
Added prepend() to jqLite
| -rw-r--r-- | CHANGELOG.md | 4 | ||||
| -rw-r--r-- | src/jqLite.js | 14 | ||||
| -rw-r--r-- | test/jqLiteSpec.js | 18 |
3 files changed, 36 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 25bffca4..5acb5832 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ <a name="0.9.17"><a/> # <angular/> 0.9.17 vegetable-reanimation (in progress) # +### New Features +- Added prepend() to jqLite + + ### Bug Fixes - Number filter would return incorrect value when fractional part had leading zeros. diff --git a/src/jqLite.js b/src/jqLite.js index 68cda632..a1203739 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -408,6 +408,20 @@ forEach({ }); }, + prepend: function(element, node) { + 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; + } + }); + } + }, + remove: function(element) { JQLiteDealoc(element); var parent = element.parentNode; diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index 5aec0cff..6794c4e0 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -380,6 +380,24 @@ describe('jqLite', function(){ }); }); + describe('prepend', function(){ + it('should prepend to empty', function(){ + var root = jqLite('<div>'); + expect(root.prepend('<span>abc</span>')).toEqual(root); + expect(root.html().toLowerCase()).toEqual('<span>abc</span>'); + }); + it('should prepend to content', function(){ + var root = jqLite('<div>text</div>'); + expect(root.prepend('<span>abc</span>')).toEqual(root); + expect(root.html().toLowerCase()).toEqual('<span>abc</span>text'); + }); + it('should prepend text to content', function(){ + var root = jqLite('<div>text</div>'); + expect(root.prepend('abc')).toEqual(root); + expect(root.html().toLowerCase()).toEqual('abctext'); + }); + }); + describe('remove', function(){ it('should remove', function(){ |
