0
|
1 //>>excludeStart("exclude", pragmas.exclude);
|
|
2 define([ "shoestring" ], function(){
|
|
3 //>>excludeEnd("exclude");
|
|
4
|
|
5 /**
|
|
6 * Checks the current set of elements against the selector, if one matches return `true`.
|
|
7 *
|
|
8 * @param {string} selector The selector to check.
|
|
9 * @return {boolean}
|
|
10 * @this {shoestring}
|
|
11 */
|
|
12 shoestring.fn.is = function( selector ){
|
|
13 var ret = false, self = this, parents, check;
|
|
14
|
|
15 // assume a dom element
|
|
16 if( typeof selector !== "string" ){
|
|
17 // array-like, ie shoestring objects or element arrays
|
|
18 if( selector.length && selector[0] ){
|
|
19 check = selector;
|
|
20 } else {
|
|
21 check = [selector];
|
|
22 }
|
|
23
|
|
24 return _checkElements(this, check);
|
|
25 }
|
|
26
|
|
27 parents = this.parent();
|
|
28
|
|
29 if( !parents.length ){
|
|
30 parents = shoestring( doc );
|
|
31 }
|
|
32
|
|
33 parents.each(function( i, e ) {
|
|
34 var children;
|
|
35
|
|
36 //>>includeStart("development", pragmas.development);
|
|
37 try {
|
|
38 //>>includeEnd("development");
|
|
39 children = e.querySelectorAll( selector );
|
|
40 //>>includeStart("development", pragmas.development);
|
|
41 } catch( e ) {
|
|
42 shoestring.error( 'queryselector', selector );
|
|
43 }
|
|
44 //>>includeEnd("development");
|
|
45
|
|
46 ret = _checkElements( self, children );
|
|
47 });
|
|
48
|
|
49 return ret;
|
|
50 };
|
|
51
|
|
52 function _checkElements(needles, haystack){
|
|
53 var ret = false;
|
|
54
|
|
55 needles.each(function() {
|
|
56 var j = 0;
|
|
57
|
|
58 while( j < haystack.length ){
|
|
59 if( this === haystack[j] ){
|
|
60 ret = true;
|
|
61 }
|
|
62
|
|
63 j++;
|
|
64 }
|
|
65 });
|
|
66
|
|
67 return ret;
|
|
68 }
|
|
69
|
|
70 //>>excludeStart("exclude", pragmas.exclude);
|
|
71 });
|
|
72 //>>excludeEnd("exclude");
|