Re: Extending CSSOM Views matchMedium with callback

On Mon, 10 May 2010 19:56:41 +0200, L. David Baron <>  
> On Monday 2010-05-10 10:27 -0700, Simon Fraser wrote:
>> 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.

Yeah, if @media was enough we would not have needed to provide the  
matchMedium() abstraction.

   styleMedia.addMediumListener(mq, callback)
   styleMedia.removeMediumListener(mq, callback)

Sounds good to me. With the same semantics as addEventListener(). (I.e.  
duplicates removed, invoked in order of registration.)

And as context information the media query and how it currently evaluates?  
What kind of representation for the media query? Serialized form?

Anne van Kesteren

Received on Tuesday, 11 May 2010 06:41:20 UTC