Created
January 30, 2010 19:43
-
-
Save rkatic/290689 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
;(function(jQuery){ | |
// This jQuery.filter version handles selectors and callbacks. | |
// | |
// Selector - ( elems, selector, [not] ) | |
// This is the original jQuery.filter signature with two first arguments swapped. | |
// | |
// Callback - ( elems, callback, [thisObject], [inv] ) | |
// This is the old jQuery.grep signature enhanced to support the ECMA-262 filter signature. | |
jQuery.filter = function( elems, filter, inv ) { | |
// Handle sellectors | |
if ( typeof filter === "string" ) { | |
if ( inv ) { | |
filter = ":not(" + filter + ")"; | |
} | |
return elems.length === 1 ? | |
jQuery.find.matchesSelector( elems[0], expr ) ? [ elems[0] ] : [] : | |
jQuery.find.matches( expr, elems ); | |
} | |
var ret = [], elem, thisObject; | |
if ( inv && inv !== true || arguments.length > 3 ) { | |
thisObject = inv; | |
inv = arguments[3]; | |
} | |
inv = !!inv; | |
for ( var i = 0, length = elems.length; i < length; i++ ) { | |
elem = elems[i]; | |
if ( inv !== filter.call( thisObject || elem, elem, i, elems ) ) { | |
ret.push( elem ); | |
} | |
} | |
return ret; | |
}; | |
// Make .grep() an alias of .filter(). | |
jQuery.grep = jQuery.filter; | |
})(jQuery); |
This file contains hidden or 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
;(function(jQuery){ | |
// This jQuery.filter version handles selectors and callbacks. | |
// | |
// Selector - ( selector, elems, [not] ) | |
// This is the original jQuery.filter signature. | |
// | |
// Callback - ( elems, callback, [thisObject], [inv] ) | |
// This is the old jQuery.grep signature enhanced to support the ECMA-262 filter signature. | |
jQuery.filter = function( a0, a1, inv ) { | |
// Handle ( selector, elems, not ) | |
if ( typeof a0 === "string" ) { | |
if ( inv ) { | |
a0 = ":not(" + a0 + ")"; | |
} | |
return a1.length === 1 ? | |
jQuery.find.matchesSelector( a1[0], a0 ) ? [ a1[0] ] : [] : | |
jQuery.find.matches( a0, a1 ); | |
} | |
// Handle ( elems, filter, [thisObject], [inv] ) | |
var ret = [], elem, thisObject; | |
if ( inv && inv !== true ) { | |
thisObject = inv; | |
inv = arguments[3]; | |
} | |
for ( var i = 0, length = a0.length; i < length; i++ ) { | |
elem = a0[i]; | |
if ( inv !== a1.call( thisObject || elem, elem, i, a0 ) ) { | |
ret.push( elem ); | |
} | |
} | |
return ret; | |
}; | |
// Make .grep() an alias of .filter(). | |
jQuery.grep = jQuery.filter; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment