Sam Rowe
2006-Jun-15 13:38 UTC
Yahoo!-like Event object emulation/abstraction in Prototype?
Hi, I was reading about the Yahoo! library recently and was really excited by the idea that I wouldn''t have to branch for IE in my event handlers. Is there any chance that such abstraction will come to Prototype? Thanks, Sam
Ryan Gahl
2006-Jun-15 13:44 UTC
Re: Yahoo!-like Event object emulation/abstraction in Prototype?
Um... Event.observe() -- it''s been there all along and does that abstraction. On 6/15/06, Sam Rowe <scriptaculous-NA8LtxyqzOtZdbSWXsKqFg@public.gmane.org> wrote:> > Hi, > > I was reading about the Yahoo! library recently and was really > excited by the idea that I wouldn''t have to branch for IE in my > event handlers. Is there any chance that such abstraction will come > to Prototype? > > 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
Sam Rowe
2006-Jun-15 17:23 UTC
Re: Yahoo!-like Event object emulation/abstraction in 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?
Ryan Gahl
2006-Jun-15 17:33 UTC
Re: Yahoo!-like Event object emulation/abstraction in Prototype?
Ahh... the event object itself... what you need is proto''s bindAsEventListener method. myClass = Class.create(); myClass.prototype { initialize: function() { //initialization code... Event.observe(myElement, "click", this.myElementClicked.binAsEventListener (this)); }, myElementClicked: function(e) { //use e }, }; The above will work cross-browser. Otherwise, in the example you gave, you can do the following in myFunc... function myFunc(e){ if (!e) e = window.event; //use e } On 6/15/06, Sam Rowe <scriptaculous-NA8LtxyqzOtZdbSWXsKqFg@public.gmane.org> wrote:> > 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
Ryan Gahl
2006-Jun-15 17:34 UTC
Re: Yahoo!-like Event object emulation/abstraction in Prototype?
i had a typo in there, and Greg beat me to it... yep Greg''s example should work perfectly too On 6/15/06, Ryan Gahl <ryan.gahl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Ahh... the event object itself... what you need is proto''s > bindAsEventListener method. > > myClass = Class.create(); > myClass.prototype > { > initialize: function() > { > //initialization code... > Event.observe(myElement, "click", this.myElementClicked.binAsEventListener > (this)); > }, > > myElementClicked: function(e) > { > //use e > }, > }; > > The above will work cross-browser. Otherwise, in the example you gave, you > can do the following in myFunc... > > function myFunc(e){ > if (!e) e = window.event ; > //use e > } > > On 6/15/06, Sam Rowe <scriptaculous-NA8LtxyqzOtZdbSWXsKqFg@public.gmane.org> wrote: > > > 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