W3C home > Mailing lists > Public > www-style@w3.org > April 2008

Re: [SelectorsAPI] Selector detection needed?

From: Bjoern Hoehrmann <derhoermi@gmx.net>
Date: Tue, 08 Apr 2008 01:23:05 +0200
To: Daniel Glazman <daniel.glazman@disruptive-innovations.com>
Cc: www-style@w3.org
Message-ID: <tvskv31r68spt9p94k8k1vd7i6h9dfnd07@hive.bjoern.hoehrmann.de>

* Daniel Glazman wrote:
>> For which I would naturally call the methods on an empty document or
>> an isolated element. Quite frankly even then this is a lot nicer then
>> doing something like
>> 
>>   if (document.supportsSelector(DocumentSelector.CSS_TYPE_SELECTOR) &&
>>       document.supportsSelector(DocumentSelector.CSS_CHILD_COMBINER))
>>     ...
>> 
>> As has been suggested initially in this thread.
>
>Wow. I just cannot believe what I read above. Wow.

Since this list is for technical discussion only, let me expand on what
I've said before. Using numerical constants is a bad idea, I've already
mentioned that it does not work with selectors from dynamic sources and
fails for more complex selector support queries. I could add that tests
like the one above are very verbose and require substantial lookup and
copy and paste effort, worst of all is of course that we'd have to make
new constants for every pseudo-class we add, and make a policy for how
to query for vendor-specific ones.

documents.supportsSelector("A > B") does not have any of these problems,
so if you'd add such a function, you'd use this syntax instead. Now that
you can implement with, say,

  Document.prototype.supportsSelector = function(s) {
    try { document.createElement("tmp").querySelector(s,
      function(prefix) { return "ns"; }) }
    catch (e) { return false; }
    return true;
  }

yourself, which is none of overly verbose, slow, or difficult. Clearly
I prefer this over having to lookup numerous constants online, and since
so far I only came up with a single and rather exotic use case for this,
it's difficult to see why the specification should enable some other
approach. If anyone has good use cases or arguments relative to this
matter, they are most welcome to share them on public-webapi@w3.org.
-- 
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 
Received on Monday, 7 April 2008 23:23:51 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:55:04 GMT