- From: Tab Atkins Jr. <jackalmage@gmail.com>
- Date: Tue, 21 Aug 2012 15:40:19 -0700
- To: Rick Waldron <waldron.rick@gmail.com>
- Cc: Brian Kardell <bkardell@gmail.com>, public-webapps <public-webapps@w3.org>, Ojan Vafai <ojan@chromium.org>
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. > 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. >> 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. ^_^ ~TJ
Received on Tuesday, 21 August 2012 22:41:06 UTC