aboutsummaryrefslogtreecommitdiffstats
path: root/src/traversing.js
diff options
context:
space:
mode:
authorjeresig <jeresig@gmail.com>2010-09-27 15:45:02 -0400
committerjeresig <jeresig@gmail.com>2010-09-27 15:45:02 -0400
commit8c41325a081f4009aa94748b9b6045e50a78422e (patch)
tree0089549ab4ffe6894616d5c5ece5d3b783bcf26c /src/traversing.js
parente63fa8beb8e285fe19fc0a1557045b80e3c63c66 (diff)
parenta2bd8a53f3a750606abea9bbb6ee2302437d42f3 (diff)
downloadjquery-8c41325a081f4009aa94748b9b6045e50a78422e.tar.gz
jquery-8c41325a081f4009aa94748b9b6045e50a78422e.zip
Merge branch 'closestbug-6700' of http://github.com/ajpiano/jquery into ajpiano-closestbug-6700
Diffstat (limited to 'src/traversing.js')
-rw-r--r--src/traversing.js14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/traversing.js b/src/traversing.js
index 59110b096..f7dde44ec 100644
--- a/src/traversing.js
+++ b/src/traversing.js
@@ -55,9 +55,10 @@ jQuery.fn.extend({
},
closest: function( selectors, context ) {
+ var ret;
if ( jQuery.isArray( selectors ) ) {
- var ret = [], cur = this[0], match, matches = {}, selector, level = 1;
-
+ var cur = this[0], match, matches = {}, selector, level = 1;
+ ret = [];
if ( cur && selectors.length ) {
for ( var i = 0, l = selectors.length; i < l; i++ ) {
selector = selectors[i];
@@ -82,13 +83,12 @@ jQuery.fn.extend({
}
}
- return ret;
+ return ret.length > 1 ? jQuery.unique(ret) : ret;
}
var pos = jQuery.expr.match.POS.test( selectors ) ?
jQuery( selectors, context || this.context ) : null;
-
- return this.map(function( i, cur ) {
+ ret = jQuery.map(this.get(),function( cur,i ) {
while ( cur && cur.ownerDocument && cur !== context ) {
if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selectors) ) {
return cur;
@@ -97,6 +97,10 @@ jQuery.fn.extend({
}
return null;
});
+
+ ret = ret.length > 1 ? jQuery.unique(ret) : ret;
+
+ return this.pushStack( ret, "closest", selectors );
},
// Determine the position of an element within