File size: 1,076 Bytes
bc20498
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { matches as queryMatches } from './query-type-match';
import Type from './type';

// filter an existing collection
let filter = function( collection ){
  let self = this;

  // for 1 id #foo queries, just get the element
  if( self.length === 1 && self[0].checks.length === 1 && self[0].checks[0].type === Type.ID ){
    return collection.getElementById( self[0].checks[0].value ).collection();
  }

  let selectorFunction = function( element ){
    for( let j = 0; j < self.length; j++ ){
      let query = self[ j ];

      if( queryMatches( query, element ) ){
        return true;
      }
    }

    return false;
  };

  if( self.text() == null ){
    selectorFunction = function(){ return true; };
  }

  return collection.filter( selectorFunction );
}; // filter

// does selector match a single element?
let matches = function( ele ){
  let self = this;

  for( let j = 0; j < self.length; j++ ){
    let query = self[ j ];

    if( queryMatches( query, ele ) ){
      return true;
    }
  }

  return false;
}; // matches

export default { matches, filter };