0
|
1 //>>excludeStart("exclude", pragmas.exclude);
|
|
2 define([ "shoestring", "dom/is" ], function( shoestring ) {
|
|
3 //>>excludeEnd("exclude");
|
|
4
|
|
5 /**
|
|
6 * Find an element matching the selector in the set of the current element and its parents.
|
|
7 *
|
|
8 * @param {string} selector The selector used to identify the target element.
|
|
9 * @return shoestring
|
|
10 * @this shoestring
|
|
11 */
|
|
12 shoestring.fn.closest = function( selector ){
|
|
13 var ret = [];
|
|
14
|
|
15 if( !selector ){
|
|
16 return shoestring( ret );
|
|
17 }
|
|
18
|
|
19 this.each(function(){
|
|
20 var element, $self = shoestring( element = this );
|
|
21
|
|
22 if( $self.is(selector) ){
|
|
23 ret.push( this );
|
|
24 return;
|
|
25 }
|
|
26
|
|
27 while( element.parentElement ) {
|
|
28 if( shoestring(element.parentElement).is(selector) ){
|
|
29 ret.push( element.parentElement );
|
|
30 break;
|
|
31 }
|
|
32
|
|
33 element = element.parentElement;
|
|
34 }
|
|
35 });
|
|
36
|
|
37 return shoestring( ret );
|
|
38 };
|
|
39
|
|
40 //>>excludeStart("exclude", pragmas.exclude);
|
|
41 });
|
|
42 //>>excludeEnd("exclude");
|