src/node/js/node.js
function(selector) {

	var allMatches = localnwt.all(selector),
		testNode = this._node,
		ancestor = null,
		maxDepth = 0;

	if( allMatches.size() == 0 ) {
		return null;
	}

	while( true ) {

		// Iterate through all matches for each parent, and exit as soon as we have a match
		// Pretty bad performance, but super small. TODO: Omtimize
		allMatches.each(function (el) {
			if (el._node == testNode) {
				ancestor = el;
			}
		});

		var parentNode = testNode.parentNode;

		if( ancestor || !parentNode) { break; }
		testNode = parentNode;
	}

	if( ancestor ) {
		return ancestor;
	} else {
		return null;
	}
}
function(selector) {

	var allMatches = localnwt.all(selector),
		testNode = this._node,
		ancestor = null,
		maxDepth = 0;

	if( allMatches.size() == 0 ) {
		return null;
	}

	while( true ) {

		// Iterate through all matches for each parent, and exit as soon as we have a match
		// Pretty bad performance, but super small. TODO: Omtimize
		allMatches.each(function (el) {
			if (el._node == testNode) {
				ancestor = el;
			}
		});

		var parentNode = testNode.parentNode;

		if( ancestor || !parentNode) { break; }
		testNode = parentNode;
	}

	if( ancestor ) {
		return ancestor;
	} else {
		return null;
	}
}
function ( selector ) { var allMatches = localnwt . all ( selector ) , testNode = this . _node , ancestor = null , maxDepth = 0 ; if ( allMatches . size ( ) == 0 ) { return null ; } while ( true ) { // Iterate through all matches for each parent, and exit as soon as we have a match // Pretty bad performance, but super small. TODO: Omtimize allMatches . each ( function ( el ) { if ( el . _node == testNode ) { ancestor = el ; } } ) ; var parentNode = testNode . parentNode ; if ( ancestor || ! parentNode ) { break ; } testNode = parentNode ; } if ( ancestor ) { return ancestor ; } else { return null ; } }
Returns the ancestor that matches the css selector
@param string CSS Selector
Returns the ancestor that matches the css selector