Gregory Hill
2006-Jun-15 18:24 UTC
RE: Yahoo!-like Event object emulation/abstractioninPrototype?
If that doesn''t work, then you''ve done something wrong somewhere. ''Cause it works for IE for me and everyone else. The only advantage I see with the YUI toolkit is that it''ll defer attaching events to elements that do not yet exist in the DOM. Big whoop, only a sloppy programmer would try to attach an event to a non-existant element. With Prototype, you can bind the handler function to an object of your choice and create your own scope. I didn''t see that option on the YUI documentation I read. (it automatically binds the scope to the element the event acted upon, which is pretty much never what I want). Greg> -----Original Message----- > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org[mailto:rails-spinoffs-> bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Sam Rowe > Sent: Thursday, June 15, 2006 12:18 PM > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: Re: [Rails-spinoffs] Yahoo!-like Event object > emulation/abstractioninPrototype? > > On Thu, Jun 15, 2006 at 11:28:03AM -0600, Gregory Hill wrote: > # Event.observe(myelement, ''click'', myfunc.bindAsEventListener()); > # > # That might fix your wagon. > > That didn''t seem to make any difference. FF still works, IE still > does not. I''m not branching for window.event in my callback/listener. > > I''m asking about a level of abstraction/emulation like is described > in the section titled "It''s Tight because..." > > http://www.dustindiaz.com/yahoo-event-utility/ > > Any chance of getting that in Prototype? > > # > # Greg > # > # > -----Original Message----- > # > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > # [mailto:rails-spinoffs- > # > bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Sam Rowe > # > Sent: Thursday, June 15, 2006 11:24 AM > # > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > # > Subject: Re: [Rails-spinoffs] Yahoo!-like Event object > # > emulation/abstractionin Prototype? > # > > # > On Thu, Jun 15, 2006 at 08:44:13AM -0500, Ryan Gahl wrote: > # > # Um... Event.observe() -- it''s been there all along and doesthat> # > # abstraction. > # > > # > Weird, I wonder why none of my event handlers work in IE. I''lllook> # > closer. > # > Thanks for the info. > # > > # > Just cause I''m dense... I''m talking about this: > # > > # > Event.observe(myelement,''click'',myfunc); > # > > # > function myfunc(e){ > # > // deal with e like I would in FF > # > } > # > > # > Are we talking about the same thing? > # > _______________________________________________ > # > Rails-spinoffs mailing list > # > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > # > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > # _______________________________________________ > # Rails-spinoffs mailing list > # Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > # http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Sam Rowe
2006-Jun-15 18:48 UTC
Re: Yahoo!-like Event object emulation/abstractioninPrototype?
On Thu, Jun 15, 2006 at 12:24:11PM -0600, Gregory Hill wrote: # If that doesn''t work, then you''ve done something wrong somewhere. # ''Cause it works for IE for me and everyone else. # # The only advantage I see with the YUI toolkit is that it''ll defer # attaching events to elements that do not yet exist in the DOM. Big # whoop, only a sloppy programmer would try to attach an event to a # non-existant element. With Prototype, you can bind the handler function # to an object of your choice and create your own scope. I didn''t see # that option on the YUI documentation I read. (it automatically binds the # scope to the element the event acted upon, which is pretty much never # what I want). # # Greg What am I doing wrong? http://pastebin.com/711271 Works in FF, in IE I get an error about target.id. Thanks! -Sam
Ryan Gahl
2006-Jun-15 18:50 UTC
Re: Yahoo!-like Event object emulation/abstractioninPrototype?
jojo is a member method of taco (in your previous posts I think both me and Greg assumed your function was at the global scope level)... change your Event.observe line to the following... Event.observe(x,''click'', this.jojo.bindAsEventListener(this)); On 6/15/06, Sam Rowe <scriptaculous-NA8LtxyqzOtZdbSWXsKqFg@public.gmane.org> wrote:> > On Thu, Jun 15, 2006 at 12:24:11PM -0600, Gregory Hill wrote: > # If that doesn''t work, then you''ve done something wrong somewhere. > # ''Cause it works for IE for me and everyone else. > # > # The only advantage I see with the YUI toolkit is that it''ll defer > # attaching events to elements that do not yet exist in the DOM. Big > # whoop, only a sloppy programmer would try to attach an event to a > # non-existant element. With Prototype, you can bind the handler function > # to an object of your choice and create your own scope. I didn''t see > # that option on the YUI documentation I read. (it automatically binds the > # scope to the element the event acted upon, which is pretty much never > # what I want). > # > # Greg > > What am I doing wrong? > > http://pastebin.com/711271 > > Works in FF, in IE I get an error about target.id. > > Thanks! > -Sam > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Ryan Gahl
2006-Jun-15 18:54 UTC
Re: Yahoo!-like Event object emulation/abstractioninPrototype?
actually that may not work either, you''re using a funky nested function syntax... One way or the other, you just have to get the proper object bound the the lexical scope of the jojo function... Or something like that... it definitely works.... What version of prototype are you using? On 6/15/06, Ryan Gahl <ryan.gahl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > jojo is a member method of taco (in your previous posts I think both me > and Greg assumed your function was at the global scope level)... > > change your Event.observe line to the following... > > Event.observe(x,''click'', this.jojo.bindAsEventListener(this)); > > On 6/15/06, Sam Rowe <scriptaculous-NA8LtxyqzOtZdbSWXsKqFg@public.gmane.org> wrote: > > > On Thu, Jun 15, 2006 at 12:24:11PM -0600, Gregory Hill wrote: > > # If that doesn''t work, then you''ve done something wrong somewhere. > > # ''Cause it works for IE for me and everyone else. > > # > > # The only advantage I see with the YUI toolkit is that it''ll defer > > # attaching events to elements that do not yet exist in the DOM. Big > > # whoop, only a sloppy programmer would try to attach an event to a > > # non-existant element. With Prototype, you can bind the handler > > function > > # to an object of your choice and create your own scope. I didn''t see > > # that option on the YUI documentation I read. (it automatically binds > > the > > # scope to the element the event acted upon, which is pretty much never > > # what I want). > > # > > # Greg > > > > What am I doing wrong? > > > > http://pastebin.com/711271 > > > > Works in FF, in IE I get an error about target.id. > > > > Thanks! > > -Sam > > _______________________________________________ > > Rails-spinoffs mailing list > > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > >_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Jeremy Kitchen
2006-Jun-15 19:00 UTC
Re: Yahoo!-like Event object emulation/abstractioninPrototype?
On Thursday 15 June 2006 11:48, Sam Rowe wrote:> http://pastebin.com/711271on a side note, ditch that add load event thing and do this: Event.observe(window, ''load'', function() { whatever; }); -Jeremy -- Jeremy Kitchen ++ kitchen-RA8HwDor7flnDGu+y90WmgC/G2K4zDHf@public.gmane.org http://www.pirate-party.us/ -- defend your rights _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Sam Rowe
2006-Jun-15 19:04 UTC
Re: Yahoo!-like Event object emulation/abstractioninPrototype?
On Thu, Jun 15, 2006 at 01:50:41PM -0500, Ryan Gahl wrote: # jojo is a member method of taco (in your previous posts I think both me # and Greg assumed your function was at the global scope level)... # # change your Event.observe line to the following... # # Event.observe(x,''click'', this.jojo.bindAsEventListener(this)); Sorry to be dense. I changed it and now IE gives me an error that this.jojo is null or not an object. http://pastebin.com/711299
Sam Rowe
2006-Jun-15 19:08 UTC
Re: Yahoo!-like Event object emulation/abstractioninPrototype?
On Thu, Jun 15, 2006 at 01:54:41PM -0500, Ryan Gahl wrote: # actually that may not work either, you''re using a funky nested function # syntax... # # One way or the other, you just have to get the proper object bound the the # lexical scope of the jojo function... # # Or something like that... it definitely works.... # # What version of prototype are you using? Prototype JavaScript framework, version 1.5.0_rc0. As you''ve probably guessed, I''m new to Javascript (and OO programming in general.) I got that syntax from Simon Willison''s recent "A re-introduction to Javascript" presentation. As an old-school procedural programmer, all of that ''this.whatever'' stuff makes my head spin. Thanks for the help! -Sam
Ryan Gahl
2006-Jun-15 19:26 UTC
Re: Yahoo!-like Event object emulation/abstractioninPrototype?
Yea, like I said, it might not work how I originally wrote it, because you''re not using the traditional prototype-ish class or object syntax... here... re-write everything like this... taco { init: function() { this.x = $("myelement"); Event.observe(this.x, "click", this.jojo.bindAsEventListener(this) ); }, jojo: function(e) { alert(Event.element(e).id); } }; Event.observe(window, "onload", taco.init ); ...After I looked harder I realized your main problem isn''t that scope thing... it''s that "target" is not a valid property of IE''s Event object... lol sorry I was so blind... so using Event.element(e).id was really all you were looking for... my bad!! I''m just going to leave the above code like that though so you can see a working example of bindAsEventListener()... On 6/15/06, Sam Rowe <scriptaculous-NA8LtxyqzOtZdbSWXsKqFg@public.gmane.org> wrote:> > On Thu, Jun 15, 2006 at 01:50:41PM -0500, Ryan Gahl wrote: > # jojo is a member method of taco (in your previous posts I think both > me > # and Greg assumed your function was at the global scope level)... > # > # change your Event.observe line to the following... > # > # Event.observe(x,''click'', this.jojo.bindAsEventListener(this)); > > Sorry to be dense. I changed it and now IE gives me an error that > this.jojo is null or not an object. > > http://pastebin.com/711299 > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Sam Rowe
2006-Jun-15 19:32 UTC
Re: Yahoo!-like Event object emulation/abstractioninPrototype?
On Thu, Jun 15, 2006 at 02:26:06PM -0500, Ryan Gahl wrote: # Yea, like I said, it might not work how I originally wrote it, because # you''re not using the traditional prototype-ish class or object syntax... # here... re-write everything like this... # taco # { # init: function() # { # this.x = $("myelement"); # Event.observe(this.x, "click", this.jojo.bindAsEventListener(this) ); # }, # # jojo: function(e) # { # alert(Event.element(e).id); # } # }; # Event.observe(window, "onload", taco.init ); # # ...After I looked harder I realized your main problem isn''t that scope # thing... it''s that "target" is not a valid property of IE''s Event # object... lol sorry I was so blind... # # so using Event.element(e).id was really all you were looking for... my # bad!! I''m just going to leave the above code like that though so you can # see a working example of bindAsEventListener()... Hehe thanks for putting so much work into this, but to me it certainly begs my original question. Any chance of making "e" work the same in FF and IE?
Ryan Gahl
2006-Jun-15 19:54 UTC
Re: Yahoo!-like Event object emulation/abstractioninPrototype?
Well sure, but the only way to do that would be for "e" to be some other object that you''ve derived from the actual Event object, but then you''d lose the ability to access the native Event object to do things like stop propagation, etc.. prototype gives you those abstracted static methods (like Event.element() and Event.positionY and positionX), which you can use in a cross-browser manner... and then you still have access the original (browser native) Event object if you need it. On 6/15/06, Sam Rowe <scriptaculous-NA8LtxyqzOtZdbSWXsKqFg@public.gmane.org> wrote:> > On Thu, Jun 15, 2006 at 02:26:06PM -0500, Ryan Gahl wrote: > # Yea, like I said, it might not work how I originally wrote it, > because > # you''re not using the traditional prototype-ish class or object > syntax... > # here... re-write everything like this... > # taco > # { > # init: function() > # { > # this.x = $("myelement"); > # Event.observe(this.x, "click", this.jojo.bindAsEventListener(this) ); > # }, > # > # jojo: function(e) > # { > # alert(Event.element(e).id); > # } > # }; > # Event.observe(window, "onload", taco.init ); > # > # ...After I looked harder I realized your main problem isn''t that > scope > # thing... it''s that "target" is not a valid property of IE''s Event > # object... lol sorry I was so blind... > # > # so using Event.element(e).id was really all you were looking for... > my > # bad!! I''m just going to leave the above code like that though so you > can > # see a working example of bindAsEventListener()... > > Hehe thanks for putting so much work into this, but to me it certainly > begs my original question. Any chance of making "e" work the same in > FF and IE? > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Ryan Gahl
2006-Jun-15 20:19 UTC
Re: Yahoo!-like Event object emulation/abstractioninPrototype?
And btw, Greg, I totally agree with you. YUI event attachment deferring only aids lazy (or downright) poor programming practices. On 6/15/06, Gregory Hill <Gregory_Hill-l9nu40+TWxQ@public.gmane.org> wrote:> > If that doesn''t work, then you''ve done something wrong somewhere. > ''Cause it works for IE for me and everyone else. > > The only advantage I see with the YUI toolkit is that it''ll defer > attaching events to elements that do not yet exist in the DOM. Big > whoop, only a sloppy programmer would try to attach an event to a > non-existant element. With Prototype, you can bind the handler function > to an object of your choice and create your own scope. I didn''t see > that option on the YUI documentation I read. (it automatically binds the > scope to the element the event acted upon, which is pretty much never > what I want). > > Greg > > > -----Original Message----- > > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs- > > bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Sam Rowe > > Sent: Thursday, June 15, 2006 12:18 PM > > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > Subject: Re: [Rails-spinoffs] Yahoo!-like Event object > > emulation/abstractioninPrototype? > > > > On Thu, Jun 15, 2006 at 11:28:03AM -0600, Gregory Hill wrote: > > # Event.observe(myelement, ''click'', myfunc.bindAsEventListener()); > > # > > # That might fix your wagon. > > > > That didn''t seem to make any difference. FF still works, IE still > > does not. I''m not branching for window.event in my callback/listener. > > > > I''m asking about a level of abstraction/emulation like is described > > in the section titled "It''s Tight because..." > > > > http://www.dustindiaz.com/yahoo-event-utility/ > > > > Any chance of getting that in Prototype? > > > > # > > # Greg > > # > > # > -----Original Message----- > > # > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > # [mailto:rails-spinoffs- > > # > bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Sam Rowe > > # > Sent: Thursday, June 15, 2006 11:24 AM > > # > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > # > Subject: Re: [Rails-spinoffs] Yahoo!-like Event object > > # > emulation/abstractionin Prototype? > > # > > > # > On Thu, Jun 15, 2006 at 08:44:13AM -0500, Ryan Gahl wrote: > > # > # Um... Event.observe() -- it''s been there all along and does > that > > # > # abstraction. > > # > > > # > Weird, I wonder why none of my event handlers work in IE. I''ll > look > > # > closer. > > # > Thanks for the info. > > # > > > # > Just cause I''m dense... I''m talking about this: > > # > > > # > Event.observe(myelement,''click'',myfunc); > > # > > > # > function myfunc(e){ > > # > // deal with e like I would in FF > > # > } > > # > > > # > Are we talking about the same thing? > > # > _______________________________________________ > > # > Rails-spinoffs mailing list > > # > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > # > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > # _______________________________________________ > > # Rails-spinoffs mailing list > > # Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > # http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > _______________________________________________ > > Rails-spinoffs mailing list > > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs