scratch – Blame information for rev 58
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
58 | office | 1 | define( [ |
2 | "./core", |
||
3 | "./var/indexOf", |
||
4 | "./traversing/var/dir", |
||
5 | "./traversing/var/siblings", |
||
6 | "./traversing/var/rneedsContext", |
||
7 | "./core/init", |
||
8 | "./traversing/findFilter", |
||
9 | "./selector" |
||
10 | ], function( jQuery, indexOf, dir, siblings, rneedsContext ) { |
||
11 | |||
12 | "use strict"; |
||
13 | |||
14 | var rparentsprev = /^(?:parents|prev(?:Until|All))/, |
||
15 | |||
16 | // Methods guaranteed to produce a unique set when starting from a unique set |
||
17 | guaranteedUnique = { |
||
18 | children: true, |
||
19 | contents: true, |
||
20 | next: true, |
||
21 | prev: true |
||
22 | }; |
||
23 | |||
24 | jQuery.fn.extend( { |
||
25 | has: function( target ) { |
||
26 | var targets = jQuery( target, this ), |
||
27 | l = targets.length; |
||
28 | |||
29 | return this.filter( function() { |
||
30 | var i = 0; |
||
31 | for ( ; i < l; i++ ) { |
||
32 | if ( jQuery.contains( this, targets[ i ] ) ) { |
||
33 | return true; |
||
34 | } |
||
35 | } |
||
36 | } ); |
||
37 | }, |
||
38 | |||
39 | closest: function( selectors, context ) { |
||
40 | var cur, |
||
41 | i = 0, |
||
42 | l = this.length, |
||
43 | matched = [], |
||
44 | targets = typeof selectors !== "string" && jQuery( selectors ); |
||
45 | |||
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 | |||
55 | // Don't pass non-elements to Sizzle |
||
56 | cur.nodeType === 1 && |
||
57 | jQuery.find.matchesSelector( cur, selectors ) ) ) { |
||
58 | |||
59 | matched.push( cur ); |
||
60 | break; |
||
61 | } |
||
62 | } |
||
63 | } |
||
64 | } |
||
65 | |||
66 | return this.pushStack( matched.length > 1 ? jQuery.uniqueSort( matched ) : matched ); |
||
67 | }, |
||
68 | |||
69 | // Determine the position of an element within the set |
||
70 | index: function( elem ) { |
||
71 | |||
72 | // No argument, return index in parent |
||
73 | if ( !elem ) { |
||
74 | return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1; |
||
75 | } |
||
76 | |||
77 | // Index in selector |
||
78 | if ( typeof elem === "string" ) { |
||
79 | return indexOf.call( jQuery( elem ), this[ 0 ] ); |
||
80 | } |
||
81 | |||
82 | // Locate the position of the desired element |
||
83 | return indexOf.call( this, |
||
84 | |||
85 | // If it receives a jQuery object, the first element is used |
||
86 | elem.jquery ? elem[ 0 ] : elem |
||
87 | ); |
||
88 | }, |
||
89 | |||
90 | add: function( selector, context ) { |
||
91 | return this.pushStack( |
||
92 | jQuery.uniqueSort( |
||
93 | jQuery.merge( this.get(), jQuery( selector, context ) ) |
||
94 | ) |
||
95 | ); |
||
96 | }, |
||
97 | |||
98 | addBack: function( selector ) { |
||
99 | return this.add( selector == null ? |
||
100 | this.prevObject : this.prevObject.filter( selector ) |
||
101 | ); |
||
102 | } |
||
103 | } ); |
||
104 | |||
105 | function sibling( cur, dir ) { |
||
106 | while ( ( cur = cur[ dir ] ) && cur.nodeType !== 1 ) {} |
||
107 | return cur; |
||
108 | } |
||
109 | |||
110 | jQuery.each( { |
||
111 | parent: function( elem ) { |
||
112 | var parent = elem.parentNode; |
||
113 | return parent && parent.nodeType !== 11 ? parent : null; |
||
114 | }, |
||
115 | parents: function( elem ) { |
||
116 | return dir( elem, "parentNode" ); |
||
117 | }, |
||
118 | parentsUntil: function( elem, i, until ) { |
||
119 | return dir( elem, "parentNode", until ); |
||
120 | }, |
||
121 | next: function( elem ) { |
||
122 | return sibling( elem, "nextSibling" ); |
||
123 | }, |
||
124 | prev: function( elem ) { |
||
125 | return sibling( elem, "previousSibling" ); |
||
126 | }, |
||
127 | nextAll: function( elem ) { |
||
128 | return dir( elem, "nextSibling" ); |
||
129 | }, |
||
130 | prevAll: function( elem ) { |
||
131 | return dir( elem, "previousSibling" ); |
||
132 | }, |
||
133 | nextUntil: function( elem, i, until ) { |
||
134 | return dir( elem, "nextSibling", until ); |
||
135 | }, |
||
136 | prevUntil: function( elem, i, until ) { |
||
137 | return dir( elem, "previousSibling", until ); |
||
138 | }, |
||
139 | siblings: function( elem ) { |
||
140 | return siblings( ( elem.parentNode || {} ).firstChild, elem ); |
||
141 | }, |
||
142 | children: function( elem ) { |
||
143 | return siblings( elem.firstChild ); |
||
144 | }, |
||
145 | contents: function( elem ) { |
||
146 | return elem.contentDocument || jQuery.merge( [], elem.childNodes ); |
||
147 | } |
||
148 | }, function( name, fn ) { |
||
149 | jQuery.fn[ name ] = function( until, selector ) { |
||
150 | var matched = jQuery.map( this, fn, until ); |
||
151 | |||
152 | if ( name.slice( -5 ) !== "Until" ) { |
||
153 | selector = until; |
||
154 | } |
||
155 | |||
156 | if ( selector && typeof selector === "string" ) { |
||
157 | matched = jQuery.filter( selector, matched ); |
||
158 | } |
||
159 | |||
160 | if ( this.length > 1 ) { |
||
161 | |||
162 | // Remove duplicates |
||
163 | if ( !guaranteedUnique[ name ] ) { |
||
164 | jQuery.uniqueSort( matched ); |
||
165 | } |
||
166 | |||
167 | // Reverse order for parents* and prev-derivatives |
||
168 | if ( rparentsprev.test( name ) ) { |
||
169 | matched.reverse(); |
||
170 | } |
||
171 | } |
||
172 | |||
173 | return this.pushStack( matched ); |
||
174 | }; |
||
175 | } ); |
||
176 | |||
177 | return jQuery; |
||
178 | } ); |