scratch – Diff between revs 58 and 125
?pathlinks?
Rev 58 | Rev 125 | |||
---|---|---|---|---|
Line 3... | Line 3... | |||
3 | "../var/indexOf", |
3 | "../var/indexOf", |
|
4 | "./var/rneedsContext", |
4 | "./var/rneedsContext", |
|
5 | "../selector" |
5 | "../selector" |
|
6 | ], function( jQuery, indexOf, rneedsContext ) { |
6 | ], function( jQuery, indexOf, rneedsContext ) { |
|
Line 7... | Line -... | |||
7 | |
- | ||
8 | "use strict"; |
- | ||
9 | |
7 | |
|
Line 10... | Line 8... | |||
10 | var risSimple = /^.[^:#\[\.,]*$/; |
8 | var risSimple = /^.[^:#\[\.,]*$/; |
|
11 | |
9 | |
|
12 | // Implement the identical functionality for filter and not |
10 | // Implement the identical functionality for filter and not |
|
13 | function winnow( elements, qualifier, not ) { |
11 | function winnow( elements, qualifier, not ) { |
|
- | 12 | if ( jQuery.isFunction( qualifier ) ) { |
||
14 | if ( jQuery.isFunction( qualifier ) ) { |
13 | return jQuery.grep( elements, function( elem, i ) { |
|
15 | return jQuery.grep( elements, function( elem, i ) { |
14 | /* jshint -W018 */ |
|
- | 15 | return !!qualifier.call( elem, i, elem ) !== not; |
||
16 | return !!qualifier.call( elem, i, elem ) !== not; |
16 | }); |
|
Line 17... | Line -... | |||
17 | } ); |
- | ||
18 | } |
17 | |
|
19 | |
18 | } |
|
20 | // Single element |
19 | |
|
21 | if ( qualifier.nodeType ) { |
20 | if ( qualifier.nodeType ) { |
|
22 | return jQuery.grep( elements, function( elem ) { |
- | ||
Line 23... | Line -... | |||
23 | return ( elem === qualifier ) !== not; |
- | ||
24 | } ); |
- | ||
25 | } |
- | ||
26 | |
- | ||
27 | // Arraylike of elements (jQuery, arguments, Array) |
- | ||
28 | if ( typeof qualifier !== "string" ) { |
21 | return jQuery.grep( elements, function( elem ) { |
|
Line 29... | Line 22... | |||
29 | return jQuery.grep( elements, function( elem ) { |
22 | return ( elem === qualifier ) !== not; |
|
30 | return ( indexOf.call( qualifier, elem ) > -1 ) !== not; |
23 | }); |
|
31 | } ); |
24 | |
|
32 | } |
25 | } |
|
Line 33... | Line -... | |||
33 | |
- | ||
34 | // Simple selector that can be filtered directly, removing non-Elements |
26 | |
|
- | 27 | if ( typeof qualifier === "string" ) { |
||
- | 28 | if ( risSimple.test( qualifier ) ) { |
||
35 | if ( risSimple.test( qualifier ) ) { |
29 | return jQuery.filter( qualifier, elements, not ); |
|
36 | return jQuery.filter( qualifier, elements, not ); |
30 | } |
|
37 | } |
31 | |
|
38 | |
32 | qualifier = jQuery.filter( qualifier, elements ); |
|
Line 39... | Line 33... | |||
39 | // Complex selector, compare the two sets, removing non-Elements |
33 | } |
|
40 | qualifier = jQuery.filter( qualifier, elements ); |
34 | |
|
Line 41... | Line 35... | |||
41 | return jQuery.grep( elements, function( elem ) { |
35 | return jQuery.grep( elements, function( elem ) { |
|
42 | return ( indexOf.call( qualifier, elem ) > -1 ) !== not && elem.nodeType === 1; |
36 | return ( indexOf.call( qualifier, elem ) >= 0 ) !== not; |
|
43 | } ); |
37 | }); |
|
Line 44... | Line 38... | |||
44 | } |
38 | } |
|
45 | |
39 | |
|
46 | jQuery.filter = function( expr, elems, not ) { |
- | ||
47 | var elem = elems[ 0 ]; |
- | ||
48 | |
40 | jQuery.filter = function( expr, elems, not ) { |
|
49 | if ( not ) { |
41 | var elem = elems[ 0 ]; |
|
50 | expr = ":not(" + expr + ")"; |
42 | |
|
51 | } |
43 | if ( not ) { |
|
Line 52... | Line 44... | |||
52 | |
44 | expr = ":not(" + expr + ")"; |
|
53 | if ( elems.length === 1 && elem.nodeType === 1 ) { |
45 | } |
|
54 | return jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : []; |
46 | |
|
55 | } |
47 | return elems.length === 1 && elem.nodeType === 1 ? |
|
- | 48 | jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] : |
||
56 | |
49 | jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) { |
|
Line 57... | Line 50... | |||
57 | return jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) { |
50 | return elem.nodeType === 1; |
|
58 | return elem.nodeType === 1; |
51 | })); |
|
59 | } ) ); |
52 | }; |
|
Line 73... | Line 66... | |||
73 | } |
66 | } |
|
74 | } |
67 | } |
|
75 | } ) ); |
68 | }) ); |
|
76 | } |
69 | } |
|
Line 77... | Line -... | |||
77 | |
- | ||
78 | ret = this.pushStack( [] ); |
- | ||
79 | |
70 | |
|
80 | for ( i = 0; i < len; i++ ) { |
71 | for ( i = 0; i < len; i++ ) { |
|
81 | jQuery.find( selector, self[ i ], ret ); |
72 | jQuery.find( selector, self[ i ], ret ); |
|
Line -... | Line 73... | |||
- | 73 | } |
||
82 | } |
74 | |
|
- | 75 | // Needed because $( selector, context ) becomes $( context ).find( selector ) |
||
- | 76 | ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret ); |
||
83 | |
77 | ret.selector = this.selector ? this.selector + " " + selector : selector; |
|
84 | return len > 1 ? jQuery.uniqueSort( ret ) : ret; |
78 | return ret; |
|
85 | }, |
79 | }, |
|
86 | filter: function( selector ) { |
80 | filter: function( selector ) { |
|
87 | return this.pushStack( winnow( this, selector || [], false ) ); |
81 | return this.pushStack( winnow(this, selector || [], false) ); |