W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2011

Re: QSA, the problem with ":scope", and naming

From: Lachlan Hunt <lachlan.hunt@lachy.id.au>
Date: Wed, 19 Oct 2011 20:17:50 +0200
Message-ID: <4E9F144E.4030906@lachy.id.au>
To: Alex Russell <slightlyoff@google.com>
CC: Webapps WG <public-webapps@w3.org>, Yehuda Katz <wycats@gmail.com>, John Resig <jeresig@gmail.com>, Paul Irish <paulirish@google.com>
On 2011-10-18 18:42, Alex Russell wrote:
>    HTMLDocument.prototype.find =
>    HTMLElement.prototype.find = function(rootedSelector) {
>       return this.querySelector(":scope " + rootedSelector);
>     }
>
>     HTMLDocument.prototype.findAll =
>     HTMLElement.prototype.findAll = function(rootedSelector) {
>       return this.querySelectorAll(":scope " + rootedSelector);
>     }

What exactly does it mean to have a "rootedSelector" applied to the 
Document object?  As I understand it, the scoping problem explained only 
seems to apply to running the query on elements, whereas the existing 
document.qsa already behaves as expected by authors.  It doesn't seem to 
make sense to try and prepend :scope to selectors in that case.

e.g. document.find("html") shouldn't be equivalent to 
document.querySelector(":scope html");

So, either we introduce the new method only for elements, or we use a 
similarly named method on document for a similar, but slightly different 
purpose.

A previous use case discussed on this list is the ability to take a 
collection of elements, and execute the same selector on all all of 
them, as if iterating the list, collecting the results and returning a 
single merged collection.

The current API handles this use case with document.querySelectorAll, 
explicitly specifying :scope and passing a collection of refNodes.

e.g.
var list = ...; // Elements (Array, NodeList or indexed object)

// Find the sibling p elements of all elements in the list
document.querySelectorAll(":scope+p", list);

Thus, if we do introduce the proposed method, should it behave 
similarly, but with the implied rather than explicit :scope?

e.g.
document.findAll("+p", list);

-- 
Lachlan Hunt - Opera Software
http://lachy.id.au/
http://www.opera.com/
Received on Wednesday, 19 October 2011 18:18:41 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:48 GMT