Re: [cssom] Constructor for MediaList

On Wed, Jun 26, 2013 at 10:24 AM, Simon Sapin <simon.sapin@exyr.org> wrote:
> Le 26/06/2013 18:18, Tab Atkins Jr. a écrit :
>>> Why is a constructor needed instead of just a string?
>>>
>>> document.css.customMedia.set("foo", "(foo:bar) and (baz:qux)");
>>
>> Because a custom MQ should be settable to a string as well, so you can
>> do ("foo": "bar"), similar to existing MQs that let you test for
>> specific values.
>>
>> Basically, custom MQs should be settable to booleans, strings, or
>> numbers.  Setting them to another MQ is a special form of
>> auto-updating boolean.
>
> I meant a JS string, not a CSS string.

I also mean a JS string.  Forcing people to set a custom MQ to a
string value by embedding a CSS string inside a JS string would be
horrid.

> Your proposal is to have the JS API allow setting custom MQs to booleans,
> numbers, and MQ objects. The latter are auto-updating booleans.

Also strings.  For example, the built-in orientation MQ accepts the
keyword "landscape".  If you were doing this yourself as a custom MQ,
it would be something like:

document.css.customMedia.set("orientation", "landscape");
@media ("orientation": "landscape") { ... }

(Ignore my lack of appropriate element wrappers - you can figure out
which language is which.)

I'm using strings for both MQ name and value here partially for
disambiguation, and partially because it means the author doesn't have
to worry about CSS's ident rules - we often use strings to represent
things from the outside world, even if they would be idents if written
in normal CSS.

> My proposal is to allow booleans, numbers, and strings. The latter are
> parsed as MQs for auto-updating booleans.

Hopefully you now understand why the custom MQ proposal has already
claimed strings, and so it can't be reused for something else.

~TJ

Received on Wednesday, 26 June 2013 17:41:06 UTC