It''s possible that I''ve missed a discussion on this already; if so, I apologize. I''ve been doing a lot of work recently with Prototype''s built-in CSS selector capability, which has all been very helpful and very nice. What I''ve had difficulty with is passing CSS selectors to script.aculo.usobjects. For example, given this: <div id="foo"> <p>Blah blah</p> <p class="second">Hello, second paragraph.</p> </div> ... I''m not able to trigger a highlight effect on *only* the second paragraph easily. Ideally, I''d be able to do something like: new Effect.Highlight($$(''div#foo p.second''), {"duration":1}); ... however, the best I''ve been able to manage thus far is highlighting the entire div, or giving the second paragraph a specific ID then highlighting that. I feel like there''s something obvious I''m missing here. Can anyone see what that might be? Thanks! -Clay -- Killersoft.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 -~----------~----~----~----~------~----~------~--~---
My guess is that $$() always returns an array even if there''s only one thing in that array. If you''re absolutely sure there will only be one item coming back to you, maybe you could say: $$(''div#foo p.second'')[0] --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 8/28/06, John Beppu <john.beppu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > My guess is that $$() always returns an array even if there''s only one > thing in that array. If you''re absolutely sure there will only be one > item coming back to you, maybe you could say: > > $$(''div#foo p.second'')[0]John, you''re right -- thanks. that''s helpful. $$(..) does indeed return an instance of $A(). So, $$(''div#foo p.second'').first() would work the same way. It seems like there''s no easy way to pass a $$(..) selector result to a method that takes input and runs it through $(..). Seems like $$(''div#foo p.second'').join() should do it, but it doesn''t seem to. new Effect.Highlight($$(''div#foo p.second'').join(), {"duration": 1}); ... seems like it should highlight all paragraphs with a class of .second inside the div #foo for one second. But, doesn''t seem to work that way. Using first() works, though. The same end result can be achieved with: $$(''div#foo p.second'').each(function(el) {new Effect.Highlight(el, {"duration": 1});}); ... but that seems a bit less clean to me personally, and is a little more complicated to generate on the fly. However, perhaps that''s the only way to do it without extending Prototype. John, can you (or anyone else) see another way similar to what I''m suggesting with join(), short of flipping it around to the $$().each(...) approach? Thanks! -Clay -- Killersoft.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 -~----------~----~----~----~------~----~------~--~---
On 8/28/06, Killersoft <killersoft-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> $$(''div#foo p.second'').each(function(el) {new Effect.Highlight(el, > {"duration": 1});}); > > ... but that seems a bit less clean to me personally, and is a little more > complicated to generate on the fly. However, perhaps that''s the only way to > do it without extending Prototype. > > John, can you (or anyone else) see another way similar to what I''m > suggesting with join(), short of flipping it around to the $$().each(...) > approach?Use jQuery. ;-) I love prototype and scriptaculous, but this is the kind of thing that jQuery shines at. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 8/28/06, Killersoft <killersoft-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > The same end result can be achieved with: > > $$(''div#foo p.second'').each(function(el) {new Effect.Highlight(el, > {"duration": 1});}); > > ... but that seems a bit less clean to me personally, and is a little more > complicated to generate on the fly. However, perhaps that''s the only way to > do it without extending Prototype. >Sorry to reply to my own post -- a better example of why I''m trying to do without without looping through each() came to mind about an hour after sending my last message. Let''s say that I want an Ajax.Updater() to update more than one element for some reason. Using a $$() selector with each() around that Ajax.Updater() call would call the server for each element matching the $$() selector ... which could be significantly more times than is desired or necessary. In this instance, I know I could do an Ajax.Request() with an onSuccess callback that would update some group of elements determined by a $$() selector ... but that''s not as nice as something like: new Ajax.Updater($$(''li.foo'').join(), [url], [options]); ... which would then update every <li class="foo"> element on the page with the result. Not sure that I''d want to do this, or that it would make sense -- but given the usage of $(), I keep wanting to use $$() in a similar fashion, and am just trying to determine what, if anything, is possible that I''m overlooking. Thanks again, Clay -- Killersoft.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 -~----------~----~----~----~------~----~------~--~---
On 8/29/06, John Beppu <john.beppu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Use jQuery. ;-) > > I love prototype and scriptaculous, but this is the kind of thing that > jQuery shines at.Hah! Fair enough. :) I''d seen recently that jQuery could be used with Prototype and script.aculo.us to essentially allow $() to be used as $() AND/OR $$() are use in Prototype, but didn''t want to make the leap to yet another library if it could be avoided. But, perhaps that''s the way to go until some possible future that includes that level interchangability within Prototype. Thanks, John. :) -Clay -- Killersoft.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 -~----------~----~----~----~------~----~------~--~---
My own experience with mixing jQuery with prototype is that they don''t mix too well no matter what they claim in their FAQ. In prototype, when you use $(), you exepct to get back a DOM element, and a lot of code I''ve written relies on this assumption. In jQuery, this is never the case. You *ALWAYS* get a jQuery object back. In light of this, how compatible can they really be with each other? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
another way of doin'' that is: $$(''my#selec.tor'').invoke(''visualEffect'', ''highlight'', { duration: 1 }); brgds On 8/29/06, Killersoft <killersoft-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On 8/28/06, John Beppu <john.beppu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > My guess is that $$() always returns an array even if there''s only one > > thing in that array. If you''re absolutely sure there will only be one > > item coming back to you, maybe you could say: > > > > $$(''div#foo p.second '')[0] > > > John, you''re right -- thanks. that''s helpful. $$(..) does indeed return an > instance of $A(). > > So, $$(''div#foo p.second'').first() would work the same way. > > It seems like there''s no easy way to pass a $$(..) selector result to a > method that takes input and runs it through $(..). > > Seems like $$(''div#foo p.second'').join() should do it, but it doesn''t seem > to. > > new Effect.Highlight($$(''div#foo p.second'').join(), {"duration": 1}); > > ... seems like it should highlight all paragraphs with a class of .second > inside the div #foo for one second. But, doesn''t seem to work that way. > Using first() works, though. > > The same end result can be achieved with: > > $$(''div#foo p.second'').each(function(el) {new Effect.Highlight(el, > {"duration": 1});}); > > ... but that seems a bit less clean to me personally, and is a little more > complicated to generate on the fly. However, perhaps that''s the only way to > do it without extending Prototype. > > John, can you (or anyone else) see another way similar to what I''m > suggesting with join(), short of flipping it around to the $$().each(...) > approach? > > Thanks! > -Clay > > > -- > Killersoft.com > > > >-- Siegfried Puchbauer --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 8/29/06, Siegfried Puchbauer <siegfried.puchbauer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > another way of doin'' that is: > > $$(''my#selec.tor'').invoke(''visualEffect'', ''highlight'', { duration: 1 }); > >Sweet! That''s very helpful as well, thank you Siegfried! Regards, Clay -- Killersoft.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 -~----------~----~----~----~------~----~------~--~---