[whatwg] Features for responsive Web design

Aaron Gustafson aaron at easy-designs.net
Wed Sep 5 15:42:37 PDT 2012

On Wed, Sep 5, 2012 at 1:45 PM, Mathew Marquis <mat at matmarquis.com> wrote:

> I can say for my own part: manipulating strings is far more difficult than
> manipulating the value of individual attributes. It’s hard to imagine a
> situation where I’d prefer to muck through a space/comma separated string
> rather than a set of independent elements and attributes. Unless the plan is
> to include an API similar to classList, though it would then be occupied by
> a set of strings describing disparate information.

I agree, string manipulation is *not* what we want here.

> Given `srcset="img2.jpg 2x 300w, img3.jpg 600w 2x"`, I can only envision a
> classList-style API returning something like one of the following:
> 1) [ "img2.jpg", "2x", "300w", "img3.jpg", "600w", "2x" ]
> This obviously isn’t ideal where authors will have no idea what information
> is being manipulated without keeping constant tabs on the current index as
> compared to the string in the markup. Even if the order of these separate
> concerns were normalized, the inclusion or omission of any individual aspect
> of a rule would mean a flurry of `console.log`s in order to figure out which
> index represented which concern — or careful counting of spaces in one’s
> markup, which certainly seems error-prone to me. I know I would certainly
> make mistakes, there.
> 2) [ "img2.jpg 2x 300w", "img3.jpg 600w 2x" ]
> We’re still left parsing space-seperated strings for relevant information,
> albeit smaller ones.
> I don’t feel there’s much of a case to be made in favor of writing regular
> expressions to parse and manipulate strings, rather than manipulating
> elements and attributes — though, as always, I’m happy to reach out to the
> author community and ask. If I’m completely off-base here — and I may well
> be — I’d certainly be interested in reading more about the plans for an API.

Might I propose an option 3 (which is in no way a vote of support for
Hixies suggested srcset, I like the proposed video-like syntax far

[{ image: 'img2.jpg', density: '2x', query: '300w' }, { image:
'img3.jpg', density: '2x', query: '600w' }]

If the values are actually keyed to something predictable, we might
stand some chance of actually reading/manipulating them without having
to determine which value is which if they are out of order (it stand
to reason the browser would have done this already, so…)



Aaron Gustafson
Easy Designs, LLC

More information about the whatwg mailing list