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