What does the $$ do? Also, what is the best way to do getElementsbyClassName using prototype? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey Keith, Keith a écrit :> What does the $$ do? Also, what is the best way to do > getElementsbyClassName using prototype?Until 1.5_rc1, you had: document.getElementsByClassName(''yourClassname''); Since RC1, I believe you have it at the Element level. So either: Element.getElementsByClassName(''yourId'', ''yourClassname''); or: $(''yourId'').getElementsByClassName(''yourClassName''); As for $$, it uses DOM traversal to implement a selection based on a *CSS rule*. However, it custom-parses the rule, so it is not isomorphic to your browser''s CSS parser. It currently supports the following selectors: - descendant ('' '') - class (''.xyz'') - id (''#xyz'') - attributes (full ''[...]'' feature set, including ''='', ''!='', ''~='' and ''|='' operators) -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey Keith, Keith a écrit :> What does the $$ do? Also, what is the best way to do > getElementsbyClassName using prototype?Until 1.5_rc1, you had: document.getElementsByClassName(''yourClassname''); Since RC1, I believe you have it at the Element level. So either: Element.getElementsByClassName(''yourId'', ''yourClassname''); or: $(''yourId'').getElementsByClassName(''yourClassName''); As for $$, it uses DOM traversal to implement a selection based on a *CSS rule*. However, it custom-parses the rule, so it is not isomorphic to your browser''s CSS parser. It currently supports the following selectors: - descendant ('' '') - class (''.xyz'') - id (''#xyz'') - attributes (full ''[...]'' feature set, including ''='', ''!='', ''~='' and ''|='' operators) -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi May i add that $$ is a little slower the getElementsByClassName. Especially if you have a large source and alot of elements. If you have the choice i would suggest to go for getElementsByClassName. PS: i expierienced that in FFox. changes were dramatically, but it depends on enviroment anyhow.. take it as sidenote and try for yourself. Regards, Kjell Bublitz 2006/10/4, Christophe Porteneuve aka TDD <tdd@tddsworld.com>:> > > Hey Keith, > > Keith a écrit : > > What does the $$ do? Also, what is the best way to do > > getElementsbyClassName using prototype? > > Until 1.5_rc1, you had: > > document.getElementsByClassName('yourClassname'); > > Since RC1, I believe you have it at the Element level. > > So either: > > Element.getElementsByClassName('yourId', 'yourClassname'); > > or: > > $('yourId').getElementsByClassName('yourClassName'); > > As for $$, it uses DOM traversal to implement a selection based on a > *CSS rule*. However, it custom-parses the rule, so it is not isomorphic > to your browser's CSS parser. It currently supports the following > selectors: > > - descendant (' ') > - class ('.xyz') > - id ('#xyz') > - attributes (full '[...]' feature set, including '=', '!=', '~=' and > '|=' operators) > > -- > Christophe Porteneuve aka TDD > tdd@tddsworld.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@googlegroups.com To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Could you give some examples of using $$? I don''t quite understand your description. Is there any documentation on it? -----Original Message----- From: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Christophe Porteneuve aka TDD Sent: Wednesday, October 04, 2006 10:50 AM To: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Subject: [Rails-spinoffs] Re: $$ and getElementsbyClassName Hey Keith, Keith a écrit :> What does the $$ do? Also, what is the best way to do > getElementsbyClassName using prototype?Until 1.5_rc1, you had: document.getElementsByClassName(''yourClassname''); Since RC1, I believe you have it at the Element level. So either: Element.getElementsByClassName(''yourId'', ''yourClassname''); or: $(''yourId'').getElementsByClassName(''yourClassName''); As for $$, it uses DOM traversal to implement a selection based on a *CSS rule*. However, it custom-parses the rule, so it is not isomorphic to your browser''s CSS parser. It currently supports the following selectors: - descendant ('' '') - class (''.xyz'') - id (''#xyz'') - attributes (full ''[...]'' feature set, including ''='', ''!='', ''~='' and ''|='' operators) -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Do you mean prototype 1.5_rc1? Where can I download that? I only see 1.4.0. -----Original Message----- From: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Christophe Porteneuve aka TDD Sent: Wednesday, October 04, 2006 10:50 AM To: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Subject: [Rails-spinoffs] Re: $$ and getElementsbyClassName Hey Keith, Keith a écrit :> What does the $$ do? Also, what is the best way to do > getElementsbyClassName using prototype?Until 1.5_rc1, you had: document.getElementsByClassName(''yourClassname''); Since RC1, I believe you have it at the Element level. So either: Element.getElementsByClassName(''yourId'', ''yourClassname''); or: $(''yourId'').getElementsByClassName(''yourClassName''); As for $$, it uses DOM traversal to implement a selection based on a *CSS rule*. However, it custom-parses the rule, so it is not isomorphic to your browser''s CSS parser. It currently supports the following selectors: - descendant ('' '') - class (''.xyz'') - id (''#xyz'') - attributes (full ''[...]'' feature set, including ''='', ''!='', ''~='' and ''|='' operators) -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Never mind. I found 1.5_rc1 with a search. Keith Davis wrote:> Do you mean prototype 1.5_rc1? Where can I download that? I only see 1.4.0. > > -----Original Message----- > From: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > [mailto:rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Christophe > Porteneuve aka TDD > Sent: Wednesday, October 04, 2006 10:50 AM > To: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > Subject: [Rails-spinoffs] Re: $$ and getElementsbyClassName > > > Hey Keith, > > Keith a écrit : > > What does the $$ do? Also, what is the best way to do > > getElementsbyClassName using prototype? > > Until 1.5_rc1, you had: > > document.getElementsByClassName(''yourClassname''); > > Since RC1, I believe you have it at the Element level. > > So either: > > Element.getElementsByClassName(''yourId'', ''yourClassname''); > > or: > > $(''yourId'').getElementsByClassName(''yourClassName''); > > As for $$, it uses DOM traversal to implement a selection based on a *CSS > rule*. However, it custom-parses the rule, so it is not isomorphic to your > browser''s CSS parser. It currently supports the following > selectors: > > - descendant ('' '') > - class (''.xyz'') > - id (''#xyz'') > - attributes (full ''[...]'' feature set, including ''='', ''!='', ''~='' and ''|='' > operators) > > -- > Christophe Porteneuve aka TDD > tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey, Keith Davis a écrit :> Do you mean prototype 1.5_rc1? Where can I download that? I only see 1.4.0.Yup, it won''t change until 1.5 final. But there''s been a WORLD of upgrades. You can 1.5.0_rc1 from script.aculo.us [1] (''includes it + a couple patches), or get the SVN version from the Spinoffs SVN [2]. [1] http://script.aculo.us/downloads [2] svn co http://dev.rubyonrails.org/svn/rails/spinoffs -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey there! Keith Davis a écrit :> Could you give some examples of using $$? I don''t quite understand your > description. Is there any documentation on it?a) my upcoming book documents it, but it''s going to be in French! :-) b) basically, $$ takes a *CSS RULE*. ''know CSS? You know $$. Note that $$, like $, automagically extends the elements it returns, which means all Element.blah(elt, ...) methods are available "first-person" on resulting elements: $(''yourId'').blah(...); $$(''#container .yourClass[lang!=en]'').each(function(e) { e.blah(...); }); As I said a couple times, if you''re just going for a single CSS class name, use getElementsByClassName (either at the document or element level) instead. -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I personally never use $$ because when I tried it, it was noticeably slower than other methods. My solution to grabbing elements from a large DOM was to override document.getElementsByClassName with a function that adds an extra parameter, tagName. This allows it to filter elements by tagName before applying any other filter rather than grabbing EVERY element in the DOM. From my unscientific tests this is considerably faster. Example: you have a complex conglomeration of nested div, span, ul, li, a elements that together compose a nice tree (with parent ''tree1''). You want to get all of the drag handles at once. Rather than document.getElementsByClassName(''handle'',''tree1''); I would use document.getElementsByClassName(''handle'',''tree1'',''span''); Already that cuts out probably half or more of the elements. That''s half as many regular expression matches required for a few extra characters of code, and it is backward compatible with the original. I have no idea why the original override in prototype doesn''t do this, that getElementsByTagName(''*'') just stuck out to me like a sore thumb as a prime candidate for an easy improvement. Of course if you want to filter by class and tag only you can document.getElementsByClassName(''handle'',null,''span''); //or document.body but that is longer to type.. ---------- /* override the Prototype function, this one adds a ''tag'' argument and uses xpath where possible */ document.getElementsByClassName = function(className, parent, tagName) { if(document.evaluate && $(parent) && $(parent).documentElement){ var xpathResult = document.evaluate("//"+(tagName||''*'')+"[@class=''"+className+"'']", $(parent), null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); var outArray = new Array(); for(var i=0; i<xpathResult.snapshotLength;i++){ outArray[i] = xpathResult.snapshotItem(i);} return $A(outArray); }else{ var children = ($(parent) || document).getElementsByTagName((tagName || ''*'')); return $A(children).inject([], function(elements, child) { if (child.className.match(new RegExp("(^|\\s)" + className + "(\\s|$)"))) elements.push(Element.extend(child)); return elements; }); } } Colin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey Colin! Colin Mollenhour a écrit :> I personally never use $$ because when I tried it, it was noticeably > slower than other methods. My solution to grabbing elements from a > large DOM was to override document.getElementsByClassName with a > function that adds an extra parameter, tagName. This allows it to > filter elements by tagName before applying any other filter rather > than grabbing EVERY element in the DOM.I think there''s some patch in trac that goes the same way, but I''m not sure.> I have no idea why the original override in prototype doesn''t do > this, that getElementsByTagName(''*'') just stuck out to me like a sore > thumb as a prime candidate for an easy improvement.I''d be interested to get an answer on this from Sam (although he doesn''t seem like he''s very present in the community) or Thomas (more likely). -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---