mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-27 23:14:00 +00:00
fix jqLite#parent to be compatible with jQuery
our original implementation doesn't work with document fragments on IE - tests were added to cover missing cases
This commit is contained in:
parent
15ec78f5ef
commit
56c00800c7
2 changed files with 21 additions and 2 deletions
|
|
@ -371,8 +371,8 @@ forEach({
|
||||||
},
|
},
|
||||||
|
|
||||||
parent: function(element) {
|
parent: function(element) {
|
||||||
// in IE it returns undefined, but we need differentiate it from functions which have no return
|
var parent = element.parentNode;
|
||||||
return element.parentNode || null;
|
return parent && parent.nodeType !== 11 ? parent : null;
|
||||||
},
|
},
|
||||||
|
|
||||||
next: function(element) {
|
next: function(element) {
|
||||||
|
|
|
||||||
|
|
@ -323,11 +323,30 @@ describe('jqLite', function(){
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('parent', function(){
|
describe('parent', function(){
|
||||||
|
it('should return parent or an empty set when no parent', function(){
|
||||||
|
var parent = jqLite('<div><p>abc</p></div>'),
|
||||||
|
child = parent.find('p');
|
||||||
|
|
||||||
|
expect(parent.parent()).toBeTruthy();
|
||||||
|
expect(parent.parent().length).toEqual(0);
|
||||||
|
|
||||||
|
expect(child.parent().length).toBe(1);
|
||||||
|
expect(child.parent()[0]).toBe(parent[0]);
|
||||||
|
});
|
||||||
it('should return empty set when no parent', function(){
|
it('should return empty set when no parent', function(){
|
||||||
var element = jqLite('<div>abc</div>');
|
var element = jqLite('<div>abc</div>');
|
||||||
expect(element.parent()).toBeTruthy();
|
expect(element.parent()).toBeTruthy();
|
||||||
expect(element.parent().length).toEqual(0);
|
expect(element.parent().length).toEqual(0);
|
||||||
});
|
});
|
||||||
|
it('should return empty jqLite object when parent is a document fragment', function() {
|
||||||
|
//this is quite unfortunate but jQuery 1.5.1 behaves this way
|
||||||
|
var fragment = document.createDocumentFragment(),
|
||||||
|
child = jqLite('<p>foo</p>');
|
||||||
|
|
||||||
|
fragment.appendChild(child[0]);
|
||||||
|
expect(child[0].parentNode).toBe(fragment);
|
||||||
|
expect(child.parent().length).toBe(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('next', function(){
|
describe('next', function(){
|
||||||
it('should return next sibling', function(){
|
it('should return next sibling', function(){
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue