From 56c00800c78d3d896fa6cb97ab97b974805152c4 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Thu, 31 Mar 2011 01:17:34 -0700 Subject: 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 --- src/jqLite.js | 4 ++-- test/jqLiteSpec.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/jqLite.js b/src/jqLite.js index 78fc1655..d16ce19e 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -371,8 +371,8 @@ forEach({ }, parent: function(element) { - // in IE it returns undefined, but we need differentiate it from functions which have no return - return element.parentNode || null; + var parent = element.parentNode; + return parent && parent.nodeType !== 11 ? parent : null; }, next: function(element) { diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index 346017f1..2fc670ce 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -323,11 +323,30 @@ describe('jqLite', function(){ }); }); describe('parent', function(){ + it('should return parent or an empty set when no parent', function(){ + var parent = jqLite('
abc
foo
'); + + fragment.appendChild(child[0]); + expect(child[0].parentNode).toBe(fragment); + expect(child.parent().length).toBe(0); + }); }); describe('next', function(){ it('should return next sibling', function(){ -- cgit v1.2.3