Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
sibling and ancestor/descendant with Sizzle
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
cold sun  
View profile  
 More options Oct 4 2009, 10:08 am
From: cold sun <coldsu...@gmail.com>
Date: Sun, 4 Oct 2009 07:08:52 -0700 (PDT)
Local: Sun, Oct 4 2009 10:08 am
Subject: sibling and ancestor/descendant with Sizzle
Hello,

I get a problem when trying this kind of selector :
"prev ~ sibling descendant"

For instance (with jQuery 1.3.2, which uses Sizzle)
http://coldsun.free.fr/tmp/test2.php?version=1.3.2

You can see in the source code the CSS style :
<style>
#test ~ div *{
        color:yellow;

}

</style>
which sets correctly the color of the <select> to yellow.

Whereas here :
<script type='text/javascript'>
var nb_node_selected = 0;
jQuery("#test ~ div *").css("color", "red").each(function(){
        nb_node_selected ++ ;
        $("#nb").html(nb_node_selected);

});

</script>
jQuery doesn't override the color set with CSS.

Thank you in advance, do not hesitate to ask for precisions if I am
not clear :) .


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron Gustafson  
View profile  
 More options Oct 4 2009, 1:08 pm
From: Aaron Gustafson <aaron.easydesi...@gmail.com>
Date: Sun, 4 Oct 2009 13:08:40 -0400
Local: Sun, Oct 4 2009 1:08 pm
Subject: Re: sibling and ancestor/descendant with Sizzle
On 4 Oct 2009, at 10:08 AM, cold sun wrote:

> I get a problem when trying this kind of selector :
> "prev ~ sibling descendant"

Sizzle doesn't currently support general sibling selectors. I am  
working on an algorithm for it now, but it is a rather complex one to  
calculate, especially if multiple general sibling selections are used.

Cheers,

Aaron

----
Aaron Gustafson
Principal
Easy! Designs, LLC
+1 877 EASY 313 x101
aa...@easy-designs.net


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
cold sun  
View profile  
 More options Oct 5 2009, 5:23 pm
From: cold sun <coldsu...@gmail.com>
Date: Mon, 5 Oct 2009 14:23:33 -0700 (PDT)
Local: Mon, Oct 5 2009 5:23 pm
Subject: Re: sibling and ancestor/descendant with Sizzle
Thank you for your answer.
I hope you will improve this algorithm.

Congratulation for your work, and thank you for sharing it :) .

Cheers


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
cold sun  
View profile  
 More options Oct 17 2009, 1:15 pm
From: cold sun <coldsu...@gmail.com>
Date: Sat, 17 Oct 2009 10:15:50 -0700 (PDT)
Local: Sat, Oct 17 2009 1:15 pm
Subject: Re: sibling and ancestor/descendant with Sizzle
I have noticed that the problem comes from the functions dirCheck and
dirNodeCheck.
I am trying to explain the problem that leads me to this solution :
if you type this selector for exemple :
"div .foobar"
this will search elements with the class "foobar", then the first
parent Node that is a div. For example :
<div><div><p class="foobar"></p></div></div>
This will stop the search at the second div.
In that case, that works, because we are asking for nodes whose class
is "foobar" and who has a div parent node.
Now, we type this selector :
".bar ~ div .foobar"
this will do the same search, but this will check for each first div
ancestor Node, if there is a "previous sibling" node whose class is
"bar".
Now, consider two examples :
- this one works :
<div><span class="bar">foo</span><div><p class="foobar">hi</p></div></
div>
because the second div is after a node whose class is "bar"
- this one does not work with Sizzle, but works with CSS
<span class="bar">foo</span><div><div><p class="foobar">hi</p></div></
div>
because the second div node (who is the first ancestor of ".foobar")
is not after a node whose class is "bar".
However, the grand-parent node (the first div node) is really after a
node whose class is "bar".

Thus, in the piece of code I wrote, I add all ancestors nodes (even
grand-parent nodes ...) in an array (others) and if there is no match,
the next "other" node is shifted.

But, this must not be optimized enough. Moreover, I had to disable the
cache functionality .

I hope this will help, and that my explanation is clear enough. Sorry
for the possible mistakes or non-sens I did.

function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck,
isXML ) {
        var sibDir = dir == "previousSibling" && !isXML;
        for ( var i = 0, l = checkSet.length; i < l; i++ ) {
                var elem = checkSet[i];
                if ( elem ) {
                        if ( sibDir && elem.nodeType === 1 ){
                                elem.sizcache = doneName;
                                elem.sizset = i;
                        }
                        elem = elem[dir];
                        var match = false;

                        while ( elem ) {
                                if ( elem.sizcache === doneName ) {
                                        if(!match) // modifs
                                                match = checkSet[elem.sizset];
                                        else if(elem.nodeName != "BODY" ){
                                                match.others = match.others || new Array();
                                                match.others.push(checkSet[elem.sizset]);
                                        }
                                        else
                                                break;
                                        elem = elem[dir];
                                        continue;
                                }

                                if ( elem.nodeType === 1 && !isXML ){
                                        elem.sizcache = doneName;
                                        elem.sizset = i;
                                }

                                if ( elem.nodeName === cur ) {
                                        if(!match) // modifs
                                                match = elem;
                                        else if(elem.nodeName != "BODY"){
                                                match.others = match.others || new Array();
                                                match.others.push(elem);
                                        }
                                        else
                                                break;
                                        elem = elem[dir];
                                        continue;
                                }

                                elem = elem[dir];
                        }

                        if(!match && checkSet[i].others && checkSet[i].others.length > 0){
                                var tmp = checkSet[i].others;
                                checkSet[i] = tmp.shift();
                                checkSet[i].others = tmp;
                                tmp = null;
                                i--;
                        }
                        else
                                checkSet[i] = match;

                }
        }

}

function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
        var sibDir = dir == "previousSibling" && !isXML;
        for ( var i = 0, l = checkSet.length; i < l; i++ ) {
                var elem = checkSet[i];
                if ( elem ) {
                        if ( sibDir && elem.nodeType === 1 ) {
                                elem.sizcache = doneName;
                                elem.sizset = i;
                        }
                        elem = elem[dir];
                        var match = false;

                        while ( elem ) {
                                if (false && elem.sizcache === doneName ) { // disabled ! (causes
problems with the modifications)
                                        match = checkSet[elem.sizset];
                                        if(match != false)
                                                break;
                                }

                                if ( elem.nodeType === 1 ) {
                                        if ( !isXML ) {
                                                elem.sizcache = doneName;
                                                elem.sizset = i;
                                        }
                                        if ( typeof cur !== "string" ) {
                                                if ( elem === cur ) {
                                                        match = true;
                                                        break;
                                                }

                                        } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {
                                                match = elem;
                                                break;
                                        }
                                }

                                elem = elem[dir];
                        }

                        if(!match && checkSet[i].others && checkSet[i].others.length > 0){
                                var tmp = checkSet[i].others;
                                checkSet[i] = tmp.shift();
                                checkSet[i].others = tmp;
                                tmp = null;
                                i--;
                        }
                        else
                                checkSet[i] = match;
                }
        }


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »