Re: Extending CSSOM Views matchMedium with callback

On Monday 2010-05-10 10:27 -0700, Simon Fraser wrote:
> This simple callback-based mechanism suffers from various problems (of the type
> that add/removeEventListener were designed to solve):
> 
> 1. Unclear behavior when calling matchMedium() a second time for the same query,
> with a different callback.
> 2. No way to remove a callback
> 3. Lack of context on the callback

Right.  These are problems.

> It feels to me like the correct solution would be enhance CSS OM somehow to allow
> authors to attach event listeners to CSSMediaRules somehow, so they can get notified
> when those @media statements start or stop matching.

Making @media rules implement EventTarget sounds ok, as long as the
events don't bubble.  But is the main use case for this API actually
people who already have @media rules, or people who want to do
things separately from @media rules and would thus now have to go
through the bother of adding some to a style sheet?  (The CSSOM also
isn't very good at giving you the rule object after adding a rule.)

I might still lean towards an
addMediaQueryListener/removeMediaQueryListener type API.

-David

-- 
L. David Baron                                 http://dbaron.org/
Mozilla Corporation                       http://www.mozilla.com/

Received on Monday, 10 May 2010 17:57:16 UTC