From 494ef263e9eeaf72eff42bbba05ef861625b5108 Mon Sep 17 00:00:00 2001 From: Keyamoon Date: Thu, 20 Dec 2012 03:18:47 +0330 Subject: [PATCH 1/3] test(jqLite): Improve the test for next() --- test/jqLiteSpec.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index 01f9b9ae8138..2c6e9d01e3a2 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -1,4 +1,3 @@ - describe('jqLite', function() { var scope, a, b, c; @@ -1068,7 +1067,7 @@ describe('jqLite', function() { describe('next', function() { it('should return next sibling', function() { - var element = jqLite('
bi
'); + var element = jqLite('
bTextNodei
'); var b = element.find('b'); var i = element.find('i'); expect(b.next()).toJqEqual([i]); From 9f770ffb633a45f1d5a3dad690fe42eff0230072 Mon Sep 17 00:00:00 2001 From: Keyamoon Date: Thu, 20 Dec 2012 03:48:22 +0330 Subject: [PATCH 2/3] fix(jqLite): make next() ignore text nodes next() is supposed to return the next sibling element and it should ignore text nodes. To achieve this, nextElementSibling() should be used instead of nextSibling(). --- src/jqLite.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jqLite.js b/src/jqLite.js index 8305f0c30f2c..de3471262d42 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -718,7 +718,7 @@ forEach({ }, next: function(element) { - return element.nextSibling; + return element.nextElementSibling; }, find: function(element, selector) { From da0c41b47425bb2f21e4d3ee4ad61bd3097630e2 Mon Sep 17 00:00:00 2001 From: Keyamoon Date: Thu, 20 Dec 2012 15:11:13 +0330 Subject: [PATCH 3/3] fix(jqLite): make next() work in older browsers nextElementSibling is not supported in IE8 but nextSibling is. To make next() work in IE8, we can check the nodeType to see whether it's a DOM element or not. If it's not an element, we will move to the next sibling node using nextSibling. --- src/jqLite.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/jqLite.js b/src/jqLite.js index de3471262d42..6c493dc887af 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -718,7 +718,14 @@ forEach({ }, next: function(element) { - return element.nextElementSibling; + if (element.nextElementSibling) { + return element.nextElementSibling; + } + var elm = element.nextSibling; + while (elm != null && elm.nodeType !== 1) { + elm = elm.nextSibling; + } + return elm; }, find: function(element, selector) {