is there an easier way then looping through the result of Element.siblings(); to check and see if an item has a sibling with a certain classname? --~--~---------~--~----~------------~-------~--~----~ 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 Thu, Jun 19, 2008 at 4:35 PM, louis w <louiswalch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > is there an easier way then looping through the result of > Element.siblings(); to check and see if an item has a sibling with a > certain classname?Dunno if it''s faster per se, but el.siblings().match(''.className'') looks nice :) :Dan --~--~---------~--~----~------------~-------~--~----~ 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 Thu, Jun 19, 2008 at 4:41 PM, Dan Dorman <dan.dorman-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Dunno if it''s faster per se, but el.siblings().match(''.className'') looks nice :)But, y''know, too bad it doesn''t work. Sorry about that. You could try chaining findAll after siblings, but that kinda what you''re trying to avoid, huh? :Dan --~--~---------~--~----~------------~-------~--~----~ 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, not sure what Array#match is, but #grep could do this nicely : ) $(someElement).siblings().grep(new Selector(''.someClass'')); - kangax On Jun 19, 6:41 pm, "Dan Dorman" <dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thu, Jun 19, 2008 at 4:35 PM, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > is there an easier way then looping through the result of > > Element.siblings(); to check and see if an item has a sibling with a > > certain classname? > > Dunno if it''s faster per se, but el.siblings().match(''.className'') looks nice :) > > :Dan--~--~---------~--~----~------------~-------~--~----~ 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 Thu, Jun 19, 2008 at 4:56 PM, kangax <kangax-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Dan, > not sure what Array#match is, but #grep could do this nicely : ) > > $(someElement).siblings().grep(new Selector(''.someClass''));Yep, I''m not sure what I was smoking exactly, but I think it had some jQuery in it :) By way of penance, some extra credit work. Louis, If you find yourself needing this functionality a lot, you could always augment the behavior of siblings using Function.wrap: Element.addMethods({ siblings: Element.siblings.wrap(function(proceed, element, selector) { var sibs = proceed.call(this, element); return selector ? sibs.grep(selector instanceof Selector ? selector : new Selector(selector)) : sibs; }) }); :Dan --~--~---------~--~----~------------~-------~--~----~ 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 actually find certain traversal methods too limiting. We could easily make siblings/ancestors/etc. accept an optional selector/ iterator argument (or even both, where function would be treated as iterator and string as selector). This also leads to a better performance. I cooked a patch for this some time ago http://dev.rubyonrails.org/ticket/11143 Does this make sense? - kangax On Jun 19, 7:13 pm, "Dan Dorman" <dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thu, Jun 19, 2008 at 4:56 PM, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Dan, > > not sure what Array#match is, but #grep could do this nicely : ) > > > $(someElement).siblings().grep(new Selector(''.someClass'')); > > Yep, I''m not sure what I was smoking exactly, but I think it had some > jQuery in it :) > > By way of penance, some extra credit work. Louis, If you find yourself > needing this functionality a lot, you could always augment the > behavior of siblings using Function.wrap: > > Element.addMethods({ > siblings: Element.siblings.wrap(function(proceed, element, selector) { > var sibs = proceed.call(this, element); > return selector ? > sibs.grep(selector instanceof Selector ? > selector : > new Selector(selector)) : > sibs; > }) > > }); > > :Dan--~--~---------~--~----~------------~-------~--~----~ 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 Thu, Jun 19, 2008 at 7:36 PM, kangax <kangax-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I actually find certain traversal methods too limiting. We could > easily make siblings/ancestors/etc. accept an optional selector/ > iterator argument (or even both, where function would be treated as > iterator and string as selector). This also leads to a better > performance. I cooked a patch for this some time ago > http://dev.rubyonrails.org/ticket/11143 Does this make sense?It makes a ton of sense, since before I even started work on that last snippet, I was wondering why that sort of functionality wasn''t already in Prototype. That ancestors, siblings, et al, inherit from the same method would seem to make it exceptionally low-hanging fruit. Any idea on whether your patch will make it into the next release? :Dan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---