Skip to content

Commit 89e001b

Browse files
committed
Added prepend() to jqLite
1 parent 4f2f3c9 commit 89e001b

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<a name="0.9.17"><a/>
22
# <angular/> 0.9.17 vegetable-reanimation (in progress) #
33

4+
### New Features
5+
- Added prepend() to jqLite
6+
7+
48
### Bug Fixes
59
- Number filter would return incorrect value when fractional part had leading zeros.
610

src/jqLite.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,20 @@ forEach({
408408
});
409409
},
410410

411+
prepend: function(element, node) {
412+
if (element.nodeType === 1) {
413+
var index = element.firstChild;
414+
forEach(new JQLite(node), function(child){
415+
if (index) {
416+
element.insertBefore(child, index);
417+
} else {
418+
element.appendChild(child);
419+
index = child;
420+
}
421+
});
422+
}
423+
},
424+
411425
remove: function(element) {
412426
JQLiteDealoc(element);
413427
var parent = element.parentNode;

test/jqLiteSpec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,24 @@ describe('jqLite', function(){
380380
});
381381
});
382382

383+
describe('prepend', function(){
384+
it('should prepend to empty', function(){
385+
var root = jqLite('<div>');
386+
expect(root.prepend('<span>abc</span>')).toEqual(root);
387+
expect(root.html().toLowerCase()).toEqual('<span>abc</span>');
388+
});
389+
it('should prepend to content', function(){
390+
var root = jqLite('<div>text</div>');
391+
expect(root.prepend('<span>abc</span>')).toEqual(root);
392+
expect(root.html().toLowerCase()).toEqual('<span>abc</span>text');
393+
});
394+
it('should prepend text to content', function(){
395+
var root = jqLite('<div>text</div>');
396+
expect(root.prepend('abc')).toEqual(root);
397+
expect(root.html().toLowerCase()).toEqual('abctext');
398+
});
399+
});
400+
383401

384402
describe('remove', function(){
385403
it('should remove', function(){

0 commit comments

Comments
 (0)