The querySelectorAll returns elements in documents order, but Sizzle
(for now?) treat each selector separately.

Maybe this can be easily resolved joining each result array in one
with nodes in documents order?
If so, maybe something like this would help (not tested). Or you are
thinking to sort results all together?

var precedes = ( document.documentElement.sourceIndex == 0 ) &&
        function( a, b ) {
            return a.sourceIndex < b.sourceIndex;
        }
    || ( document.documentElement.compareDocumentPosition ) &&
        function( a, b ) {
            return !!( a.compareDocumentPosition(b) & 4 );
        }
    ||  function( a, b ) {
            if ( a === b || b.contains(a) )
                return false

            if ( a.contains(b) )
                return true;

            var c = a.parentNode;
            while ( !c.contains(b) ) {
                a = c;
                c = c.parentNode;
            }

            var p = b.parentNode;
            while ( p !== c ) {
                b = p;
                p = p.parentNode;
            }

            var nodes = c.childNodes;
            for ( var i = 0, node = nodes[0]; node; node = nodes[+
+i] ) {
                if ( node === a )
                    return true;
                if ( node === b )
                    return false;
            }

            return false;
        };


function joinResultsHelper( res, a, i, b, j ) {
    if ( b[j] ) {
        for ( var l = a.length; i < l; ++i ) {
            if ( a[i] === b[j] )
                ++j;

            else if ( precedes(a[i], b[j]) )
                res.push( a[i] );

            else {
                res.push( b[j++] );
                joinResultsHelper( res, b, j, a, i );
                break;
            }
        }
    } else {
        for ( var l = a.length; i < l; ++i )
            res.push( a[i] );
    }

    return res;
}

function joinResults( a, b ) {
    if ( a.length === 0 )
        return b;

    if ( b.length === 0 )
        return a;

    return joinResultsHelper( [], a, 0, b, 0 );
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to