Hi. Event.observe($(''fleetAxelConfig''), ''change'', contractEdited); Event.observe($(''fleetCustomer''), ''change'', contractEdited); Event.observe($(''fleetDirectory''), ''change'', contractEdited); Event.observe($(''fleetPurch''), ''change'', contractEdited); Event.observe($(''fleetSales''), ''change'', contractEdited); Event.observe($(''fleetSort1''), ''change'', contractEdited); Event.observe($(''fleetSort2''), ''change'', contractEdited); Event.observe($(''fleetSort3''), ''change'', contractEdited); Event.observe($(''fleetSort4''), ''change'', contractEdited); Event.observe($(''fleetSort5''), ''change'', contractEdited); Event.observe($(''fleetSort6''), ''change'', contractEdited); Event.observe($(''fleetVehType''), ''change'', contractEdited); vs ''fleetAxelConfig,fleetCustomer,fleetDirectory,fleetPurch,fleetSales,fleetSort1,fleetSort2,fleetSort3,fleetSort4,fleetSort5,fleetSort6,fleetVehType''.split('','').each( function(s_ID) { Event.observe($(s_ID), ''change'', contractEdited); } ); Anyone got a preference. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Richard Quadling
2007-Jul-20 09:03 UTC
Re: Observing the same behaviour on multiple elements.
On 20/07/07, Tobias <tobias.michaelsen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 20 Jul., 10:12, "Richard Quadling" <rquadl...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > > Hi. > > > > [...] > > ''fleetAxelConfig,fleetCustomer,fleetDirectory,fleetPurch,fleetSales,fleetSort1,fleetSort2,fleetSort3,fleetSort4,fleetSort5,fleetSort6,fleetVehType''.split('','').each( > > function(s_ID) > > { > > Event.observe($(s_ID), ''change'', contractEdited); > > } > > ); > > > > I think I would prefere: > > $w(''fleetAxelConfig fleetCustomer fleetDirectory fleetPurch fleetSales > fleetSort1 fleetSort2 fleetSort3 fleetSort4 fleetSort5 fleetSort6 > fleetVehType'').each(function(s_ID) { Event.observe(s_ID, ''change'', > contractEdited); }); > > (you do not need to use the $() in Event.observe() since it will be > called internally anyway)Excellent. 2 great tips for the price of one. Thank you. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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 believe this will work just as well... $w(''fleetAxelConfig fleetCustomer fleetDirectory fleetPurch fleetSales fleetSort1 fleetSort2 fleetSort3 fleetSort4 fleetSort5 fleetSort6 fleetVehType'').invoke(''observe'', ''change'', contractEdited); -- View this message in context: http://www.nabble.com/Observing-the-same-behaviour-on-multiple-elements.-tf4115678.html#a11706977 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 -~----------~----~----~----~------~----~------~--~---
On Jul 20, 2007, at 2:54 AM, Tobias wrote:> $w(''fleetAxelConfig fleetCustomer fleetDirectory fleetPurch fleetSales > fleetSort1 fleetSort2 fleetSort3 fleetSort4 fleetSort5 fleetSort6 > fleetVehType'').each(function(s_ID) { Event.observe(s_ID, ''change'', > contractEdited); });I realize this is all about personal preference, but why pass a string literal to be converted to an array? Why not just pass the array literal? e.x. [''fleetAxelConfig'', ''fleetCustomer'', ''fleetDirectory'', ... ].each ( function(el) { // ... }); TAG --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
because $w extends an array? Otherwise you would still have to do smth like $A([blah1, blah2, blah3]).each(...) -- View this message in context: http://www.nabble.com/Observing-the-same-behaviour-on-multiple-elements.-tf4115678.html#a11709624 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 -~----------~----~----~----~------~----~------~--~---
On 20 Jul., 14:08, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I believe this will work just as well... > > $w(''fleetAxelConfig fleetCustomer fleetDirectory fleetPurch fleetSales > fleetSort1 fleetSort2 fleetSort3 fleetSort4 fleetSort5 fleetSort6 > fleetVehType'').invoke(''observe'', ''change'', contractEdited);You would need to put .map($) in between $w() and .invoke() -- otherwise you will be calling observe() on a lot of strings ;-) Another alternative - if http://dev.rubyonrails.org/ticket/9034 is accepted - would be: $w(...).each(Event.observe.rcurry(''change'', contractEdited)); --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Kangax, There is no need to "extend" arrays... $A is useful to transform collections (such as DOM nodes, or arguments of an function) into an array. Nothing else. What''s going to be missing however is actually turning the element ids into elements... You''ll need to run them through $() at some point if you want to be able to invoke observe on them. Best, Tobie On Jul 20, 10:51 am, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> because $w extends an array? > > Otherwise you would still have to do smth like > > $A([blah1, blah2, blah3]).each(...) > -- > View this message in context:http://www.nabble.com/Observing-the-same-behaviour-on-multiple-elemen... > 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 -~----------~----~----~----~------~----~------~--~---
What a shame... Just looked at the source and realized that Array.prototype indeed gets extended with Enumerable... for some reason I always thought that this should be done explicitly... Well, thanks for clarification, Tobie Best, kangax -- View this message in context: http://www.nabble.com/Observing-the-same-behaviour-on-multiple-elements.-tf4115678.html#a11715165 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 -~----------~----~----~----~------~----~------~--~---
no problem! On Jul 20, 4:07 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What a shame... > Just looked at the source and realized that Array.prototype indeed gets > extended with Enumerable... for some reason I always thought that this > should be done explicitly... > > Well, thanks for clarification, Tobie > > Best, > > kangax > > -- > View this message in context:http://www.nabble.com/Observing-the-same-behaviour-on-multiple-elemen... > 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 -~----------~----~----~----~------~----~------~--~---
cleaner maybe... I don''t like doing everything on one line of code: var names [''AxelConfig'',''Customer'',''Directory'',''Purch'',''Sales'',''Sort1'',''Sort2'',''Sort3'',''Sort4'',''Sort5'',''Sort6'',''VehType'']; var addPrefix = function(prefix){ return function(s){ prefix+s;}}; names.map(addPrefix(''fleet'')).invoke(''observe'', ''change'', contractEdited); --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
http://pastie.caboo.se/80806 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Richard Quadling wrote:> ... > ''fleetAxelConfig,fleetCustomer,fleetDirectory,fleetPurch,fleetSales,fleetSort1,fleetSort2,fleetSort3,fleetSort4,fleetSort5,fleetSort6,fleetVehType''.split('','').each( > function(s_ID) > { > Event.observe($(s_ID), ''change'', contractEdited); > } > ); > ... > >Looks like my reply is a little late, but this seems like a good situation for using $$(). Maybe something like: $$(''#fleet select'').invoke(''observe'', ''change'', contractEdited); If your html is more complex, you could add a class to each of the elements and use something like $$(''#fleet .contract''); - Ken Snyder --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Richard Quadling
2007-Jul-23 08:18 UTC
Re: Observing the same behaviour on multiple elements.
On 21/07/07, Ken Snyder <kendsnyder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Richard Quadling wrote: > > ... > > ''fleetAxelConfig,fleetCustomer,fleetDirectory,fleetPurch,fleetSales,fleetSort1,fleetSort2,fleetSort3,fleetSort4,fleetSort5,fleetSort6,fleetVehType''.split('','').each( > > function(s_ID) > > { > > Event.observe($(s_ID), ''change'', contractEdited); > > } > > ); > > ... > > > > > Looks like my reply is a little late, but this seems like a good > situation for using $$(). Maybe something like: > > $$(''#fleet select'').invoke(''observe'', ''change'', contractEdited); > > If your html is more complex, you could add a class to each of the > elements and use something like $$(''#fleet .contract''); > > - Ken SnyderUsing ... [''AxelConfig'',''Customer'',''Directory'',''Purch'',''Sales'',''Sort1'',''Sort2'',''Sort3'',''Sort4'',''Sort5'',''Sort6'',''VehType''].each( function(s_ID) { Event.observe(''fleet'' + s_ID, ''change'', contractEdited); } ); seems to be working for me just fine. Strangely enough, if I wrap this with console.time(''Attach Events), console.timeEnd(''Attach Events''), it seems to take 0ms. So, hey! Pretty fast! Ha ha. My original code took 15.63ms and made 76 calls. So I suspect, I''m not doing SOMETHING quite right. It works though. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Richard Quadling
2007-Jul-24 08:28 UTC
Re: Observing the same behaviour on multiple elements.
On 23/07/07, Richard Quadling <rquadling-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 21/07/07, Ken Snyder <kendsnyder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Richard Quadling wrote: > > > ... > > > ''fleetAxelConfig,fleetCustomer,fleetDirectory,fleetPurch,fleetSales,fleetSort1,fleetSort2,fleetSort3,fleetSort4,fleetSort5,fleetSort6,fleetVehType''.split('','').each( > > > function(s_ID) > > > { > > > Event.observe($(s_ID), ''change'', contractEdited); > > > } > > > ); > > > ... > > > > > > > > Looks like my reply is a little late, but this seems like a good > > situation for using $$(). Maybe something like: > > > > $$(''#fleet select'').invoke(''observe'', ''change'', contractEdited); > > > > If your html is more complex, you could add a class to each of the > > elements and use something like $$(''#fleet .contract''); > > > > - Ken Snyder > > Using ... > [''AxelConfig'',''Customer'',''Directory'',''Purch'',''Sales'',''Sort1'',''Sort2'',''Sort3'',''Sort4'',''Sort5'',''Sort6'',''VehType''].each( > function(s_ID) > { > Event.observe(''fleet'' + s_ID, ''change'', contractEdited); > } > ); > > seems to be working for me just fine. Strangely enough, if I wrap this > with console.time(''Attach Events), console.timeEnd(''Attach Events''), > it seems to take 0ms. > > So, hey! Pretty fast! Ha ha. My original code took 15.63ms and made 76 calls. > > So I suspect, I''m not doing SOMETHING quite right. It works though.$(''fleetForm'').getElements().each( function(s_ID) { if (''fleetContract'' != s_ID) { Event.observe(s_ID, ''change'', contractEdited); } } ); Is a little neater as I added some more elements to the form. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---