scratch – Diff between revs 58 and 125
?pathlinks?
Rev 58 | Rev 125 | |||
---|---|---|---|---|
Line 1... | Line 1... | |||
1 | define( [ |
1 | define([ |
|
2 | "./core", |
2 | "./core", |
|
3 | "./var/indexOf", |
3 | "./var/indexOf", |
|
4 | "./traversing/var/dir", |
- | ||
5 | "./traversing/var/siblings", |
- | ||
6 | "./traversing/var/rneedsContext", |
4 | "./traversing/var/rneedsContext", |
|
7 | "./core/init", |
5 | "./core/init", |
|
8 | "./traversing/findFilter", |
6 | "./traversing/findFilter", |
|
9 | "./selector" |
7 | "./selector" |
|
10 | ], function( jQuery, indexOf, dir, siblings, rneedsContext ) { |
8 | ], function( jQuery, indexOf, rneedsContext ) { |
|
11 | |
- | ||
12 | "use strict"; |
- | ||
Line 13... | Line 9... | |||
13 | |
9 | |
|
14 | var rparentsprev = /^(?:parents|prev(?:Until|All))/, |
- | ||
15 | |
10 | var rparentsprev = /^(?:parents|prev(?:Until|All))/, |
|
16 | // Methods guaranteed to produce a unique set when starting from a unique set |
11 | // Methods guaranteed to produce a unique set when starting from a unique set |
|
17 | guaranteedUnique = { |
12 | guaranteedUnique = { |
|
18 | children: true, |
13 | children: true, |
|
19 | contents: true, |
14 | contents: true, |
|
20 | next: true, |
15 | next: true, |
|
21 | prev: true |
16 | prev: true |
|
Line -... | Line 17... | |||
- | 17 | }; |
||
- | 18 | |
||
- | 19 | jQuery.extend({ |
||
- | 20 | dir: function( elem, dir, until ) { |
||
- | 21 | var matched = [], |
||
- | 22 | truncate = until !== undefined; |
||
- | 23 | |
||
- | 24 | while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) { |
||
- | 25 | if ( elem.nodeType === 1 ) { |
||
- | 26 | if ( truncate && jQuery( elem ).is( until ) ) { |
||
- | 27 | break; |
||
- | 28 | } |
||
- | 29 | matched.push( elem ); |
||
- | 30 | } |
||
- | 31 | } |
||
- | 32 | return matched; |
||
- | 33 | }, |
||
- | 34 | |
||
- | 35 | sibling: function( n, elem ) { |
||
- | 36 | var matched = []; |
||
- | 37 | |
||
- | 38 | for ( ; n; n = n.nextSibling ) { |
||
- | 39 | if ( n.nodeType === 1 && n !== elem ) { |
||
- | 40 | matched.push( n ); |
||
- | 41 | } |
||
- | 42 | } |
||
- | 43 | |
||
- | 44 | return matched; |
||
- | 45 | } |
||
22 | }; |
46 | }); |
|
23 | |
47 | |
|
24 | jQuery.fn.extend( { |
48 | jQuery.fn.extend({ |
|
25 | has: function( target ) { |
49 | has: function( target ) { |
|
Line 26... | Line 50... | |||
26 | var targets = jQuery( target, this ), |
50 | var targets = jQuery( target, this ), |
|
27 | l = targets.length; |
51 | l = targets.length; |
|
28 | |
52 | |
|
29 | return this.filter( function() { |
53 | return this.filter(function() { |
|
30 | var i = 0; |
54 | var i = 0; |
|
31 | for ( ; i < l; i++ ) { |
55 | for ( ; i < l; i++ ) { |
|
32 | if ( jQuery.contains( this, targets[ i ] ) ) { |
56 | if ( jQuery.contains( this, targets[i] ) ) { |
|
33 | return true; |
57 | return true; |
|
34 | } |
58 | } |
|
Line 35... | Line 59... | |||
35 | } |
59 | } |
|
36 | } ); |
60 | }); |
|
37 | }, |
61 | }, |
|
38 | |
62 | |
|
39 | closest: function( selectors, context ) { |
63 | closest: function( selectors, context ) { |
|
40 | var cur, |
64 | var cur, |
|
- | 65 | i = 0, |
||
- | 66 | l = this.length, |
||
41 | i = 0, |
67 | matched = [], |
|
- | 68 | pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ? |
||
42 | l = this.length, |
69 | jQuery( selectors, context || this.context ) : |
|
- | 70 | 0; |
||
43 | matched = [], |
71 | |
|
- | 72 | for ( ; i < l; i++ ) { |
||
- | 73 | for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) { |
||
- | 74 | // Always skip document fragments |
||
44 | targets = typeof selectors !== "string" && jQuery( selectors ); |
75 | if ( cur.nodeType < 11 && (pos ? |
|
45 | |
76 | pos.index(cur) > -1 : |
|
Line 46... | Line -... | |||
46 | // Positional selectors never match, since there's no _selection_ context |
- | ||
47 | if ( !rneedsContext.test( selectors ) ) { |
- | ||
48 | for ( ; i < l; i++ ) { |
- | ||
49 | for ( cur = this[ i ]; cur && cur !== context; cur = cur.parentNode ) { |
- | ||
50 | |
- | ||
51 | // Always skip document fragments |
- | ||
52 | if ( cur.nodeType < 11 && ( targets ? |
- | ||
53 | targets.index( cur ) > -1 : |
- | ||
54 | |
77 | |
|
55 | // Don't pass non-elements to Sizzle |
78 | // Don't pass non-elements to Sizzle |
|
56 | cur.nodeType === 1 && |
- | ||
57 | jQuery.find.matchesSelector( cur, selectors ) ) ) { |
79 | cur.nodeType === 1 && |
|
58 | |
80 | jQuery.find.matchesSelector(cur, selectors)) ) { |
|
59 | matched.push( cur ); |
81 | |
|
Line 60... | Line 82... | |||
60 | break; |
82 | matched.push( cur ); |
|
61 | } |
83 | break; |
|
Line 62... | Line 84... | |||
62 | } |
84 | } |
|
63 | } |
85 | } |
|
Line 87... | Line 109... | |||
87 | ); |
109 | ); |
|
88 | }, |
110 | }, |
|
Line 89... | Line 111... | |||
89 | |
111 | |
|
90 | add: function( selector, context ) { |
112 | add: function( selector, context ) { |
|
91 | return this.pushStack( |
113 | return this.pushStack( |
|
92 | jQuery.uniqueSort( |
114 | jQuery.unique( |
|
93 | jQuery.merge( this.get(), jQuery( selector, context ) ) |
115 | jQuery.merge( this.get(), jQuery( selector, context ) ) |
|
94 | ) |
116 | ) |
|
95 | ); |
117 | ); |
|
Line 96... | Line 118... | |||
96 | }, |
118 | }, |
|
97 | |
119 | |
|
98 | addBack: function( selector ) { |
120 | addBack: function( selector ) { |
|
99 | return this.add( selector == null ? |
121 | return this.add( selector == null ? |
|
100 | this.prevObject : this.prevObject.filter( selector ) |
122 | this.prevObject : this.prevObject.filter(selector) |
|
101 | ); |
123 | ); |
|
Line 102... | Line 124... | |||
102 | } |
124 | } |
|
103 | } ); |
125 | }); |
|
104 | |
126 | |
|
105 | function sibling( cur, dir ) { |
127 | function sibling( cur, dir ) { |
|
Line 106... | Line 128... | |||
106 | while ( ( cur = cur[ dir ] ) && cur.nodeType !== 1 ) {} |
128 | while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {} |
|
107 | return cur; |
129 | return cur; |
|
108 | } |
130 | } |
|
109 | |
131 | |
|
110 | jQuery.each( { |
132 | jQuery.each({ |
|
111 | parent: function( elem ) { |
133 | parent: function( elem ) { |
|
112 | var parent = elem.parentNode; |
134 | var parent = elem.parentNode; |
|
113 | return parent && parent.nodeType !== 11 ? parent : null; |
135 | return parent && parent.nodeType !== 11 ? parent : null; |
|
114 | }, |
136 | }, |
|
115 | parents: function( elem ) { |
137 | parents: function( elem ) { |
|
116 | return dir( elem, "parentNode" ); |
138 | return jQuery.dir( elem, "parentNode" ); |
|
117 | }, |
139 | }, |
|
118 | parentsUntil: function( elem, i, until ) { |
140 | parentsUntil: function( elem, i, until ) { |
|
119 | return dir( elem, "parentNode", until ); |
141 | return jQuery.dir( elem, "parentNode", until ); |
|
120 | }, |
142 | }, |
|
121 | next: function( elem ) { |
143 | next: function( elem ) { |
|
122 | return sibling( elem, "nextSibling" ); |
144 | return sibling( elem, "nextSibling" ); |
|
123 | }, |
145 | }, |
|
124 | prev: function( elem ) { |
146 | prev: function( elem ) { |
|
125 | return sibling( elem, "previousSibling" ); |
147 | return sibling( elem, "previousSibling" ); |
|
126 | }, |
148 | }, |
|
127 | nextAll: function( elem ) { |
149 | nextAll: function( elem ) { |
|
128 | return dir( elem, "nextSibling" ); |
150 | return jQuery.dir( elem, "nextSibling" ); |
|
129 | }, |
151 | }, |
|
130 | prevAll: function( elem ) { |
152 | prevAll: function( elem ) { |
|
131 | return dir( elem, "previousSibling" ); |
153 | return jQuery.dir( elem, "previousSibling" ); |
|
132 | }, |
154 | }, |
|
133 | nextUntil: function( elem, i, until ) { |
155 | nextUntil: function( elem, i, until ) { |
|
134 | return dir( elem, "nextSibling", until ); |
156 | return jQuery.dir( elem, "nextSibling", until ); |
|
135 | }, |
157 | }, |
|
136 | prevUntil: function( elem, i, until ) { |
158 | prevUntil: function( elem, i, until ) { |
|
137 | return dir( elem, "previousSibling", until ); |
159 | return jQuery.dir( elem, "previousSibling", until ); |
|
138 | }, |
160 | }, |
|
139 | siblings: function( elem ) { |
161 | siblings: function( elem ) { |
|
140 | return siblings( ( elem.parentNode || {} ).firstChild, elem ); |
162 | return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem ); |
|
141 | }, |
163 | }, |
|
142 | children: function( elem ) { |
164 | children: function( elem ) { |
|
143 | return siblings( elem.firstChild ); |
165 | return jQuery.sibling( elem.firstChild ); |
|
144 | }, |
166 | }, |
|
Line 156... | Line 178... | |||
156 | if ( selector && typeof selector === "string" ) { |
178 | if ( selector && typeof selector === "string" ) { |
|
157 | matched = jQuery.filter( selector, matched ); |
179 | matched = jQuery.filter( selector, matched ); |
|
158 | } |
180 | } |
|
Line 159... | Line 181... | |||
159 | |
181 | |
|
160 | if ( this.length > 1 ) { |
- | ||
161 | |
182 | if ( this.length > 1 ) { |
|
162 | // Remove duplicates |
183 | // Remove duplicates |
|
163 | if ( !guaranteedUnique[ name ] ) { |
184 | if ( !guaranteedUnique[ name ] ) { |
|
164 | jQuery.uniqueSort( matched ); |
185 | jQuery.unique( matched ); |
|
Line 165... | Line 186... | |||
165 | } |
186 | } |
|
166 | |
187 | |
|
167 | // Reverse order for parents* and prev-derivatives |
188 | // Reverse order for parents* and prev-derivatives |
|
168 | if ( rparentsprev.test( name ) ) { |
189 | if ( rparentsprev.test( name ) ) { |
|
169 | matched.reverse(); |
190 | matched.reverse(); |
|
Line 170... | Line 191... | |||
170 | } |
191 | } |
|
171 | } |
192 | } |
|
172 | |
193 | |
|
Line 173... | Line 194... | |||
173 | return this.pushStack( matched ); |
194 | return this.pushStack( matched ); |
|
174 | }; |
195 | }; |