Created
November 30, 2016 17:19
-
-
Save SvetlozarKalchev/c4c62fe9a66c19a114e4e18060b293fb to your computer and use it in GitHub Desktop.
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
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