[Proto-Scripty] Re: Is this a bug in select()'s CSS evaluation, or am I misunderstandig something?

2009-03-09 Thread Marc Liyanage



On 09.03.2009, at 01:44, Tobie Langel wrote:

 We'll be shifting to Sizzle pretty soon, which afaik allows (or could
 easily be modified to allow) both behaviours.

 Maybe we can make this opt-in for an upcoming release.

That would be great, I can see both use cases. I also see that  
different people seem to expect different things. It would be great to  
have the implementation support both ways.


BTW I like the idea of a :self pseudoclass a lot.

For example, I often need to select the child (not descendant)  
elements of a given element that satisfy a given selector.

With :self I could do:

 $(x).select(':self  .mixedcontent').each(...);

Right now this is the shortest I came up with, and it's not as concise  
as I'm used to with Prototype:

 $(x).childElements().findAll(function (e) {return  
e.match('.mixedcontent')}).each(...);

:self provides the explicit link between selector evaluation and  
context node that I find so surprising as default behavior.


As an aside, getElementsBySelector()'s *documentation* describes what  
I'd want in the example above, it says the method selects extended  
children, but in fact it too seems to select descendants, not children.






--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Is this a bug in select()'s CSS evaluation, or am I misunderstandig something?

2009-03-09 Thread T.J. Crowder

 With :self I could do:

  $(x).select(':self  .mixedcontent').each(...);

I don't have anything against :self, but I don't see why $(x).select
( .foo) shouldn't be legal syntax.

 Right now this is the shortest I came up with, and it's not as concise
 as I'm used to with Prototype:

  $(x).childElements().findAll(function (e) {return
 e.match('.mixedcontent')}).each(...);

Of course, if brevity is the main goal, there's always

$$(#foo  .mixedcontent).each(...);

...but that's dramatically slower on Firefox than a $().select()
(curiously, about the same speed on IE7 and Opera9, which are all I
tried it on).

 As an aside, getElementsBySelector()'s *documentation* describes what
 I'd want in the example above, it says the method selects extended
 children, but in fact it too seems to select descendants, not children.

getElementsBySelector is deprecated in favor of Element#select, which
is documented correctly as retrieving descendant elements (not
children).
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Mar 9, 9:36 am, Marc Liyanage liyan...@gmail.com wrote:
 On 09.03.2009, at 01:44, Tobie Langel wrote:

  We'll be shifting to Sizzle pretty soon, which afaik allows (or could
  easily be modified to allow) both behaviours.

  Maybe we can make this opt-in for an upcoming release.

 That would be great, I can see both use cases. I also see that
 different people seem to expect different things. It would be great to
 have the implementation support both ways.

 BTW I like the idea of a :self pseudoclass a lot.

 For example, I often need to select the child (not descendant)
 elements of a given element that satisfy a given selector.

 With :self I could do:

  $(x).select(':self  .mixedcontent').each(...);

 Right now this is the shortest I came up with, and it's not as concise
 as I'm used to with Prototype:

  $(x).childElements().findAll(function (e) {return
 e.match('.mixedcontent')}).each(...);

 :self provides the explicit link between selector evaluation and
 context node that I find so surprising as default behavior.

 As an aside, getElementsBySelector()'s *documentation* describes what
 I'd want in the example above, it says the method selects extended
 children, but in fact it too seems to select descendants, not children.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Is this a bug in select()'s CSS evaluation, or am I misunderstandig something?

2009-03-08 Thread Quleczka



On 8 Mar, 14:51, Marc Liyanage liyan...@gmail.com wrote:
 From my experiments I get the impression that the select() context
 element and all of its ancestors are completely taken out of the
 selector match calculation.

Exaclty :)

It selects from elements INSIDE of given one. So it can find only 2
elements because first one is not considered as matching the rule
'div.div_a  span.span_a' cause first div is the one you use to call
select function.

From documentation:
Takes an arbitrary number of CSS selectors (strings) and returns an
array of extended descendants of element that match any of them.

It does not count selectors which are not inside of given context.
You have to use element.select on highter level or $$() instead.

Quleczka

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Is this a bug in select()'s CSS evaluation, or am I misunderstandig something?

2009-03-08 Thread Maarten

On Mar 8, 2:51 pm, Marc Liyanage liyan...@gmail.com wrote:
 I am wondering if this is a bug:

 body id='body'

         div id='foo' class='div_a'
                 span class='span_a'/span
                 div class='div_a'
                         span class='span_a'/span
                         div class='div_a'
                                 span class='span_a'/span
                         /div
                 /div
         /div

 /body

 I would expect

 $('foo').select('div.div_a  span.span_a')

 to return three span elements because three of its span descendants
 match the selector. In fact it only returns two, the two deepest ones.

Hi Marc,

If I understand your code correctly, it reads as the following CSS
equivalent:

#foo div.div_a  span.span_a

which indeed matches only the last two elements, as you don't select
the first div element with class value 'div_a', because select()
matches all elements _from_ the element with id 'foo', but if you wrap
that element around your sets of 'div_a' elements, I expect your code
to work as expected.

Ta,
  Maarten

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Is this a bug in select()'s CSS evaluation, or am I misunderstandig something?

2009-03-08 Thread Tobie Langel

Hi,

You might want to read John Resig's article[1] on
document.querySelectorAll.

Ideally, a :root or :self selector would be specified so as to avoid
this potential confusion.

For example:

$('foo').select(':self div.div_a  span.span_a')

Best,

Tobie

[1] http://ejohn.org/blog/thoughts-on-queryselectorall/


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Is this a bug in select()'s CSS evaluation, or am I misunderstandig something?

2009-03-08 Thread Marc Liyanage



On Mar 8, 5:34 pm, Quleczka qulec...@gazeta.pl wrote:
 On 8 Mar, 14:51, Marc Liyanage liyan...@gmail.com wrote:

  From my experiments I get the impression that the select() context
  element and all of its ancestors are completely taken out of the
  selector match calculation.

 Exaclty :)

 It selects from elements INSIDE of given one. So it can find only 2
 elements because first one is not considered as matching the rule
 'div.div_a  span.span_a' cause first div is the one you use to call
 select function.

I realize that, but do you all think that this is the expected
behavior?

I would not expect the implementation to *select* elements outside of
the context scope, but I would definitely expect it to consider such
elements for the *selector evaluation*. In my mind, the selector
evaluation is absolute and independent of the context node, only
considering the structural relationships.

In this case, the first span

1.) *has* a parent div.div_a after all, and that is what the selector
says (and this part has nothing to do with the context element), and
2.) it *is* a descendant of the select() context element

so I think it should be selected.

The implementation as it is now mixes up these two things, in a way
that is really suprising for me. I'm not saying it's wrong, but if
this is intended, I think the documentation should mention that the
context node does influence the selector evaluation.

@Tobie

I just read what Resig wrote and this is interesting:

 This is due to the fact that element-rooted queries are handled by finding 
 all the elements that match the given selector -- rooted in the document -- 
 then filtering by the ones that have the specified element as an ancestor. 
 This is completely unacceptable. Not only is it not intuitive [...]

To me this is *exactly* the way I would have expected it to work. I
guess what's intuitive for one person is surprising for the next :-)




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---