Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
fix(contains): fix contains method
Browse files Browse the repository at this point in the history
  • Loading branch information
vvo committed Jun 20, 2017
1 parent ce9575b commit d2c38db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
34 changes: 17 additions & 17 deletions in-viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

This comment has been minimized.

Copy link
@tzi

tzi Jun 20, 2017

Collaborator

👍 It's really more readable!

}

function createInViewport(container, debounceValue, failsafe) {
Expand Down
2 changes: 1 addition & 1 deletion test/no-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ describe('without using callbacks', function() {
assert.strictEqual(inViewport(test), false);
});
});
});
});

0 comments on commit d2c38db

Please sign in to comment.