Walter Lee Davis
2007-Aug-24 18:04 UTC
How do you use $$() and bindAsEventListener together?
Subject pretty much says it all: I have $$(''a.citation''), and I am using invoke to run through all of them. I know I need to add bindAsEventListener in there somewhere, but what is the reference to my "looped" object that I pass back to it? I have tried this and nothing, and neither give me any reference back inside my function. $$(''a.citation'').invoke(''observe'',''click'',cit_this.bindAsEventListener() ); Thanks in advance, Walter --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Dan Dorman
2007-Aug-24 18:16 UTC
Re: How do you use $$() and bindAsEventListener together?
On 8/24/07, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> I have $$(''a.citation''), and I am using invoke to run through all of > them. I know I need to add bindAsEventListener in there somewhere, but > what is the reference to my "looped" object that I pass back to it? > > $$(''a.citation'').invoke(''observe'',''click'',cit_this.bindAsEventListener() > );If you''re trying to assign an event handler to all the citation links, you can do it like so: $$(''a.citation'').invoke(''observe'', ''click'', eventHandler); You don''t need to call bindAsEventListener. How you get the element that triggered the event once inside the event handler depends on whether you''re using 1.5 or 1.6. 1.5 style: function eventHandler(evt) { var el = Event.element(evt); // do stuff with el } 1.6 style: function eventHandler(evt) { var el = this; // sweet! ''this'' is mapped to the element that fired the event automatically // do stuff with el } I may have missed the point of what you''re actually trying to do, and if so, I apologize. :Dan Dorman --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Walter Lee Davis
2007-Aug-24 18:32 UTC
Re: How do you use $$() and bindAsEventListener together?
And now I''ve come full-circle. I was using that 1.5 code previously, and the whole bindAsEventListener thing was to solve another problem I was having with IE6-- the reference from the click is to the image, not the link that wraps it, even though my loop is constructed of extended A objects. How production-worthy is the RC of 1.6? Thanks very much. Walter On Aug 24, 2007, at 2:16 PM, Dan Dorman wrote:> > On 8/24/07, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: >> I have $$(''a.citation''), and I am using invoke to run through all of >> them. I know I need to add bindAsEventListener in there somewhere, but >> what is the reference to my "looped" object that I pass back to it? >> >> $$(''a.citation'').invoke(''observe'',''click'',cit_this.bindAsEventListener >> () >> ); > > If you''re trying to assign an event handler to all the citation links, > you can do it like so: > > $$(''a.citation'').invoke(''observe'', ''click'', eventHandler); > > You don''t need to call bindAsEventListener. How you get the element > that triggered the event once inside the event handler depends on > whether you''re using 1.5 or 1.6. > > 1.5 style: > function eventHandler(evt) { > var el = Event.element(evt); > // do stuff with el > } > > 1.6 style: > function eventHandler(evt) { > var el = this; // sweet! ''this'' is mapped to the element that fired > the event automatically > // do stuff with el > } > > I may have missed the point of what you''re actually trying to do, and > if so, I apologize. > > :Dan Dorman > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Dan Dorman
2007-Aug-24 18:56 UTC
Re: How do you use $$() and bindAsEventListener together?
On 8/24/07, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> How production-worthy is the RC of 1.6?I just rewrote a big chunk of JS here at work to utilize 1.6''s features, and it''s been pretty solid so far. :Dan Dorman --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Matt Foster
2007-Aug-24 19:50 UTC
Re: How do you use $$() and bindAsEventListener together?
Yeah isn''t that a great bug in IE, there is no way for a click event to reference its currentTarget, just where it originates from, fantastic. I worked out a solution to that using bindAsEventListener and just attaching the object i was observing to the argument scope of the bound function. check out the full article here, http://www.positionabsolute.net/blog/2007/04/function-bind.php On Aug 24, 2:56 pm, "Dan Dorman" <dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 8/24/07, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: > > > How production-worthy is the RC of 1.6? > > I just rewrote a big chunk of JS here at work to utilize 1.6''s > features, and it''s been pretty solid so far. > > :Dan Dorman--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Walter Lee Davis
2007-Aug-24 20:13 UTC
Re: How do you use $$() and bindAsEventListener together?
Thanks, I had seen a similar example, and it works fine for single instances. But when you are inside a loop, going through an array of many elements on the page with each or invoke, there doesn''t seem to be any reference possible to the object in question. I ended up using Event.element inside my anonymous function, but I live in fear that IE will think that''s too ambiguous. Is there some way to use bind or bindAsEventListener when you are looping through a collection with invoke? Walter On Aug 24, 2007, at 3:50 PM, Matt Foster wrote:> > Yeah isn''t that a great bug in IE, there is no way for a click event > to reference its currentTarget, just where it originates from, > fantastic. > > I worked out a solution to that using bindAsEventListener and just > attaching the object i was observing to the argument scope of the > bound function. > > check out the full article here, > > http://www.positionabsolute.net/blog/2007/04/function-bind.php > > On Aug 24, 2:56 pm, "Dan Dorman" <dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On 8/24/07, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: >> >>> How production-worthy is the RC of 1.6? >> >> I just rewrote a big chunk of JS here at work to utilize 1.6''s >> features, and it''s been pretty solid so far. >> >> :Dan Dorman > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I dont think its possible with invoke, but using each should work $$(''a.citation'').each(function(el) {el.observe(''click'',cit_this.bindAsEventListener(el));} ); Tom On Aug 24, 1:13 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> Thanks, I had seen a similar example, and it works fine for single > instances. > > But when you are inside a loop, going through an array of many elements > on the page with each or invoke, there doesn''t seem to be any reference > possible to the object in question. I ended up using Event.element > inside my anonymous function, but I live in fear that IE will think > that''s too ambiguous. > > Is there some way to use bind or bindAsEventListener when you are > looping through a collection with invoke? > > Walter > > On Aug 24, 2007, at 3:50 PM, Matt Foster wrote: > > > > > Yeah isn''t that a great bug in IE, there is no way for a click event > > to reference its currentTarget, just where it originates from, > > fantastic. > > > I worked out a solution to that using bindAsEventListener and just > > attaching the object i was observing to the argument scope of the > > bound function. > > > check out the full article here, > > >http://www.positionabsolute.net/blog/2007/04/function-bind.php > > > On Aug 24, 2:56 pm, "Dan Dorman" <dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> On 8/24/07, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: > > >>> How production-worthy is the RC of 1.6? > > >> I just rewrote a big chunk of JS here at work to utilize 1.6''s > >> features, and it''s been pretty solid so far. > > >> :Dan Dorman--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
$$(''a.citation'').invoke(''observe'', ''click'', callback); function callback(e){ e.stop(); // here''s your event alert(this); // here''s your element alert(this.up()); // that''s how you can access upper element alert(e.target); // this should reference element that fired event } -- View this message in context: http://www.nabble.com/How-do-you-use-%24%24%28%29-and-bindAsEventListener-together--tf4324993.html#a12323160 Sent from the RubyOnRails Spinoffs mailing list archive at Nabble.com. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve
2007-Aug-25 08:29 UTC
Re: How do you use $$() and bindAsEventListener together?
Tom a écrit :> I dont think its possible with invoke, but using each should workIn 1.6 it is, because you''d get properly bound ("this" is the element you registered on). In 1.5, you would need the each, but you don''t need bindAsEventListener: not passing any extra arguments means you''ll get the event object as first arg even with a simple bind. -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Walter Lee Davis
2007-Aug-25 15:33 UTC
Re: How do you use $$() and bindAsEventListener together?
Thanks, this is approximately what I ended up doing, except using Event.findElement rather than up. Walter On Aug 25, 2007, at 12:37 AM, kangax wrote:> > > $$(''a.citation'').invoke(''observe'', ''click'', callback); > > function callback(e){ > e.stop(); // here''s your event > alert(this); // here''s your element > alert(this.up()); // that''s how you can access upper element > alert(e.target); // this should reference element that fired event > } >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Walter Lee Davis
2007-Aug-25 15:33 UTC
Re: How do you use $$() and bindAsEventListener together?
Thanks so much, this was what I was looking for. Walter On Aug 24, 2007, at 9:41 PM, Tom wrote:> > I dont think its possible with invoke, but using each should work > > $$(''a.citation'').each(function(el) > {el.observe(''click'',cit_this.bindAsEventListener(el));} > ); > > > Tom >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---