From ce9575b37bec1dd0e550f422ff1d0ed22eb8b0f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Moreira?= Date: Tue, 20 Jun 2017 09:38:45 +0100 Subject: [PATCH 1/2] If element height is 0, return it instead of `false` --- in-viewport.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/in-viewport.js b/in-viewport.js index e2a8d8e..5fba5b2 100644 --- a/in-viewport.js +++ b/in-viewport.js @@ -148,12 +148,6 @@ function createInViewport(container, debounceValue, failsafe) { return false; } - // Check if the element is visible - // https://github.com/jquery/jquery/blob/740e190223d19a114d5373758127285d14d6b71e/src/css/hiddenVisibleSelectors.js - if (!elt.offsetWidth || !elt.offsetHeight) { - return false; - } - var eltRect = elt.getBoundingClientRect(); var viewport = {}; From d2c38db4288fde41e0fa6060467fe98e48a19f6e Mon Sep 17 00:00:00 2001 From: vvo Date: Tue, 20 Jun 2017 17:24:08 +0200 Subject: [PATCH 2/2] fix(contains): fix contains method --- in-viewport.js | 34 +++++++++++++++++----------------- test/no-watch.js | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/in-viewport.js b/in-viewport.js index 5fba5b2..c461105 100644 --- a/in-viewport.js +++ b/in-viewport.js @@ -61,26 +61,26 @@ function debounce(func, wait, immediate) { } // https://github.com/jquery/sizzle/blob/3136f48b90e3edc84cbaaa6f6f7734ef03775a07/sizzle.js#L708 -var contains = function() { +var contains = function(a, b) { if (!global.document) { return true; } - return global.document.documentElement.compareDocumentPosition ? - function (a, b) { - return !!(a.compareDocumentPosition(b) & 16); - } : - global.document.documentElement.contains ? - function (a, b) { - return a !== b && ( a.contains ? a.contains(b) : false ); - } : - function (a, b) { - while (b = b.parentNode) { - if (b === a) { - return true; - } - } - return false; - }; + + if (global.document.documentElement.compareDocumentPosition) { + return !!(a.compareDocumentPosition(b) & 16); + } + + if (global.document.documentElement.contains) { + return a !== b && ( a.contains ? a.contains(b) : false ); + } + + while (b = b.parentNode) { + if (b === a) { + return true; + } + } + + return false; } function createInViewport(container, debounceValue, failsafe) { diff --git a/test/no-watch.js b/test/no-watch.js index 456f769..2c2080b 100644 --- a/test/no-watch.js +++ b/test/no-watch.js @@ -45,4 +45,4 @@ describe('without using callbacks', function() { assert.strictEqual(inViewport(test), false); }); }); -}); \ No newline at end of file +});