Looks really useful, always been frustrated that getDimensions
includes the padding and border sizes (I know that's due to Javascript/
CSS rather that Prototype).

I prefer the 'measure' syntax rather than having to first grab an
instance of Element.Layout. However, 'measure' doesn't seem to cache
the instances of Element.Layout it uses so looks like it's a costly
method at the moment.

Perhaps 'measure' could be amended to cache Element.Layout, maybe with
a way of grabbing a fresh 'snapshot' when it's needed?

Thanks,
Mike.



On Jan 16, 9:27 am, Andrew Dupont <goo...@andrewdupont.net> wrote:
> I've just committed a couple large API additions in a "layout" branch
> in our Git repository:
>
> http://github.com/sstephenson/prototype/tree/layouthttp://github.com/sstephenson/prototype/blob/9d28f04d98307f652a2d85ff...
>
> It's still very preliminary, but Element.Layout is meant to like a
> lazy-loading, memoized subclass of Hash. It gives measurements and
> offsets of practically any aspect an element's layout box. It's lazy-
> loading because some of these computations are costly and shouldn't be
> done unless strictly necessary.
>
> In other words, I can do something like this...
>
> var foo = $('foo');
> var layout = foo.getLayout();
>
> var width = layout.get('width'); // 144 (or some other number)
> var marginBoxWidth = layout.get('margin-box-width'); // 164 (content +
> padding + border + margin)
>
> Behind the scenes, it determined the "width" (i.e., the content box
> width) by taking the offsetWidth property from the element (which is
> the width of the element's "border box") and subtracting the computed
> padding and border widths on both sides. When it did this, it cached
> the values for many other measurements, like "border-box-width,"
> "padding-left," "padding-right," and so on. If any of these values are
> requested directly, no further computation is necessary.
>
> Furthermore, when we ask for the "margin-box-width" (i.e., the space
> the element truly commands), it knows it needs to fetch "margin-left"
> and "margin-right," but the values of all other properties are already
> cached.
>
> (A caveat: because of the caching, an Element.Layout object should be
> treated like a "snapshot" of an element's dimensions. When the
> dimensions of an object change, you ought to grab a new instance of
> Element.Layout.)
>
> Take a look at the code and tell me what you think. The API is far
> from complete, naturally, but it'd be great to know if people think
> this is the right idea.
>
> Cheers,
> Andrew
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to