Store last closer value to jQuery.lastCloser instead of using data API.

This commit is contained in:
rkatic 2009-11-08 00:04:08 +08:00 committed by John Resig
parent 3106039aa8
commit 0f03c7489f

View file

@ -52,19 +52,20 @@ jQuery.fn.extend({
},
closest: function( selector, context ) {
var pos = jQuery.expr.match.POS.test( selector ) ? jQuery(selector) : null,
closer = 0;
var pos = jQuery.expr.match.POS.test( selector ) ? jQuery(selector) : null;
return this.map(function(){
var cur = this;
var cur = this, closer = 0;
while ( cur && cur.ownerDocument && cur !== context ) {
if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selector) ) {
jQuery.data(cur, "closest", closer);
jQuery.lastCloser = closer;
return cur;
}
cur = cur.parentNode;
closer++;
}
jQuery.lastCloser = -1;
return null;
});
},