Re: Proposal for "Cascading Attribute Sheets" - like CSS, but for attributes!

On Tue, Aug 21, 2012 at 6:40 PM, Tab Atkins Jr. <jackalmage@gmail.com>wrote:

> On Tue, Aug 21, 2012 at 3:29 PM, Rick Waldron <waldron.rick@gmail.com>
> wrote:
> > On Tue, Aug 21, 2012 at 6:17 PM, Tab Atkins Jr. <jackalmage@gmail.com>
> > wrote:
> >> ul.special > li {
> >>   onclick: "alert('You clicked me!');
> >> evt.target.classlist.add('clicked');";
> >> }
> >
> >
> > This is certainly interesting, but...
> >
> > 1. It's a string that will have to be eval'ed, right? In what scope? Does
> > this get wrapped in a function expression?
>
> No, it's a string that gets passed as an argument to setAttribute()
> (or the moral equivalent of such).  Any eval'ing that happens is just
> part of the normal way that onfoo attributes are handled.
>

Ah-ha, I was thinking of this a bit too "script literally"

>
>
> > 2. Using inline attributes that match up to node.onfoo will pave over
> each
> > other... if some other style sheet is introduced, by some third party
> widget
> > that happens to have
> >
> > ul.special > li {
> >   onclick: "alert('busted')";
> > }
> >
> > ...Bummer?
>
> Yes.  That's why I just suggested the listen() function, which would
> invoke addEventListener instead of setAttribute.
>
> This *would* require a little bit more detail about evaling the
> string.  I suppose it should just be passed through the Function
> constructor in the global scope before being passed to aEL.
>
>
> > 3. Where did "evt" come from?
>
> Isn't that one of the magically-defined variables in inline event
> handlers?  If not, swap it out with whatever the correct equivalent
> is.
>

Nope? (Maybe in 1990's? :D )




>
>
> >> Here's a suggestion for a similar API that would invoke
> >> addEventListener instead of setAttribute:
> >>
> >> ul.special > li {
> >>   onclick: listen("alert('You clicked me!');
> >> evt.target.classlist.add('clicked');");
> >> }
> >
> > How do we know where the body ends?
>
> Do you mean the function body?  It's a string.  The end is well-defined.
> ^_^
>

Yep, function body.

The string broke over two lines and tricked my eyes and brain. ;)


Rick



>
> ~TJ
>

Received on Tuesday, 21 August 2012 22:52:49 UTC