I tried using the keyword this in the bindAsEventListener and inside
the details function, and that did not work. What appeared to be
bound was the anchor, not the event. And I was right back where I
started with not being able to stop the click event before the link
was followed.
Should this:
$$('a.more').invoke("observe","click",blah.bindAsEventListener(this));
Have been this:
$$('a.more').invoke("observe","click",blah.bindAsEventListener('this'));
Because I can see that the former is passing an object while the
latter is passing a string.
Walter
On Mar 7, 2008, at 6:26 AM, T.J. Crowder wrote:
>
> Walter,
>
> Am I missing something about bindAsEventListener when you pass it a
> string for the thisObj parameter? Because it looks to me like you're
> binding your 'details' function such that when the function is called
> in response to the event, the 'this' keyword will refer to the string
> "evt". It doesn't matter in your example because your 'details'
> function never uses 'this' (instead it gets the element that was
> clicked using Event.element, which is reasonable), but I thought I'd
> ask the question...
> --
> T.J. Crowder
> tj / crowder software / com
>
> On Mar 6, 5:20 pm, Walter Lee Davis <[EMAIL PROTECTED]> wrote:
>> Just to wrap this up, here's what worked:
>>
>> var details = function(evt){
>> Event.stop(evt);
>> var elm = Event.element(evt);
>> alert(elm);
>> }
>> $$('a.more').invoke
>> ('observe','click',details.bindAsEventListener
>> ('evt'));
>>
>> Thanks again for setting me on the right track.
>>
>> Walter
>>
>> On Mar 6, 2008, at 11:59 AM, Elden wrote:
>>
>>> try this.
>>
>>> $$('a.more').invoke("observe","click",blah.bindAsEventListener
>>> (this));
>>
>>> function blah(event){
>>> //this function would do way more than this
>>> event.stop();
>>> alert ("blah");
>>> }
>>
>>> and for more information take a look on the api doc's
>>
>>> http://www.prototypejs.org/api/function/bind
>>
>>> http://www.prototypejs.org/api/function/bindAsEventListener
>>
>>> On Thu, Mar 6, 2008 at 10:41 AM, Walter Lee Davis
>>> <[EMAIL PROTECTED]> wrote:
>>
>>> I have a set of A tags that I would like to watch unobtrusively. I
>>> have given them all the same classname, and I want to use invoke to
>>> set them up, rather than each. Am I trying to do something that
>>> won't
>>> work?
>>
>>> var blah = function(){
>>> //this function would do way more than this
>>> alert (this);
>>> }
>>
>>> $$('a.more').invoke('observe','click',blah);
>>
>>> This works fine, but I want to stop the event, and none of these do
>>> the trick:
>>
>>> this.stop()
>>> Event.stop(this)
>>
>>> or even extending the invoke with an additional argument after blah
>>> and using that as the event.
>>
>>> $$('a.more').invoke('observe','click',blah,'evt');
>>
>>> The only way I have been able to hack it to actually do what I want
>>> is to set this.href to null. Which feels wrong in many ways.
>>
>>> What's the right way to do this -- unobtrusively setting these links
>>> to not work, yet leaving them alone for those who don't have JS
>>> enabled? Can I do this with invoke or do I need to get out and push
>>> with each?
>>
>>> Thanks in advance,
>>
>>> Walter
>>
>>> --
>>> {a human being that was given to fly}
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---