Skip to content

Instantly share code, notes, and snippets.

@SvetlozarKalchev
Created November 30, 2016 17:19
Show Gist options
  • Save SvetlozarKalchev/c4c62fe9a66c19a114e4e18060b293fb to your computer and use it in GitHub Desktop.
Save SvetlozarKalchev/c4c62fe9a66c19a114e4e18060b293fb to your computer and use it in GitHub Desktop.
define( [
"../../core"
], function( jQuery ) {
"use strict";
return function( elem, dir, until ) {
var matched = [],
truncate = until !== undefined;
// elem[dir] is DOMElement.parentNodes in this case.
// This code goes through all parent Nodes and only pushed the node in the collection if it's a DOM node.
while ( ( elem = elem[ dir ] ) && elem.nodeType !== 9 ) {
if ( elem.nodeType === 1 ) {
if ( truncate && jQuery( elem ).is( until ) ) {
break;
}
matched.push( elem );
}
}
return matched;
};
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment