Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#8585 closed defect (invalid)

[dojo.query] Extract pattern matching

Reported by: dante Owned by: alex
Priority: high Milestone: future
Component: Query Version: 1.2.3
Keywords: Cc:
Blocked By: Blocking:

Description

I would like some way to be able to determine if a node passes a matched selector. There is lots of magic going on to match all the complex selectors, but most simple ones can be handled in some pseudo-css language.

eg:

<fiv class="foo">hi</div>
<div class="foo bar">hi</div>

dojo.query(".foo").matches(".bar").length == 1

.matches is invented and a horrible API name, but the overall jist is wanting to be able to determine if some node(s) match some simpleQuery.

SimpleQueries would suffice. .class, #id, >child ...

Change History (2)

comment:1 Changed 10 years ago by alex

Resolution: invalid
Status: newclosed

First, this API already exists in the form of filter() . E.g.:

dojo.query(".foo").filter(".bar").length == 1

The NodeList? version of filter() is over-loaded *specifically* to handle this use case. Secondly, if it weren't already there, it could be easily emulated with another query and indexOf. E.g.:

dojo.extend(dojo.NodeList, {
  matches: function(sq){
    var l = dojo.query(sq);
    var nl = new dojo.NodeList();
    this.forEach(function(n){
      if(l.indexOf(n) >= 0){
        nl.push(n);
      }
    });
    return nl;
  }
});

That's a lot less efficient than the current filter() impl, but would do in a pinch.

Regards

comment:2 Changed 10 years ago by bill

Component: CoreQuery
Note: See TracTickets for help on using tickets.