Take a look at this: http://img238.imageshack.us/img238/5752/prototypeselectorduplicatesld7.png The image shows that $$ returns duplicates, is it supposed to do that, or is my CSS/HTML wrong? Thanks, Brian -- ===========================Brian Peiris Brampton, Ontario, Canada brianpeiris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org or brianpeiris-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org =========================== _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Take a look at this: http://img238.imageshack.us/img238/5752/prototypeselectorduplicatesld7.png The image shows that $$ returns duplicates, is it supposed to do that, or is my CSS/HTML wrong? I don''t understand your image, but glancing at the HTML, I can see that ID node_3_children satisfies $$(''#tree .node .nodeChildren'') once for nodeID node_1, and again for nodeID node_3. Sam _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
yes, I expect $$(''#tree .node .nodeChildren'') to return exactly those two elements, but if you look along the bottom of the image where I''ve called $$(''#tree .node .nodeChildren'') in the Javascript Console you''ll see that it returns node_3_children twice On 8/13/06, Sam <sam.google-Uc2IQQBAS6sAvxtiuMwx3w@public.gmane.org> wrote:> > Take a look at this: > http://img238.imageshack.us/img238/5752/prototypeselectorduplicatesld7.png > > The image shows that $$ returns duplicates, is it supposed to do that, or > is my CSS/HTML wrong? > > I don''t understand your image, but glancing at the HTML, I can see that ID > node_3_children satisfies $$(''#tree .node .nodeChildren'') once for nodeID > node_1, and again for nodeID node_3. > > Sam > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > >-- ===========================Brian Peiris Brampton, Ontario, Canada brianpeiris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org or brianpeiris-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org =========================== _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Funny... I don''t know if you are not understanding me, or if I am not understanding you... I just reviewed your graphic, and I see at the bottom, the output of $$ which exactly describes what I posted below. Maybe I wasn''t clear, and I apologies in advance that I''m about to write further on the same thing. Some nodes satisfy the criteria #tree .node .nodeChildren more than once, and as a result, will be output more than once by the $$ function. The node id node_3_children satisfies the criteria $(''#tree .node .nodeChildren'') once for nodeID node_1, and once again for nodeID node_3. The problem here is #tree .node .nodeChildren allows any number of elements to appear between these attributes: e.g., there may be 3 <div class="node">, all of class .node, between #tree .node and .nodeChildren. If you want to specify direct descendents only, you could try $$(''#tree > .node > .nodeChildren''), but I don''t know if $$ supports direct descendents. It probably does, but I''ve never had the opportunity to test. In my experience, nothing works until you see it work. Another solution if you want the nodeChildren only once, you could use $$(''.nodeChildren'') which will match each .nodeChildren only once. Sorry if I''m not understanding your concern. Maybe someone else can clear up the confusion. Sam _____ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Brian Peiris Sent: Sunday, August 13, 2006 12:53 AM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails-spinoffs] Prototype $$ Question yes, I expect $$(''#tree .node .nodeChildren'') to return exactly those two elements, but if you look along the bottom of the image where I''ve called $$(''#tree .node .nodeChildren'') in the Javascript Console you''ll see that it returns node_3_children twice On 8/13/06, Sam <sam.google-Uc2IQQBAS6sAvxtiuMwx3w@public.gmane.org> wrote: Take a look at this: http://img238.imageshack.us/img238/5752/prototypeselectorduplicatesld7.png The image shows that $$ returns duplicates, is it supposed to do that, or is my CSS/HTML wrong? I don''t understand your image, but glancing at the HTML, I can see that ID node_3_children satisfies $$(''#tree .node .nodeChildren'') once for nodeID node_1, and again for nodeID node_3. Sam _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org <mailto:Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs -- ===========================Brian Peiris Brampton, Ontario, Canada brianpeiris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org or brianpeiris-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org ============================ _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
On 8/13/06, Sam wrote:> The node id node_3_children satisfies the criteria $(''#tree .node > .nodeChildren'') once for nodeID node_1, and once again for nodeID node_3. > The problem here is #tree .node .nodeChildren allows any number of elements > to appear between these attributes: e.g., there may be 3 <div > class="node">, all of class .node, between #tree .node and .nodeChildren. > If you want to specify direct descendents only, you could try $$(''#tree > > .node > .nodeChildren''), but I don''t know if $$ supports direct descendents. > It probably does, but I''ve never had the opportunity to test. In my > experience, nothing works until you see it work.Sam, I think his point is that he wants a unique list from $$. It doesn''t matter if there are ten ways to get to the same element, it should be checking to make sure an item is NOT already in the list before pushing it onto the list. You''d find it very frustrating if getElementsByTagName() returned the same element more than once in the result list. That''s because you usually want to *do* something with the items in the list, and you don''t want to process any of them more than once. If getElementsByTagName() did return some elements more than once, and the browser vendors explained that the reason is because of how they build the list, we''d all be quite disgusted. In this case, knowing WHY $$ returns the same element twice doesn''t matter... that''s not what we expect the function to do. Looks like a bug to me, Brian. Seth
Hey Sam, Seth, thank you both for your replies. Seth: Now I see why $$(''#tree .node .nodeChildren'') returns duplicates, and it looks like $$(''#tree > .node > .nodeChildren'') doesn''t work ($$ probably doesn''t support direct decendents yet, it returns and empty array). $$(''.nodeChildren'') wouldn''t work for me, elements with class ''.nodeChildren'' could be under two different trees (''#tree1'' and ''#tree2'' for example). Sam: I agree with you, I discovered this problem while using event:Selectors to toggle an element on a click event, it took me a while to figure out that the toggle function was being called twice. It is un-intuitive that $$returns duplicates, even though it is technically correct, I don''t see where it would be useful, especially since it doesn''t support direct descendants yet. Perhaps it is a bug, or perhaps we just have to wait till more advanced CSS selectors are supported Anyway, I just added few lines to the $$ function to return a unique array. If anyone wants to take a look at it quickly, there''s probably a better way to do it (using prototype''s array functions) function $$() { var nodes = $A(arguments).map(function(expression) { return expression.strip().split(/\s+/).inject([null], function(results, expr) { var selector = new Selector(expr); return results.map(selector.findElements.bind(selector)).flatten(); }); }).flatten(); var uniqueNodes =[]; var i=0; for(i=0;i<nodes.length;i++){ if(uniqueNodes.indexOf(nodes[i])==-1) { uniqueNodes.push(nodes[i]); } } return uniqueNodes; } Thanks, Brian On 8/13/06, Seth Dillingham <seth.dillingham-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 8/13/06, Sam wrote: > > > The node id node_3_children satisfies the criteria $(''#tree .node > > .nodeChildren'') once for nodeID node_1, and once again for nodeID > node_3. > > The problem here is #tree .node .nodeChildren allows any number of > elements > > to appear between these attributes: e.g., there may be 3 <div > > class="node">, all of class .node, between #tree .node and > .nodeChildren. > > If you want to specify direct descendents only, you could try $$(''#tree > > > > .node > .nodeChildren''), but I don''t know if $$ supports direct > descendents. > > It probably does, but I''ve never had the opportunity to test. In my > > experience, nothing works until you see it work. > > Sam, > > I think his point is that he wants a unique list from $$. It doesn''t > matter if there are ten ways to get to the same element, it should be > checking to make sure an item is NOT already in the list before > pushing it onto the list. > > You''d find it very frustrating if getElementsByTagName() returned the > same element more than once in the result list. That''s because you > usually want to *do* something with the items in the list, and you > don''t want to process any of them more than once. > > If getElementsByTagName() did return some elements more than once, and > the browser vendors explained that the reason is because of how they > build the list, we''d all be quite disgusted. In this case, knowing WHY > $$ returns the same element twice doesn''t matter... that''s not what we > expect the function to do. > > Looks like a bug to me, Brian. > > Seth > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-- ===========================Brian Peiris Brampton, Ontario, Canada brianpeiris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org or brianpeiris-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org =========================== _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
woops, mixed up your names, sorry :) _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
> > Looks like a bug to me, Brian.I gave two examples of css selectors which ensure that the same node wouldn''t be returned more than once. Seemed more productive than declaring the software broken. Sam
And the little more elegant, prototypish way ;) Object.extend(Array.prototype, { unique: function() { return this.inject([], function(array, value) { if (!array.include(value)) array.push(value); return array; }); } }); _$$_old = $$; function $$() {return _$$_old.apply(null, arguments).unique()} Ciao Martin On 8/13/06, Brian Peiris <brianpeiris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hey Sam, Seth, > thank you both for your replies. > Seth: > Now I see why $$(''#tree .node .nodeChildren'') returns duplicates, and it > looks like $$(''#tree > .node > .nodeChildren'') doesn''t work ($$ probably > doesn''t support direct decendents yet, it returns and empty array). > $$('' .nodeChildren'') wouldn''t work for me, elements with class > ''.nodeChildren'' could be under two different trees (''#tree1'' and ''#tree2'' > for example). > > Sam: > I agree with you, I discovered this problem while using event:Selectors to > toggle an element on a click event, it took me a while to figure out that > the toggle function was being called twice. It is un-intuitive that $$returns duplicates, even though it is technically correct, I don''t see where > it would be useful, especially since it doesn''t support direct descendants > yet. > Perhaps it is a bug, or perhaps we just have to wait till more advanced > CSS selectors are supported > > Anyway, > I just added few lines to the $$ function to return a unique array. If > anyone wants to take a look at it quickly, there''s probably a better way to > do it (using prototype''s array functions) > > > function $$() { > var nodes = $A(arguments).map(function(expression) { > return expression.strip ().split(/\s+/).inject([null], > function(results, expr) { > var selector = new Selector(expr); > return results.map(selector.findElements.bind(selector)).flatten(); > }); > }).flatten(); > var uniqueNodes =[]; > var i=0; > for(i=0;i<nodes.length;i++){ > if(uniqueNodes.indexOf(nodes[i])==-1) > { > uniqueNodes.push(nodes[i]); > } > } > return uniqueNodes; > } > > Thanks, > Brian > > On 8/13/06, Seth Dillingham <seth.dillingham-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On 8/13/06, Sam wrote: > > > > > The node id node_3_children satisfies the criteria $(''#tree .node > > > .nodeChildren'') once for nodeID node_1, and once again for nodeID > > node_3. > > > The problem here is #tree .node .nodeChildren allows any number of > > elements > > > to appear between these attributes: e.g., there may be 3 <div > > > class="node">, all of class .node, between #tree .node and > > .nodeChildren. > > > If you want to specify direct descendents only, you could try > > $$(''#tree > > > > .node > .nodeChildren''), but I don''t know if $$ supports direct > > descendents. > > > It probably does, but I''ve never had the opportunity to test. In my > > > experience, nothing works until you see it work. > > > > Sam, > > > > I think his point is that he wants a unique list from $$. It doesn''t > > matter if there are ten ways to get to the same element, it should be > > checking to make sure an item is NOT already in the list before > > pushing it onto the list. > > > > You''d find it very frustrating if getElementsByTagName() returned the > > same element more than once in the result list. That''s because you > > usually want to *do* something with the items in the list, and you > > don''t want to process any of them more than once. > > > > If getElementsByTagName() did return some elements more than once, and > > the browser vendors explained that the reason is because of how they > > build the list, we''d all be quite disgusted. In this case, knowing WHY > > $$ returns the same element twice doesn''t matter... that''s not what we > > expect the function to do. > > > > Looks like a bug to me, Brian. > > > > Seth > > _______________________________________________ > > Rails-spinoffs mailing list > > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > > > -- > ===========================> Brian Peiris > Brampton, Ontario, Canada > brianpeiris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org or brianpeiris-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org > ===========================> > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > >-- burnfield.com/martin _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
That method should be named "uniq" (to match the ruby enumerables, which Prototype heavily borrows from), and should be added to the Prototype enumerables-- seems like a nice extension. :) -Thomas Am 14.08.2006 um 00:06 schrieb Martin Ström:> And the little more elegant, prototypish way ;) > > Object.extend(Array.prototype, { > unique: function() { > return this.inject([], function(array, value) { > if (!array.include(value)) array.push (value); > return array; > }); > } > }); > > _$$_old = $$; > > function $$() {return _$$_old.apply(null, arguments).unique()} > > Ciao > Martin > > On 8/13/06, Brian Peiris <brianpeiris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > Hey Sam, Seth, > thank you both for your replies. > Seth: > Now I see why $$(''#tree .node .nodeChildren'') returns duplicates, > and it looks like $$(''#tree > .node > .nodeChildren'') doesn''t work > ($$ probably doesn''t support direct decendents yet, it returns and > empty array). > $$('' .nodeChildren'') wouldn''t work for me, elements with class > ''.nodeChildren'' could be under two different trees (''#tree1'' and > ''#tree2'' for example). > > Sam: > I agree with you, I discovered this problem while using > event:Selectors to toggle an element on a click event, it took me a > while to figure out that the toggle function was being called > twice. It is un-intuitive that $$ returns duplicates, even though > it is technically correct, I don''t see where it would be useful, > especially since it doesn''t support direct descendants yet. > Perhaps it is a bug, or perhaps we just have to wait till more > advanced CSS selectors are supported > > Anyway, > I just added few lines to the $$ function to return a unique array. > If anyone wants to take a look at it quickly, there''s probably a > better way to do it (using prototype''s array functions) > > > function $$() { > var nodes = $A(arguments).map(function(expression) { > return expression.strip ().split(/\s+/).inject([null], function > (results, expr) { > var selector = new Selector(expr); > return results.map(selector.findElements.bind > (selector)).flatten(); > }); > }).flatten(); > var uniqueNodes =[]; > var i=0; > for(i=0;i<nodes.length;i++){ > if(uniqueNodes.indexOf(nodes[i])==-1) > { > uniqueNodes.push(nodes[i]); > } > } > return uniqueNodes; > } > > Thanks, > Brian > > On 8/13/06, Seth Dillingham <seth.dillingham-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: On > 8/13/06, Sam wrote: > > > The node id node_3_children satisfies the criteria $(''#tree .node > > .nodeChildren'') once for nodeID node_1, and once again for nodeID > node_3. > > The problem here is #tree .node .nodeChildren allows any number > of elements > > to appear between these attributes: e.g., there may be 3 <div > > class="node">, all of class .node, between #tree .node > and .nodeChildren. > > If you want to specify direct descendents only, you could try $$ > (''#tree > > > .node > .nodeChildren''), but I don''t know if $$ supports direct > descendents. > > It probably does, but I''ve never had the opportunity to test. > In my > > experience, nothing works until you see it work. > > Sam, > > I think his point is that he wants a unique list from $$. It doesn''t > matter if there are ten ways to get to the same element, it should be > checking to make sure an item is NOT already in the list before > pushing it onto the list. > > You''d find it very frustrating if getElementsByTagName() returned the > same element more than once in the result list. That''s because you > usually want to *do* something with the items in the list, and you > don''t want to process any of them more than once. > > If getElementsByTagName() did return some elements more than once, and > the browser vendors explained that the reason is because of how they > build the list, we''d all be quite disgusted. In this case, knowing WHY > $$ returns the same element twice doesn''t matter... that''s not what we > expect the function to do. > > Looks like a bug to me, Brian. > > Seth > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > -- > ===========================> Brian Peiris > Brampton, Ontario, Canada > brianpeiris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org or brianpeiris-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org > ===========================> > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > > > -- > burnfield.com/martin > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
BUT, wait just a second Thomas :-) Remember a lot of us aren''t Ruby-jockies... keep the function names _descriptive_ please :-) "unique" is better than uniq IMHO On 8/14/06, Thomas Fuchs <t.fuchs-moWQItti3gBl57MIdRCFDg@public.gmane.org> wrote:> > That method should be named "uniq" (to match the ruby enumerables, which > Prototype heavily borrows from), and should be added to the Prototype > enumerables-- seems like a nice extension. :) > > -Thomas > > Am 14.08.2006 um 00:06 schrieb Martin Ström: > > > And the little more elegant, prototypish way ;) > > > > Object.extend(Array.prototype, { > > unique: function() { > > return this.inject([], function(array, value) { > > if (!array.include(value)) array.push (value); > > return array; > > }); > > } > > }); > > > > _$$_old = $$; > > > > function $$() {return _$$_old.apply(null, arguments).unique()} > > > > Ciao > > Martin > > > > On 8/13/06, Brian Peiris <brianpeiris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hey Sam, Seth, > > thank you both for your replies. > > Seth: > > Now I see why $$(''#tree .node .nodeChildren'') returns duplicates, > > and it looks like $$(''#tree > .node > .nodeChildren'') doesn''t work > > ($$ probably doesn''t support direct decendents yet, it returns and > > empty array). > > $$('' .nodeChildren'') wouldn''t work for me, elements with class > > ''.nodeChildren'' could be under two different trees (''#tree1'' and > > ''#tree2'' for example). > > > > Sam: > > I agree with you, I discovered this problem while using > > event:Selectors to toggle an element on a click event, it took me a > > while to figure out that the toggle function was being called > > twice. It is un-intuitive that $$ returns duplicates, even though > > it is technically correct, I don''t see where it would be useful, > > especially since it doesn''t support direct descendants yet. > > Perhaps it is a bug, or perhaps we just have to wait till more > > advanced CSS selectors are supported > > > > Anyway, > > I just added few lines to the $$ function to return a unique array. > > If anyone wants to take a look at it quickly, there''s probably a > > better way to do it (using prototype''s array functions) > > > > > > function $$() { > > var nodes = $A(arguments).map(function(expression) { > > return expression.strip ().split(/\s+/).inject([null], function > > (results, expr) { > > var selector = new Selector(expr); > > return results.map(selector.findElements.bind > > (selector)).flatten(); > > }); > > }).flatten(); > > var uniqueNodes =[]; > > var i=0; > > for(i=0;i<nodes.length;i++){ > > if(uniqueNodes.indexOf(nodes[i])==-1) > > { > > uniqueNodes.push(nodes[i]); > > } > > } > > return uniqueNodes; > > } > > > > Thanks, > > Brian > > > > On 8/13/06, Seth Dillingham <seth.dillingham-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: On > > 8/13/06, Sam wrote: > > > > > The node id node_3_children satisfies the criteria $(''#tree .node > > > .nodeChildren'') once for nodeID node_1, and once again for nodeID > > node_3. > > > The problem here is #tree .node .nodeChildren allows any number > > of elements > > > to appear between these attributes: e.g., there may be 3 <div > > > class="node">, all of class .node, between #tree .node > > and .nodeChildren. > > > If you want to specify direct descendents only, you could try $$ > > (''#tree > > > > .node > .nodeChildren''), but I don''t know if $$ supports direct > > descendents. > > > It probably does, but I''ve never had the opportunity to test. > > In my > > > experience, nothing works until you see it work. > > > > Sam, > > > > I think his point is that he wants a unique list from $$. It doesn''t > > matter if there are ten ways to get to the same element, it should be > > checking to make sure an item is NOT already in the list before > > pushing it onto the list. > > > > You''d find it very frustrating if getElementsByTagName() returned the > > same element more than once in the result list. That''s because you > > usually want to *do* something with the items in the list, and you > > don''t want to process any of them more than once. > > > > If getElementsByTagName() did return some elements more than once, and > > the browser vendors explained that the reason is because of how they > > build the list, we''d all be quite disgusted. In this case, knowing WHY > > $$ returns the same element twice doesn''t matter... that''s not what we > > expect the function to do. > > > > Looks like a bug to me, Brian. > > > > Seth > > _______________________________________________ > > Rails-spinoffs mailing list > > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > > > > > -- > > ===========================> > Brian Peiris > > Brampton, Ontario, Canada > > brianpeiris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org or brianpeiris-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org > > ===========================> > > > _______________________________________________ > > Rails-spinoffs mailing list > > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > > > > > > > > > -- > > burnfield.com/martin > > _______________________________________________ > > 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 >_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
I''d be concerned about the extreme lack of efficiency with that implementation. The algorithm is exponential, and worse than that, in one of the most common cases does no work at all despite taking so much time. I wouldn''t use it in the library directly. On 8/14/06, Thomas Fuchs <t.fuchs-moWQItti3gBl57MIdRCFDg@public.gmane.org> wrote:> > That method should be named "uniq" (to match the ruby enumerables, which > Prototype heavily borrows from), and should be added to the Prototype > enumerables-- seems like a nice extension. :) > > -Thomas > > Am 14.08.2006 um 00:06 schrieb Martin Ström: > > > And the little more elegant, prototypish way ;) > > > > Object.extend(Array.prototype, { > > unique: function() { > > return this.inject([], function(array, value) { > > if (!array.include(value)) array.push (value); > > return array; > > }); > > } > > }); > > > > _$$_old = $$; > > > > function $$() {return _$$_old.apply(null, arguments).unique()} > > > > Ciao > > Martin > > > > On 8/13/06, Brian Peiris <brianpeiris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hey Sam, Seth, > > thank you both for your replies. > > Seth: > > Now I see why $$(''#tree .node .nodeChildren'') returns duplicates, > > and it looks like $$(''#tree > .node > .nodeChildren'') doesn''t work > > ($$ probably doesn''t support direct decendents yet, it returns and > > empty array). > > $$('' .nodeChildren'') wouldn''t work for me, elements with class > > ''.nodeChildren'' could be under two different trees (''#tree1'' and > > ''#tree2'' for example). > > > > Sam: > > I agree with you, I discovered this problem while using > > event:Selectors to toggle an element on a click event, it took me a > > while to figure out that the toggle function was being called > > twice. It is un-intuitive that $$ returns duplicates, even though > > it is technically correct, I don''t see where it would be useful, > > especially since it doesn''t support direct descendants yet. > > Perhaps it is a bug, or perhaps we just have to wait till more > > advanced CSS selectors are supported > > > > Anyway, > > I just added few lines to the $$ function to return a unique array. > > If anyone wants to take a look at it quickly, there''s probably a > > better way to do it (using prototype''s array functions) > > > > > > function $$() { > > var nodes = $A(arguments).map(function(expression) { > > return expression.strip ().split(/\s+/).inject([null], function > > (results, expr) { > > var selector = new Selector(expr); > > return results.map(selector.findElements.bind > > (selector)).flatten(); > > }); > > }).flatten(); > > var uniqueNodes =[]; > > var i=0; > > for(i=0;i<nodes.length;i++){ > > if(uniqueNodes.indexOf(nodes[i])==-1) > > { > > uniqueNodes.push(nodes[i]); > > } > > } > > return uniqueNodes; > > } > > > > Thanks, > > Brian > > > > On 8/13/06, Seth Dillingham <seth.dillingham-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: On > > 8/13/06, Sam wrote: > > > > > The node id node_3_children satisfies the criteria $(''#tree .node > > > .nodeChildren'') once for nodeID node_1, and once again for nodeID > > node_3. > > > The problem here is #tree .node .nodeChildren allows any number > > of elements > > > to appear between these attributes: e.g., there may be 3 <div > > > class="node">, all of class .node, between #tree .node > > and .nodeChildren. > > > If you want to specify direct descendents only, you could try $$ > > (''#tree > > > > .node > .nodeChildren''), but I don''t know if $$ supports direct > > descendents. > > > It probably does, but I''ve never had the opportunity to test. > > In my > > > experience, nothing works until you see it work. > > > > Sam, > > > > I think his point is that he wants a unique list from $$. It doesn''t > > matter if there are ten ways to get to the same element, it should be > > checking to make sure an item is NOT already in the list before > > pushing it onto the list. > > > > You''d find it very frustrating if getElementsByTagName() returned the > > same element more than once in the result list. That''s because you > > usually want to *do* something with the items in the list, and you > > don''t want to process any of them more than once. > > > > If getElementsByTagName() did return some elements more than once, and > > the browser vendors explained that the reason is because of how they > > build the list, we''d all be quite disgusted. In this case, knowing WHY > > $$ returns the same element twice doesn''t matter... that''s not what we > > expect the function to do. > > > > Looks like a bug to me, Brian. > > > > Seth > > _______________________________________________ > > Rails-spinoffs mailing list > > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > > > > > -- > > ===========================> > Brian Peiris > > Brampton, Ontario, Canada > > brianpeiris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org or brianpeiris-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org > > ===========================> > > > _______________________________________________ > > Rails-spinoffs mailing list > > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > > > > > > > > > -- > > burnfield.com/martin > > _______________________________________________ > > 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 >_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
btw, there''s also a ticket on this, #3810, but the trac is currently not in working order-- note that there''s a new server on the way[1]. -Thomas [1] http://weblog.rubyonrails.org/2006/8/10/new-dedicated-trac-server- on-the-way Am 14.08.2006 um 17:11 schrieb Jay Miller:> I''d be concerned about the extreme lack of efficiency with that > implementation. The algorithm is exponential, and worse than that, > in one of the most common cases does no work at all despite taking > so much time. I wouldn''t use it in the library directly. > > On 8/14/06, Thomas Fuchs <t.fuchs-moWQItti3gBl57MIdRCFDg@public.gmane.org> wrote: That method > should be named "uniq" (to match the ruby enumerables, which > Prototype heavily borrows from), and should be added to the Prototype > enumerables-- seems like a nice extension. :) > > -Thomas > > Am 14.08.2006 um 00:06 schrieb Martin Ström: > > > And the little more elegant, prototypish way ;) > > > > Object.extend(Array.prototype, { > > unique: function() { > > return this.inject ([], function(array, value) { > > if (!array.include(value)) array.push (value); > > return array; > > }); > > } > > }); > > > > _$$_old = $$; > > > > function $$() {return _$$_old.apply(null, arguments).unique()} > > > > Ciao > > Martin >
I agree with Ryan, uniq saves you two letters and makes you cringe every time you write or read it. Ruby should seriously fix that. Greg ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Gahl Sent: Monday, August 14, 2006 8:08 AM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails-spinoffs] Prototype $$ Question BUT, wait just a second Thomas :-) Remember a lot of us aren''t Ruby-jockies... keep the function names _descriptive_ please :-) "unique" is better than uniq IMHO On 8/14/06, Thomas Fuchs <t.fuchs-moWQItti3gBl57MIdRCFDg@public.gmane.org> wrote: That method should be named "uniq" (to match the ruby enumerables, which Prototype heavily borrows from), and should be added to the Prototype enumerables-- seems like a nice extension. :) -Thomas Am 14.08.2006 um 00:06 schrieb Martin Ström:> And the little more elegant, prototypish way ;) > > Object.extend(Array.prototype, { > unique: function() { > return this.inject ([], function(array, value) { > if (!array.include(value)) array.push (value); > return array; > }); > } > }); > > _$$_old = $$; > > function $$() {return _$$_old.apply(null, arguments).unique()} > > Ciao > Martin > > On 8/13/06, Brian Peiris <brianpeiris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > Hey Sam, Seth, > thank you both for your replies. > Seth: > Now I see why $$(''#tree .node .nodeChildren'') returns duplicates, > and it looks like $$(''#tree > .node > .nodeChildren'') doesn''t work > ($$ probably doesn''t support direct decendents yet, it returns and > empty array). > $$('' .nodeChildren'') wouldn''t work for me, elements with class > ''.nodeChildren'' could be under two different trees (''#tree1'' and > ''#tree2'' for example). > > Sam: > I agree with you, I discovered this problem while using > event:Selectors to toggle an element on a click event, it took me a > while to figure out that the toggle function was being called > twice. It is un-intuitive that $$ returns duplicates, even though > it is technically correct, I don''t see where it would be useful, > especially since it doesn''t support direct descendants yet. > Perhaps it is a bug, or perhaps we just have to wait till more > advanced CSS selectors are supported > > Anyway, > I just added few lines to the $$ function to return a unique array. > If anyone wants to take a look at it quickly, there''s probably a > better way to do it (using prototype''s array functions) > > > function $$() { > var nodes = $A(arguments).map(function(expression) { > return expression.strip ().split(/\s+/).inject([null], function > (results, expr) { > var selector = new Selector(expr); > return results.map(selector.findElements.bind > (selector)).flatten(); > }); > }).flatten(); > var uniqueNodes =[]; > var i=0; > for(i=0;i<nodes.length;i++){ > if(uniqueNodes.indexOf(nodes[i])==-1) > { > uniqueNodes.push(nodes[i]); > } > } > return uniqueNodes; > } > > Thanks, > Brian > > On 8/13/06, Seth Dillingham <seth.dillingham-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: On > 8/13/06, Sam wrote: > > > The node id node_3_children satisfies the criteria $(''#tree .node > > .nodeChildren'') once for nodeID node_1, and once again for nodeID > node_3. > > The problem here is #tree .node .nodeChildren allows any number > of elements > > to appear between these attributes: e.g., there may be 3 <div > > class="node">, all of class .node, between #tree .node > and .nodeChildren. > > If you want to specify direct descendents only, you could try $$ > (''#tree > > > .node > .nodeChildren''), but I don''t know if $$ supports direct > descendents. > > It probably does, but I''ve never had the opportunity to test. > In my > > experience, nothing works until you see it work. > > Sam, > > I think his point is that he wants a unique list from $$. It doesn''t > matter if there are ten ways to get to the same element, it should be > checking to make sure an item is NOT already in the list before > pushing it onto the list. > > You''d find it very frustrating if getElementsByTagName() returned the > same element more than once in the result list. That''s because you > usually want to *do* something with the items in the list, and you > don''t want to process any of them more than once. > > If getElementsByTagName() did return some elements more than once, and > the browser vendors explained that the reason is because of how they > build the list, we''d all be quite disgusted. In this case, knowing WHY > $$ returns the same element twice doesn''t matter... that''s not what we > expect the function to do. > > Looks like a bug to me, Brian. > > Seth > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > -- > ===========================> Brian Peiris > Brampton, Ontario, Canada > brianpeiris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org or brianpeiris-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org > ===========================> > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > > > -- > burnfield.com/martin > _______________________________________________ > 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 _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
To be a tad picky, uniq is only part of Array, not Enumerable in Ruby. On 8/14/06, Hill, Greg <grhill-W2hqgAdRMsX2eFz/2MeuCQ@public.gmane.org> wrote:> > > > > I agree with Ryan, uniq saves you two letters and makes you cringe every > time you write or read it. Ruby should seriously fix that. > > > > Greg > > > > > ________________________________ > > > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On > Behalf Of Ryan Gahl > Sent: Monday, August 14, 2006 8:08 AM > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: Re: [Rails-spinoffs] Prototype $$ Question > > > > BUT, wait just a second Thomas :-) > > Remember a lot of us aren''t Ruby-jockies... keep the function names > _descriptive_ please :-) "unique" is better than uniq IMHO > > > On 8/14/06, Thomas Fuchs <t.fuchs-moWQItti3gBl57MIdRCFDg@public.gmane.org> wrote: > > That method should be named "uniq" (to match the ruby enumerables, which > Prototype heavily borrows from), and should be added to the Prototype > enumerables-- seems like a nice extension. :) > > -Thomas > > Am 14.08.2006 um 00:06 schrieb Martin Ström: > > > And the little more elegant, prototypish way ;) > > > > Object.extend(Array.prototype, { > > unique: function() { > > return this.inject ([], function(array, value) { > > if (!array.include(value)) array.push (value); > > return array; > > }); > > } > > }); > > > > _$$_old = $$; > > > > function $$() {return _$$_old.apply(null, arguments).unique()} > > > > Ciao > > Martin > > > > On 8/13/06, Brian Peiris <brianpeiris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hey Sam, Seth, > > thank you both for your replies. > > Seth: > > Now I see why $$(''#tree .node .nodeChildren'') returns duplicates, > > and it looks like $$(''#tree > .node > .nodeChildren'') doesn''t work > > ($$ probably doesn''t support direct decendents yet, it returns and > > empty array). > > $$('' .nodeChildren'') wouldn''t work for me, elements with class > > ''.nodeChildren'' could be under two different trees (''#tree1'' and > > ''#tree2'' for example). > > > > Sam: > > I agree with you, I discovered this problem while using > > event:Selectors to toggle an element on a click event, it took me a > > while to figure out that the toggle function was being called > > twice. It is un-intuitive that $$ returns duplicates, even though > > it is technically correct, I don''t see where it would be useful, > > especially since it doesn''t support direct descendants yet. > > Perhaps it is a bug, or perhaps we just have to wait till more > > advanced CSS selectors are supported > > > > Anyway, > > I just added few lines to the $$ function to return a unique array. > > If anyone wants to take a look at it quickly, there''s probably a > > better way to do it (using prototype''s array functions) > > > > > > function $$() { > > var nodes = $A(arguments).map(function(expression) { > > return expression.strip ().split(/\s+/).inject([null], function > > (results, expr) { > > var selector = new Selector(expr); > > return results.map(selector.findElements.bind > > (selector)).flatten(); > > }); > > }).flatten(); > > var uniqueNodes =[]; > > var i=0; > > for(i=0;i<nodes.length;i++){ > > if(uniqueNodes.indexOf(nodes[i])==-1) > > { > > uniqueNodes.push(nodes[i]); > > } > > } > > return uniqueNodes; > > } > > > > Thanks, > > Brian > > > > On 8/13/06, Seth Dillingham <seth.dillingham-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: On > > 8/13/06, Sam wrote: > > > > > The node id node_3_children satisfies the criteria $(''#tree .node > > > .nodeChildren'') once for nodeID node_1, and once again for nodeID > > node_3. > > > The problem here is #tree .node .nodeChildren allows any number > > of elements > > > to appear between these attributes: e.g., there may be 3 <div > > > class="node">, all of class .node, between #tree .node > > and .nodeChildren. > > > If you want to specify direct descendents only, you could try $$ > > (''#tree > > > > .node > .nodeChildren''), but I don''t know if $$ supports direct > > descendents. > > > It probably does, but I''ve never had the opportunity to test. > > In my > > > experience, nothing works until you see it work. > > > > Sam, > > > > I think his point is that he wants a unique list from $$. It doesn''t > > matter if there are ten ways to get to the same element, it should be > > checking to make sure an item is NOT already in the list before > > pushing it onto the list. > > > > You''d find it very frustrating if getElementsByTagName() returned the > > same element more than once in the result list. That''s because you > > usually want to *do* something with the items in the list, and you > > don''t want to process any of them more than once. > > > > If getElementsByTagName() did return some elements more than once, and > > the browser vendors explained that the reason is because of how they > > build the list, we''d all be quite disgusted. In this case, knowing WHY > > $$ returns the same element twice doesn''t matter... that''s not what we > > expect the function to do. > > > > Looks like a bug to me, Brian. > > > > Seth > > _______________________________________________ > > Rails-spinoffs mailing list > > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > > > > > -- > > ===========================> > Brian Peiris > > Brampton, Ontario, Canada > > brianpeiris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org or brianpeiris-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org > > ===========================> > > > _______________________________________________ > > Rails-spinoffs mailing list > > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > > > > > > > > > -- > > burnfield.com/martin > > _______________________________________________ > > 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 > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > >
I don''t. :) For Ruby people it makes sure it''s the same method, for others we can have an alias. :) Anyway, uniq (and uniq!) are members of the Array class[1], not the Enumerable class, so it probably should be added to arrays only. -Thomas [1] http://www.ruby-doc.org/core/classes/Array.html#M001755 Am 14.08.2006 um 22:51 schrieb Hill, Greg:> I agree with Ryan, uniq saves you two letters and makes you cringe > every time you write or read it. Ruby should seriously fix that. > > > > Greg > > > > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails- > spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Gahl > Sent: Monday, August 14, 2006 8:08 AM > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: Re: [Rails-spinoffs] Prototype $$ Question > > > > BUT, wait just a second Thomas :-) > > Remember a lot of us aren''t Ruby-jockies... keep the function names > _descriptive_ please :-) "unique" is better than uniq IMHO > > On 8/14/06, Thomas Fuchs <t.fuchs-moWQItti3gBl57MIdRCFDg@public.gmane.org> wrote: > > That method should be named "uniq" (to match the ruby enumerables, > which > Prototype heavily borrows from), and should be added to the Prototype > enumerables-- seems like a nice extension. :) > > -Thomas > > Am 14.08.2006 um 00:06 schrieb Martin Ström: > > > And the little more elegant, prototypish way ;) > > > > Object.extend(Array.prototype, { > > unique: function() { > > return this.inject ([], function(array, value) { > > if (!array.include(value)) array.push (value); > > return array; > > }); > > } > > }); > > > > _$$_old = $$; > > > > function $$() {return _$$_old.apply(null, arguments).unique()} > > > > Ciao > > Martin > > > > On 8/13/06, Brian Peiris <brianpeiris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hey Sam, Seth, > > thank you both for your replies. > > Seth: > > Now I see why $$(''#tree .node .nodeChildren'') returns duplicates, > > and it looks like $$(''#tree > .node > .nodeChildren'') doesn''t work > > ($$ probably doesn''t support direct decendents yet, it returns and > > empty array). > > $$('' .nodeChildren'') wouldn''t work for me, elements with class > > ''.nodeChildren'' could be under two different trees (''#tree1'' and > > ''#tree2'' for example). > > > > Sam: > > I agree with you, I discovered this problem while using > > event:Selectors to toggle an element on a click event, it took me a > > while to figure out that the toggle function was being called > > twice. It is un-intuitive that $$ returns duplicates, even though > > it is technically correct, I don''t see where it would be useful, > > especially since it doesn''t support direct descendants yet. > > Perhaps it is a bug, or perhaps we just have to wait till more > > advanced CSS selectors are supported > > > > Anyway, > > I just added few lines to the $$ function to return a unique array. > > If anyone wants to take a look at it quickly, there''s probably a > > better way to do it (using prototype''s array functions) > > > > > > function $$() { > > var nodes = $A(arguments).map(function(expression) { > > return expression.strip ().split(/\s+/).inject([null], function > > (results, expr) { > > var selector = new Selector(expr); > > return results.map(selector.findElements.bind > > (selector)).flatten(); > > }); > > }).flatten(); > > var uniqueNodes =[]; > > var i=0; > > for(i=0;i<nodes.length;i++){ > > if(uniqueNodes.indexOf(nodes[i])==-1) > > { > > uniqueNodes.push(nodes[i]); > > } > > } > > return uniqueNodes; > > } > > > > Thanks, > > Brian > > > > On 8/13/06, Seth Dillingham <seth.dillingham-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: On > > 8/13/06, Sam wrote: > > > > > The node id node_3_children satisfies the criteria $(''#tree .node > > > .nodeChildren'') once for nodeID node_1, and once again for nodeID > > node_3. > > > The problem here is #tree .node .nodeChildren allows any number > > of elements > > > to appear between these attributes: e.g., there may be 3 <div > > > class="node">, all of class .node, between #tree .node > > and .nodeChildren. > > > If you want to specify direct descendents only, you could try $$ > > (''#tree > > > > .node > .nodeChildren''), but I don''t know if $$ supports direct > > descendents. > > > It probably does, but I''ve never had the opportunity to test. > > In my > > > experience, nothing works until you see it work. > > > > Sam, > > > > I think his point is that he wants a unique list from $$. It doesn''t > > matter if there are ten ways to get to the same element, it > should be > > checking to make sure an item is NOT already in the list before > > pushing it onto the list. > > > > You''d find it very frustrating if getElementsByTagName() returned > the > > same element more than once in the result list. That''s because you > > usually want to *do* something with the items in the list, and you > > don''t want to process any of them more than once. > > > > If getElementsByTagName() did return some elements more than > once, and > > the browser vendors explained that the reason is because of how they > > build the list, we''d all be quite disgusted. In this case, > knowing WHY > > $$ returns the same element twice doesn''t matter... that''s not > what we > > expect the function to do. > > > > Looks like a bug to me, Brian. > > > > Seth > > _______________________________________________ > > Rails-spinoffs mailing list > > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > > > > > -- > > ===========================> > Brian Peiris > > Brampton, Ontario, Canada > > brianpeiris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org or brianpeiris-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org > > ===========================> > > > _______________________________________________ > > Rails-spinoffs mailing list > > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > > > > > > > > > -- > > burnfield.com/martin > > _______________________________________________ > > 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 > > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs