-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lib): insource closest to support shadow dom
Closes #5
- Loading branch information
1 parent
0672959
commit b58f019
Showing
3 changed files
with
25 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,24 @@ | ||
export { | ||
default | ||
} from 'closest'; | ||
import matches from './matches'; | ||
|
||
/** | ||
* Closest | ||
* | ||
* @param {Element} el | ||
* @param {String} selector | ||
* @param {Boolean} checkYourSelf (optional) | ||
*/ | ||
export default function(element, selector, checkYourSelf) { | ||
var currentElem = checkYourSelf ? element : element.parentNode; | ||
|
||
while (currentElem && currentElem.nodeType !== document.DOCUMENT_NODE && | ||
currentElem.nodeType !== document.DOCUMENT_FRAGMENT_NODE) { | ||
|
||
if (matches(currentElem, selector)) { | ||
return currentElem; | ||
} | ||
|
||
currentElem = currentElem.parentNode; | ||
} | ||
|
||
return matches(currentElem, selector) ? currentElem : null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters