On Thursday 09 February 2006 17:23, Todd Ross wrote:
> On 2/9/06, Todd Ross <[EMAIL PROTECTED]> wrote:
> > Event.observe(el, 'click', function(event) {
> >   event = event || window.event;
> >   var element = Event.element(event);
> >   Element.addClassName(element, 'myClass');
> > });
> >
> > I'm not sure if there's a more Prototype-centric way to smooth out
> > retreiving the event in the handler

as for this, I believe Event.observe handles finding the proper event object 
for you and passes that to your function.  This is what I've experienced 
anyways :)

Since I'm using behaviour.js and sometimes calling behaviour.apply() multiple 
times per page-session, I can't use Event.observe, unfortunately :(  I 
probably can, but just don't know how, yet ;)

> Sorry ... I know it's bad form to reply to yourself, but I just had a
> "duh" moment.
>
> This is untested, but I think this would work:
>
> Event.observe(el, 'click', (function(event) {
>   Element.addClassName(this, 'myClass');
> }).bindAsEventListener(el));

> So, you were close with your first attempts, but in order for the
> 'this' to be useful to you, you need to bind it to the element (el),
> not the window (the default 'this' object).

Flame me if I'm wrong, but couldn't you just skip the 'this' part and use 'el' 
directly?

something like:
Event.observe(el, 'click', (function(event) {
        Element.addClassName(el, 'myClass');
);

-Jeremy

-- 
Jeremy Kitchen ++ [EMAIL PROTECTED]

In the beginning was The Word and The Word was Content-type: text/plain
  -- The Word of Bob.

Attachment: pgpxwfwaoLAmn.pgp
Description: PGP signature

_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to